3.4
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
dualgridindexset.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
25#define DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
26
27#include <cassert>
28#include <vector>
29#include <algorithm>
30
31#include <dune/common/reservedvector.hh>
33
34namespace Dumux {
35
43template<class GV>
45{
46 using GridView = GV;
49
51 template< class T > using NodalScvDataStorage = std::vector< T >;
52 template< class T > using NodalScvfDataStorage = std::vector< T >;
53
55 template< class T >
56 using ScvfNeighborDataStorage = typename std::conditional_t< (int(GV::dimension)<int(GV::dimensionworld)),
57 std::vector< T >,
58 Dune::ReservedVector< T, 2 > >;
59};
60
68template< class T >
70{
71 using LI = typename T::LocalIndexType;
72 using GI = typename T::GridIndexType;
73
74 using DimIndexVector = Dune::ReservedVector<LI, T::GridView::dimension>;
75 using ScvfIndicesInScvStorage = typename T::template NodalScvDataStorage< DimIndexVector >;
76
77public:
79 using Traits = T;
80
82 using LocalIndexType = LI;
83 using GridIndexType = GI;
84
86 using NodalGridStencilType = typename T::template NodalScvDataStorage< GI >;
87 using NodalLocalStencilType = typename T::template NodalScvDataStorage< LI >;
88 using NodalGridScvfStencilType = typename T::template NodalScvfDataStorage< GI >;
89
91 using ScvfNeighborLocalIndexSet = typename T::template ScvfNeighborDataStorage< LI >;
92
94 CCMpfaDualGridNodalIndexSet() : numBoundaryScvfs_(0) {}
95
97 template<typename SubControlVolumeFace>
98 void insert(const SubControlVolumeFace& scvf)
99 {
100 insert(scvf.index(), scvf.insideScvIdx(), scvf.boundary());
101 }
102
104 void insert(const GridIndexType scvfIdx,
105 const GridIndexType insideScvIdx,
106 const bool boundary)
107 {
108 // this should always be called only once per scvf
109 assert(std::count(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx ) == 0 && "scvf already inserted!");
110
111 // the local index of the scvf data about to be inserted
112 const LocalIndexType curScvfLocalIdx = scvfIndices_.size();
113
114 // if scvf is on boundary, increase counter
115 if (boundary) numBoundaryScvfs_++;
116
117 // insert data on the new scv
118 scvfIndices_.push_back(scvfIdx);
119 scvfIsOnBoundary_.push_back(boundary);
120
121 // if entry for the inside scv exists append data, create otherwise
122 auto it = std::find( scvIndices_.begin(), scvIndices_.end(), insideScvIdx );
123 if (it != scvIndices_.end())
124 {
125 const auto scvIdxLocal = std::distance(scvIndices_.begin(), it);
126 scvfInsideScvIndices_.push_back(scvIdxLocal);
127 localScvfIndicesInScv_[scvIdxLocal].push_back(curScvfLocalIdx);
128 }
129 else
130 {
131 scvfInsideScvIndices_.push_back(scvIndices_.size());
132 localScvfIndicesInScv_.push_back({curScvfLocalIdx});
133 scvIndices_.push_back(insideScvIdx);
134 }
135 }
136
138 std::size_t numScvs() const
139 { return scvIndices_.size(); }
140
142 std::size_t numScvfs() const
143 { return scvfIndices_.size(); }
144
146 std::size_t numBoundaryScvfs() const
147 { return numBoundaryScvfs_; }
148
151 { return scvIndices_; }
152
155 { return scvfIndices_; }
156
158 bool scvfIsOnBoundary(unsigned int i) const
159 {
160 assert(i < numScvfs());
161 return scvfIsOnBoundary_[i];
162 }
163
165 GridIndexType gridScvIndex(unsigned int i) const
166 {
167 assert(i < numScvs());
168 return scvIndices_[i];
169 }
170
172 GridIndexType gridScvfIndex(unsigned int i) const
173 {
174 assert(i < numScvfs());
175 return scvfIndices_[i];
176 }
177
179 GridIndexType gridScvfIndex(unsigned int i, unsigned int j) const
180 {
181 assert(i < numScvs());
182 assert(j < localScvfIndicesInScv_[i].size());
183 return scvfIndices_[ localScvfIndicesInScv_[i][j] ];
184 }
185
187 LocalIndexType localScvfIndex(unsigned int i, unsigned int j) const
188 {
189 assert(i < numScvs());
190 assert(j < localScvfIndicesInScv_[i].size());
191 return localScvfIndicesInScv_[i][j];
192 }
193
196 {
197 assert(i < numScvfs());
198 return scvfInsideScvIndices_[i];
199 }
200
201private:
202 NodalGridStencilType scvIndices_;
203 ScvfIndicesInScvStorage localScvfIndicesInScv_;
204
205 std::size_t numBoundaryScvfs_;
206 NodalGridScvfStencilType scvfIndices_;
207 typename T::template NodalScvfDataStorage< bool > scvfIsOnBoundary_;
208 typename T::template NodalScvfDataStorage< LI > scvfInsideScvIndices_;
209};
210
217template< class NI >
219{
220public:
221 using NodalIndexSet = NI;
222 using GridIndexType = typename NodalIndexSet::GridIndexType;
223
226
228 template< class GridView >
229 CCMpfaDualGridIndexSet(const GridView& gridView)
230 : nodalIndexSets_(gridView.size(GridView::dimension))
231 {}
232
234 template< class SubControlVolumeFace >
235 const NodalIndexSet& operator[] (const SubControlVolumeFace& scvf) const
236 { return nodalIndexSets_[scvf.vertexIndex()]; }
237
238 template< class SubControlVolumeFace >
239 NodalIndexSet& operator[] (const SubControlVolumeFace& scvf)
240 { return nodalIndexSets_[scvf.vertexIndex()]; }
241
244 { return nodalIndexSets_[i]; }
245
247 { return nodalIndexSets_[i]; }
248
249private:
250 std::vector<NodalIndexSet> nodalIndexSets_;
251};
252
253} // end namespace Dumux
254
255#endif
Defines the index types used for grid and local indices.
ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:138
Definition: adapt.hh:29
Struture to define the index types used for grid and local indices.
Definition: indextraits.hh:38
Default traits to be used in conjuntion with the dual grid nodal index set.
Definition: dualgridindexset.hh:45
std::vector< T > NodalScvDataStorage
per default, we use dynamic data containers (iv size unknown)
Definition: dualgridindexset.hh:51
std::vector< T > NodalScvfDataStorage
Definition: dualgridindexset.hh:52
typename IndexTraits< GV >::LocalIndex LocalIndexType
Definition: dualgridindexset.hh:48
GV GridView
Definition: dualgridindexset.hh:46
typename IndexTraits< GV >::GridIndex GridIndexType
Definition: dualgridindexset.hh:47
typename std::conditional_t<(int(GV::dimension)< int(GV::dimensionworld)), std::vector< T >, Dune::ReservedVector< T, 2 > > ScvfNeighborDataStorage
store data on neighbors of scvfs in static containers if possible
Definition: dualgridindexset.hh:58
Nodal index set for mpfa schemes, constructed around grid vertices.
Definition: dualgridindexset.hh:70
T Traits
Export the traits type.
Definition: dualgridindexset.hh:79
GridIndexType gridScvIndex(unsigned int i) const
returns the grid scv idx of the i-th scv
Definition: dualgridindexset.hh:165
GridIndexType gridScvfIndex(unsigned int i) const
returns the index of the i-th scvf
Definition: dualgridindexset.hh:172
const NodalGridScvfStencilType & gridScvfIndices() const
returns the grid scvf indices connected to this dual grid node
Definition: dualgridindexset.hh:154
typename T::template NodalScvDataStorage< LI > NodalLocalStencilType
Definition: dualgridindexset.hh:87
void insert(const SubControlVolumeFace &scvf)
Inserts data for a given scvf.
Definition: dualgridindexset.hh:98
void insert(const GridIndexType scvfIdx, const GridIndexType insideScvIdx, const bool boundary)
Inserts scvf data.
Definition: dualgridindexset.hh:104
const NodalGridStencilType & gridScvIndices() const
returns the grid scv indices connected to this dual grid node
Definition: dualgridindexset.hh:150
CCMpfaDualGridNodalIndexSet()
Constructor.
Definition: dualgridindexset.hh:94
std::size_t numScvs() const
returns the number of scvs around the node
Definition: dualgridindexset.hh:138
typename T::template NodalScvfDataStorage< GI > NodalGridScvfStencilType
Definition: dualgridindexset.hh:88
typename T::template NodalScvDataStorage< GI > NodalGridStencilType
Export the stencil types used.
Definition: dualgridindexset.hh:86
bool scvfIsOnBoundary(unsigned int i) const
returns whether or not the i-th scvf is on a domain boundary
Definition: dualgridindexset.hh:158
std::size_t numScvfs() const
returns the number of scvfs around the node
Definition: dualgridindexset.hh:142
std::size_t numBoundaryScvfs() const
returns the number of boundary scvfs around the node
Definition: dualgridindexset.hh:146
typename T::template ScvfNeighborDataStorage< LI > ScvfNeighborLocalIndexSet
Data structure to store the neighboring scv indices of an scvf (grid/local indices)
Definition: dualgridindexset.hh:91
LI LocalIndexType
Export the index types used.
Definition: dualgridindexset.hh:82
GI GridIndexType
Definition: dualgridindexset.hh:83
LocalIndexType insideScvLocalIndex(unsigned int i) const
returns the node-local index of the inside scv of the i-th scvf
Definition: dualgridindexset.hh:195
GridIndexType gridScvfIndex(unsigned int i, unsigned int j) const
returns the grid index of the j-th scvf embedded in the i-th scv
Definition: dualgridindexset.hh:179
LocalIndexType localScvfIndex(unsigned int i, unsigned int j) const
returns the node-local index of the j-th scvf embedded in the i-th scv
Definition: dualgridindexset.hh:187
Class for the index sets of the dual grid in mpfa schemes.
Definition: dualgridindexset.hh:219
const NodalIndexSet & operator[](const SubControlVolumeFace &scvf) const
Access with an scvf.
Definition: dualgridindexset.hh:235
CCMpfaDualGridIndexSet()=delete
Default constructor should not be used.
CCMpfaDualGridIndexSet(const GridView &gridView)
Constructor taking a grid view.
Definition: dualgridindexset.hh:229
typename NodalIndexSet::GridIndexType GridIndexType
Definition: dualgridindexset.hh:222
NI NodalIndexSet
Definition: dualgridindexset.hh:221