version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
13#define DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
14
15#include <cassert>
16#include <vector>
17#include <algorithm>
18
19#include <dune/common/reservedvector.hh>
21
22namespace Dumux {
23
31template<class GV>
33{
34 using GridView = GV;
37
39 template< class T > using NodalScvDataStorage = std::vector< T >;
40 template< class T > using NodalScvfDataStorage = std::vector< T >;
41
43 template< class T >
44 using ScvfNeighborDataStorage = typename std::conditional_t< (int(GV::dimension)<int(GV::dimensionworld)),
45 std::vector< T >,
46 Dune::ReservedVector< T, 2 > >;
47};
48
56template< class T >
58{
59 using LI = typename T::LocalIndexType;
60 using GI = typename T::GridIndexType;
61
62 using DimIndexVector = Dune::ReservedVector<LI, T::GridView::dimension>;
63 using ScvfIndicesInScvStorage = typename T::template NodalScvDataStorage< DimIndexVector >;
64
65public:
67 using Traits = T;
68
70 using LocalIndexType = LI;
71 using GridIndexType = GI;
72
74 using NodalGridStencilType = typename T::template NodalScvDataStorage< GI >;
75 using NodalLocalStencilType = typename T::template NodalScvDataStorage< LI >;
76 using NodalGridScvfStencilType = typename T::template NodalScvfDataStorage< GI >;
77
79 using ScvfNeighborLocalIndexSet = typename T::template ScvfNeighborDataStorage< LI >;
80
82 CCMpfaDualGridNodalIndexSet() : numBoundaryScvfs_(0) {}
83
85 template<typename SubControlVolumeFace>
86 void insert(const SubControlVolumeFace& scvf)
87 {
88 insert(scvf.index(), scvf.insideScvIdx(), scvf.boundary());
89 }
90
92 void insert(const GridIndexType scvfIdx,
93 const GridIndexType insideScvIdx,
94 const bool boundary)
95 {
96 // this should always be called only once per scvf
97 assert(std::count(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx ) == 0 && "scvf already inserted!");
98
99 // the local index of the scvf data about to be inserted
100 const LocalIndexType curScvfLocalIdx = scvfIndices_.size();
101
102 // if scvf is on boundary, increase counter
103 if (boundary) numBoundaryScvfs_++;
104
105 // insert data on the new scv
106 scvfIndices_.push_back(scvfIdx);
107 scvfIsOnBoundary_.push_back(boundary);
108
109 // if entry for the inside scv exists append data, create otherwise
110 auto it = std::find( scvIndices_.begin(), scvIndices_.end(), insideScvIdx );
111 if (it != scvIndices_.end())
112 {
113 const auto scvIdxLocal = std::distance(scvIndices_.begin(), it);
114 scvfInsideScvIndices_.push_back(scvIdxLocal);
115 localScvfIndicesInScv_[scvIdxLocal].push_back(curScvfLocalIdx);
116 }
117 else
118 {
119 scvfInsideScvIndices_.push_back(scvIndices_.size());
120 localScvfIndicesInScv_.push_back({curScvfLocalIdx});
121 scvIndices_.push_back(insideScvIdx);
122 }
123 }
124
126 std::size_t numScvs() const
127 { return scvIndices_.size(); }
128
130 std::size_t numScvfs() const
131 { return scvfIndices_.size(); }
132
134 std::size_t numBoundaryScvfs() const
135 { return numBoundaryScvfs_; }
136
139 { return scvIndices_; }
140
143 { return scvfIndices_; }
144
146 bool scvfIsOnBoundary(unsigned int i) const
147 {
148 assert(i < numScvfs());
149 return scvfIsOnBoundary_[i];
150 }
151
153 GridIndexType gridScvIndex(unsigned int i) const
154 {
155 assert(i < numScvs());
156 return scvIndices_[i];
157 }
158
160 GridIndexType gridScvfIndex(unsigned int i) const
161 {
162 assert(i < numScvfs());
163 return scvfIndices_[i];
164 }
165
167 GridIndexType gridScvfIndex(unsigned int i, unsigned int j) const
168 {
169 assert(i < numScvs());
170 assert(j < localScvfIndicesInScv_[i].size());
171 return scvfIndices_[ localScvfIndicesInScv_[i][j] ];
172 }
173
175 LocalIndexType localScvfIndex(unsigned int i, unsigned int j) const
176 {
177 assert(i < numScvs());
178 assert(j < localScvfIndicesInScv_[i].size());
179 return localScvfIndicesInScv_[i][j];
180 }
181
184 {
185 assert(i < numScvfs());
186 return scvfInsideScvIndices_[i];
187 }
188
189private:
190 NodalGridStencilType scvIndices_;
191 ScvfIndicesInScvStorage localScvfIndicesInScv_;
192
193 std::size_t numBoundaryScvfs_;
194 NodalGridScvfStencilType scvfIndices_;
195 typename T::template NodalScvfDataStorage< bool > scvfIsOnBoundary_;
196 typename T::template NodalScvfDataStorage< LI > scvfInsideScvIndices_;
197};
198
205template< class NI >
207{
208public:
209 using NodalIndexSet = NI;
210 using GridIndexType = typename NodalIndexSet::GridIndexType;
211
214
216 template< class GridView >
217 CCMpfaDualGridIndexSet(const GridView& gridView)
218 : nodalIndexSets_(gridView.size(GridView::dimension))
219 {}
220
222 template< class SubControlVolumeFace >
223 const NodalIndexSet& operator[] (const SubControlVolumeFace& scvf) const
224 { return nodalIndexSets_[scvf.vertexIndex()]; }
225
226 template< class SubControlVolumeFace >
227 NodalIndexSet& operator[] (const SubControlVolumeFace& scvf)
228 { return nodalIndexSets_[scvf.vertexIndex()]; }
229
232 { return nodalIndexSets_[i]; }
233
235 { return nodalIndexSets_[i]; }
236
237private:
238 std::vector<NodalIndexSet> nodalIndexSets_;
239};
240
241} // end namespace Dumux
242
243#endif
Class for the index sets of the dual grid in mpfa schemes.
Definition: dualgridindexset.hh:207
const NodalIndexSet & operator[](const SubControlVolumeFace &scvf) const
Access with an scvf.
Definition: dualgridindexset.hh:223
CCMpfaDualGridIndexSet()=delete
Default constructor should not be used.
CCMpfaDualGridIndexSet(const GridView &gridView)
Constructor taking a grid view.
Definition: dualgridindexset.hh:217
typename NodalIndexSet::GridIndexType GridIndexType
Definition: dualgridindexset.hh:210
NI NodalIndexSet
Definition: dualgridindexset.hh:209
Nodal index set for mpfa schemes, constructed around grid vertices.
Definition: dualgridindexset.hh:58
T Traits
Export the traits type.
Definition: dualgridindexset.hh:67
GridIndexType gridScvIndex(unsigned int i) const
returns the grid scv idx of the i-th scv
Definition: dualgridindexset.hh:153
GridIndexType gridScvfIndex(unsigned int i) const
returns the index of the i-th scvf
Definition: dualgridindexset.hh:160
const NodalGridScvfStencilType & gridScvfIndices() const
returns the grid scvf indices connected to this dual grid node
Definition: dualgridindexset.hh:142
typename T::template NodalScvDataStorage< LI > NodalLocalStencilType
Definition: dualgridindexset.hh:75
void insert(const SubControlVolumeFace &scvf)
Inserts data for a given scvf.
Definition: dualgridindexset.hh:86
void insert(const GridIndexType scvfIdx, const GridIndexType insideScvIdx, const bool boundary)
Inserts scvf data.
Definition: dualgridindexset.hh:92
const NodalGridStencilType & gridScvIndices() const
returns the grid scv indices connected to this dual grid node
Definition: dualgridindexset.hh:138
CCMpfaDualGridNodalIndexSet()
Constructor.
Definition: dualgridindexset.hh:82
std::size_t numScvs() const
returns the number of scvs around the node
Definition: dualgridindexset.hh:126
typename T::template NodalScvfDataStorage< GI > NodalGridScvfStencilType
Definition: dualgridindexset.hh:76
typename T::template NodalScvDataStorage< GI > NodalGridStencilType
Export the stencil types used.
Definition: dualgridindexset.hh:74
bool scvfIsOnBoundary(unsigned int i) const
returns whether or not the i-th scvf is on a domain boundary
Definition: dualgridindexset.hh:146
std::size_t numScvfs() const
returns the number of scvfs around the node
Definition: dualgridindexset.hh:130
std::size_t numBoundaryScvfs() const
returns the number of boundary scvfs around the node
Definition: dualgridindexset.hh:134
typename T::template ScvfNeighborDataStorage< LI > ScvfNeighborLocalIndexSet
Data structure to store the neighboring scv indices of an scvf (grid/local indices)
Definition: dualgridindexset.hh:79
LI LocalIndexType
Export the index types used.
Definition: dualgridindexset.hh:70
GI GridIndexType
Definition: dualgridindexset.hh:71
LocalIndexType insideScvLocalIndex(unsigned int i) const
returns the node-local index of the inside scv of the i-th scvf
Definition: dualgridindexset.hh:183
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:167
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:175
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
Defines the index types used for grid and local indices.
Definition: adapt.hh:17
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
Default traits to be used in conjunction with the dual grid nodal index set.
Definition: dualgridindexset.hh:33
std::vector< T > NodalScvDataStorage
per default, we use dynamic data containers (iv size unknown)
Definition: dualgridindexset.hh:39
std::vector< T > NodalScvfDataStorage
Definition: dualgridindexset.hh:40
typename IndexTraits< GV >::LocalIndex LocalIndexType
Definition: dualgridindexset.hh:36
GV GridView
Definition: dualgridindexset.hh:34
typename IndexTraits< GV >::GridIndex GridIndexType
Definition: dualgridindexset.hh:35
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:46