Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup CCMpfaDiscretization | ||
10 | * \brief Class for the index sets of the dual grid in mpfa schemes. | ||
11 | */ | ||
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> | ||
20 | #include <dumux/common/indextraits.hh> | ||
21 | |||
22 | namespace Dumux { | ||
23 | |||
24 | /*! | ||
25 | * \ingroup CCMpfaDiscretization | ||
26 | * \brief Default traits to be used in conjunction | ||
27 | * with the dual grid nodal index set. | ||
28 | * | ||
29 | * \tparam GV The grid view type | ||
30 | */ | ||
31 | template<class GV> | ||
32 | struct NodalIndexSetDefaultTraits | ||
33 | { | ||
34 | using GridView = GV; | ||
35 | using GridIndexType = typename IndexTraits<GV>::GridIndex; | ||
36 | using LocalIndexType = typename IndexTraits<GV>::LocalIndex; | ||
37 | |||
38 | //! per default, we use dynamic data containers (iv size unknown) | ||
39 | template< class T > using NodalScvDataStorage = std::vector< T >; | ||
40 | template< class T > using NodalScvfDataStorage = std::vector< T >; | ||
41 | |||
42 | //! store data on neighbors of scvfs in static containers if possible | ||
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 | |||
49 | /*! | ||
50 | * \ingroup CCMpfaDiscretization | ||
51 | * \brief Nodal index set for mpfa schemes, constructed | ||
52 | * around grid vertices. | ||
53 | * | ||
54 | * \tparam T The traits class to be used | ||
55 | */ | ||
56 | template< class T > | ||
57 | class CCMpfaDualGridNodalIndexSet | ||
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 | |||
65 | public: | ||
66 | //! Export the traits type | ||
67 | using Traits = T; | ||
68 | |||
69 | //! Export the index types used | ||
70 | using LocalIndexType = LI; | ||
71 | using GridIndexType = GI; | ||
72 | |||
73 | //! Export the stencil types used | ||
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 | |||
78 | //! Data structure to store the neighboring scv indices of an scvf (grid/local indices) | ||
79 | using ScvfNeighborLocalIndexSet = typename T::template ScvfNeighborDataStorage< LI >; | ||
80 | |||
81 | //! Constructor | ||
82 | 474144 | CCMpfaDualGridNodalIndexSet() : numBoundaryScvfs_(0) {} | |
83 | |||
84 | //! Inserts data for a given scvf | ||
85 | template<typename SubControlVolumeFace> | ||
86 | void insert(const SubControlVolumeFace& scvf) | ||
87 | { | ||
88 |
1/2✓ Branch 1 taken 247564 times.
✗ Branch 2 not taken.
|
247564 | insert(scvf.index(), scvf.insideScvIdx(), scvf.boundary()); |
89 | } | ||
90 | |||
91 | //! Inserts scvf data | ||
92 | 630616 | 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 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 630616 times.
|
2522464 | 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 |
2/2✓ Branch 0 taken 16372 times.
✓ Branch 1 taken 614244 times.
|
630616 | const LocalIndexType curScvfLocalIdx = scvfIndices_.size(); |
101 | |||
102 | // if scvf is on boundary, increase counter | ||
103 |
2/2✓ Branch 0 taken 16372 times.
✓ Branch 1 taken 614244 times.
|
630616 | if (boundary) numBoundaryScvfs_++; |
104 | |||
105 | // insert data on the new scv | ||
106 | 630616 | scvfIndices_.push_back(scvfIdx); | |
107 | 630616 | scvfIsOnBoundary_.push_back(boundary); | |
108 | |||
109 | // if entry for the inside scv exists append data, create otherwise | ||
110 | 1891848 | auto it = std::find( scvIndices_.begin(), scvIndices_.end(), insideScvIdx ); | |
111 |
6/6✓ Branch 0 taken 317272 times.
✓ Branch 1 taken 313344 times.
✓ Branch 2 taken 317272 times.
✓ Branch 3 taken 313344 times.
✓ Branch 4 taken 317272 times.
✓ Branch 5 taken 313344 times.
|
1891848 | if (it != scvIndices_.end()) |
112 | { | ||
113 | 634544 | const auto scvIdxLocal = std::distance(scvIndices_.begin(), it); | |
114 | 317272 | scvfInsideScvIndices_.push_back(scvIdxLocal); | |
115 | 634544 | localScvfIndicesInScv_[scvIdxLocal].push_back(curScvfLocalIdx); | |
116 | } | ||
117 | else | ||
118 | { | ||
119 | 626688 | scvfInsideScvIndices_.push_back(scvIndices_.size()); | |
120 | 313344 | localScvfIndicesInScv_.push_back({curScvfLocalIdx}); | |
121 | 313344 | scvIndices_.push_back(insideScvIdx); | |
122 | } | ||
123 | 630616 | } | |
124 | |||
125 | //! returns the number of scvs around the node | ||
126 | std::size_t numScvs() const | ||
127 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 8491366 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34944 times.
|
8526310 | { return scvIndices_.size(); } |
128 | |||
129 | //! returns the number of scvfs around the node | ||
130 | std::size_t numScvfs() const | ||
131 |
4/8✓ Branch 1 taken 79024 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2044908 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 8454709 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 24336 times.
|
10602977 | { return scvfIndices_.size(); } |
132 | |||
133 | //! returns the number of boundary scvfs around the node | ||
134 | ✗ | std::size_t numBoundaryScvfs() const | |
135 | ✗ | { return numBoundaryScvfs_; } | |
136 | |||
137 | //! returns the grid scv indices connected to this dual grid node | ||
138 | const NodalGridStencilType& gridScvIndices() const | ||
139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4619997 times.
|
9159174 | { return scvIndices_; } |
140 | |||
141 | //! returns the grid scvf indices connected to this dual grid node | ||
142 | const NodalGridScvfStencilType& gridScvfIndices() const | ||
143 |
2/2✓ Branch 0 taken 6370842 times.
✓ Branch 1 taken 59820846 times.
|
71815680 | { return scvfIndices_; } |
144 | |||
145 | //! returns whether or not the i-th scvf is on a domain boundary | ||
146 | 323350 | bool scvfIsOnBoundary(unsigned int i) const | |
147 | { | ||
148 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 323350 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 323350 times.
|
646700 | assert(i < numScvfs()); |
149 | 646700 | return scvfIsOnBoundary_[i]; | |
150 | } | ||
151 | |||
152 | //! returns the grid scv idx of the i-th scv | ||
153 | GridIndexType gridScvIndex(unsigned int i) const | ||
154 | { | ||
155 | assert(i < numScvs()); | ||
156 | return scvIndices_[i]; | ||
157 | } | ||
158 | |||
159 | //! returns the index of the i-th scvf | ||
160 | 63166767 | GridIndexType gridScvfIndex(unsigned int i) const | |
161 | { | ||
162 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 63166767 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63166767 times.
|
126333534 | assert(i < numScvfs()); |
163 | 126333534 | return scvfIndices_[i]; | |
164 | } | ||
165 | |||
166 | //! returns the grid index of the j-th scvf embedded in the i-th scv | ||
167 | 117841400 | GridIndexType gridScvfIndex(unsigned int i, unsigned int j) const | |
168 | { | ||
169 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 117841400 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117841400 times.
|
235682800 | assert(i < numScvs()); |
170 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 117841400 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117841400 times.
|
235682800 | assert(j < localScvfIndicesInScv_[i].size()); |
171 | 353524200 | return scvfIndices_[ localScvfIndicesInScv_[i][j] ]; | |
172 | } | ||
173 | |||
174 | //! returns the node-local index of the j-th scvf embedded in the i-th scv | ||
175 | 822915022 | LocalIndexType localScvfIndex(unsigned int i, unsigned int j) const | |
176 | { | ||
177 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 822915022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 822915022 times.
|
1645830044 | assert(i < numScvs()); |
178 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 822915022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 822915022 times.
|
1645830044 | assert(j < localScvfIndicesInScv_[i].size()); |
179 | 1645830044 | return localScvfIndicesInScv_[i][j]; | |
180 | } | ||
181 | |||
182 | //! returns the node-local index of the inside scv of the i-th scvf | ||
183 | 630616 | LocalIndexType insideScvLocalIndex(unsigned int i) const | |
184 | { | ||
185 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 630616 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 630616 times.
|
1261232 | assert(i < numScvfs()); |
186 | 1261232 | return scvfInsideScvIndices_[i]; | |
187 | } | ||
188 | |||
189 | private: | ||
190 | NodalGridStencilType scvIndices_; //!< The indices of the scvs around a dual grid node | ||
191 | ScvfIndicesInScvStorage localScvfIndicesInScv_; //!< Maps to each scv a list of scvf indices embedded in it | ||
192 | |||
193 | std::size_t numBoundaryScvfs_; //!< stores how many boundary scvfs are embedded in this dual grid node | ||
194 | NodalGridScvfStencilType scvfIndices_; //!< the indices of the scvfs around a dual grid node | ||
195 | typename T::template NodalScvfDataStorage< bool > scvfIsOnBoundary_; //!< Maps to each scvf a boolean to indicate if it is on the boundary | ||
196 | typename T::template NodalScvfDataStorage< LI > scvfInsideScvIndices_; //!< The inside local scv index for each scvf | ||
197 | }; | ||
198 | |||
199 | /*! | ||
200 | * \ingroup CCMpfaDiscretization | ||
201 | * \brief Class for the index sets of the dual grid in mpfa schemes. | ||
202 | * | ||
203 | * \tparam NI The type used for the nodal index sets. | ||
204 | */ | ||
205 | template< class NI > | ||
206 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 48 times.
|
150 | class CCMpfaDualGridIndexSet |
207 | { | ||
208 | public: | ||
209 | using NodalIndexSet = NI; | ||
210 | using GridIndexType = typename NodalIndexSet::GridIndexType; | ||
211 | |||
212 | //! Default constructor should not be used | ||
213 | CCMpfaDualGridIndexSet() = delete; | ||
214 | |||
215 | //! Constructor taking a grid view | ||
216 | template< class GridView > | ||
217 | 50 | CCMpfaDualGridIndexSet(const GridView& gridView) | |
218 |
3/6✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 8 not taken.
|
100 | : nodalIndexSets_(gridView.size(GridView::dimension)) |
219 | 50 | {} | |
220 | |||
221 | //! Access with an scvf | ||
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 | |||
230 | //! Access with an index | ||
231 | const NodalIndexSet& operator[] (GridIndexType i) const | ||
232 | { return nodalIndexSets_[i]; } | ||
233 | |||
234 | NodalIndexSet& operator[] (GridIndexType i) | ||
235 |
8/14✓ Branch 1 taken 53055 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53055 times.
✓ Branch 5 taken 210880 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 53055 times.
✓ Branch 8 taken 210880 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 53055 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 419736 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 419736 times.
✗ Branch 17 not taken.
|
1577328 | { return nodalIndexSets_[i]; } |
236 | |||
237 | private: | ||
238 | std::vector<NodalIndexSet> nodalIndexSets_; | ||
239 | }; | ||
240 | |||
241 | } // end namespace Dumux | ||
242 | |||
243 | #endif | ||
244 |