GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/cellcentered/mpfa/omethod/interactionvolume.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 64 64 100.0%
Functions: 29 29 100.0%
Branches: 162 217 74.7%

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-FileCopyrightText: 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 interaction volume of the mpfa-o scheme.
11 */
12 #ifndef DUMUX_DISCRETIZATION_CC_MPFA_O_INTERACTIONVOLUME_HH
13 #define DUMUX_DISCRETIZATION_CC_MPFA_O_INTERACTIONVOLUME_HH
14
15 #include <type_traits>
16
17 #include <dune/common/dynmatrix.hh>
18 #include <dune/common/dynvector.hh>
19 #include <dune/common/fvector.hh>
20 #include <dune/common/reservedvector.hh>
21
22 #include <dumux/discretization/cellcentered/mpfa/interactionvolumebase.hh>
23 #include <dumux/discretization/cellcentered/mpfa/localfacedata.hh>
24 #include <dumux/discretization/cellcentered/mpfa/methods.hh>
25
26 #include "localassembler.hh"
27 #include "localsubcontrolentities.hh"
28 #include "interactionvolumeindexset.hh"
29 #include "scvgeometryhelper.hh"
30
31 namespace Dumux {
32
33 //! Forward declaration of the o-method's interaction volume
34 template< class Traits > class CCMpfaOInteractionVolume;
35
36 /*!
37 * \ingroup CCMpfaDiscretization
38 * \brief The default interaction volume traits class for the mpfa-o method.
39 * This uses dynamic types types for matrices/vectors in order to work
40 * on general grids. For interaction volumes known at compile time use
41 * the static interaction volume implementation.
42 *
43 * \tparam NodalIndexSet The type used for the dual grid's nodal index sets
44 * \tparam Scalar The Type used for scalar values
45 */
46 template< class NodalIndexSet, class Scalar >
47 struct CCMpfaODefaultInteractionVolumeTraits
48 {
49 private:
50 using GridIndexType = typename NodalIndexSet::GridIndexType;
51 using LocalIndexType = typename NodalIndexSet::LocalIndexType;
52
53 static constexpr int dim = NodalIndexSet::Traits::GridView::dimension;
54 static constexpr int dimWorld = NodalIndexSet::Traits::GridView::dimensionworld;
55
56 using DimVector = Dune::FieldVector<Scalar, dim>;
57 using FaceOmegas = typename std::conditional< (dim<dimWorld),
58 std::vector<DimVector>,
59 Dune::ReservedVector<DimVector, 2> >::type;
60
61 //! Matrix/Vector traits to be used by the data handle
62 struct MVTraits
63 {
64 using OmegaStorage = std::vector< FaceOmegas >;
65
66 using AMatrix = Dune::DynamicMatrix< Scalar >;
67 using BMatrix = Dune::DynamicMatrix< Scalar >;
68 using CMatrix = Dune::DynamicMatrix< Scalar >;
69 using DMatrix = Dune::DynamicMatrix< Scalar >;
70 using TMatrix = Dune::DynamicMatrix< Scalar >;
71 using CellVector = Dune::DynamicVector< Scalar >;
72 using FaceVector = Dune::DynamicVector< Scalar >;
73 };
74
75 public:
76 //! export the type of grid view
77 using GridView = typename NodalIndexSet::Traits::GridView;
78 //! export the type for the interaction volume index set
79 using IndexSet = CCMpfaOInteractionVolumeIndexSet< NodalIndexSet >;
80 //! export the type of interaction-volume local scvs
81 using LocalScvType = CCMpfaOInteractionVolumeLocalScv< IndexSet, Scalar, dim, dimWorld >;
82 //! export the type of interaction-volume local scvfs
83 using LocalScvfType = CCMpfaOInteractionVolumeLocalScvf< IndexSet >;
84 //! export the type of used for the iv-local face data
85 using LocalFaceData = InteractionVolumeLocalFaceData<GridIndexType, LocalIndexType>;
86 //! export the matrix/vector traits to be used by the iv
87 using MatVecTraits = MVTraits;
88
89 //! the type of assembler used for the o-method's iv-local eq systems
90 template<class Problem, class FVElementGeometry, class ElemVolVars>
91 using LocalAssembler = MpfaOInteractionVolumeAssembler<Problem, FVElementGeometry, ElemVolVars>;
92 };
93
94 /*!
95 * \ingroup CCMpfaDiscretization
96 * \brief Class for the interaction volume of the mpfa-o method.
97 * This implementation creates dynamic objects of the local geometries
98 * and can be used at boundaries and on unstructured grids.
99 */
100 template< class Traits >
101 4639837 class CCMpfaOInteractionVolume
102 : public CCMpfaInteractionVolumeBase< Traits >
103 {
104 using GridView = typename Traits::GridView;
105 using Element = typename GridView::template Codim<0>::Entity;
106
107 using IndexSet = typename Traits::IndexSet;
108 using GridIndexType = typename IndexSet::GridIndexType;
109 using LocalIndexType = typename IndexSet::LocalIndexType;
110 using Stencil = typename IndexSet::NodalGridStencilType;
111
112 using LocalScvType = typename Traits::LocalScvType;
113 using LocalScvfType = typename Traits::LocalScvfType;
114 using LocalFaceData = typename Traits::LocalFaceData;
115
116 public:
117 //! Data attached to scvf touching Dirichlet boundaries.
118 //! For the default o-scheme, we only store the corresponding vol vars index.
119 class DirichletData
120 {
121 GridIndexType volVarIndex_;
122 public:
123 //! Constructor
124 461072 DirichletData(const GridIndexType index) : volVarIndex_(index) {}
125
126 //! Return corresponding vol var index
127 2707408 GridIndexType volVarIndex() const { return volVarIndex_; }
128 };
129
130 //! publicly state the mpfa-scheme this interaction volume is associated with
131 static constexpr MpfaMethods MpfaMethod = MpfaMethods::oMethod;
132
133 //! Sets up the local scope for a given iv index set
134 template< class Problem, class FVElementGeometry >
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 void bind(const IndexSet& indexSet,
136 const Problem& problem,
137 const FVElementGeometry& fvGeometry)
138 {
139 // for the o-scheme, the stencil is equal to the scv
140 // index set of the dual grid's nodal index set
141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 stencil_ = &indexSet.nodalIndexSet().gridScvIndices();
142
143 // number of interaction-volume-local scvs(=node-local for o-scheme) and scvfs
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 numFaces_ = indexSet.numFaces();
145 4639837 const auto numLocalScvs = indexSet.numScvs();
146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 const auto numGlobalScvfs = indexSet.nodalIndexSet().numScvfs();
147
148 // reserve memory for local entities
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 elements_.clear(); elements_.reserve(numLocalScvs);
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 scvs_.clear(); scvs_.reserve(numLocalScvs);
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 scvfs_.clear(); scvfs_.reserve(numFaces_);
152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 localFaceData_.clear(); localFaceData_.reserve(numGlobalScvfs);
153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
4639837 dirichletData_.clear(); dirichletData_.reserve(numFaces_);
154
155 // set up stuff related to sub-control volumes
156
2/2
✓ Branch 0 taken 15765384 times.
✓ Branch 1 taken 4639837 times.
20405221 for (LocalIndexType scvIdxLocal = 0; scvIdxLocal < numLocalScvs; scvIdxLocal++)
157 {
158
1/2
✓ Branch 2 taken 10610246 times.
✗ Branch 3 not taken.
15765384 elements_.emplace_back(fvGeometry.gridGeometry().element( stencil()[scvIdxLocal] ));
159 15765384 scvs_.emplace_back(fvGeometry.gridGeometry().mpfaHelper(),
160 fvGeometry,
161 15765384 fvGeometry.scv( stencil()[scvIdxLocal] ),
162 scvIdxLocal,
163 indexSet);
164 }
165
166 // keep track of the number of unknowns etc
167 4639837 numUnknowns_ = 0;
168 4639837 numKnowns_ = numLocalScvs;
169
170 // set up quantities related to sub-control volume faces
171
2/2
✓ Branch 0 taken 17450279 times.
✓ Branch 1 taken 4639837 times.
22090116 for (LocalIndexType faceIdxLocal = 0; faceIdxLocal < numFaces_; ++faceIdxLocal)
172 {
173
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13917521 times.
17450279 const auto& scvf = fvGeometry.scvf(indexSet.gridScvfIndex(faceIdxLocal));
174
175 // the neighboring scvs in local indices (order: 0 - inside scv, 1..n - outside scvs)
176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17450279 times.
17450279 const auto& neighborScvIndicesLocal = indexSet.neighboringLocalScvIndices(faceIdxLocal);
177 17450279 const auto numNeighborScvs = neighborScvIndicesLocal.size();
178
2/2
✓ Branch 1 taken 3394650 times.
✓ Branch 2 taken 14055629 times.
17450279 localFaceData_.emplace_back(faceIdxLocal, neighborScvIndicesLocal[0], scvf.index());
179
180 // create iv-local scvf object
181
2/2
✓ Branch 0 taken 3394650 times.
✓ Branch 1 taken 14055629 times.
17450279 if (scvf.boundary())
182 {
183
4/4
✓ Branch 0 taken 354974 times.
✓ Branch 1 taken 2761280 times.
✓ Branch 2 taken 284982 times.
✓ Branch 3 taken 10540 times.
3411776 if (problem.boundaryTypes(elements_[neighborScvIndicesLocal[0]], scvf).hasOnlyDirichlet())
184 {
185 402958 scvfs_.emplace_back(scvf, neighborScvIndicesLocal, numKnowns_++, /*isDirichlet*/true);
186 402958 dirichletData_.emplace_back(scvf.outsideScvIdx());
187 }
188 else
189 2991692 scvfs_.emplace_back(scvf, neighborScvIndicesLocal, numUnknowns_++, /*isDirichlet*/false);
190 }
191 else
192 {
193 14055629 scvfs_.emplace_back(scvf, neighborScvIndicesLocal, numUnknowns_++, /*isDirichlet*/false);
194
195 // add local face data objects for the outside faces
196
2/2
✓ Branch 0 taken 14080489 times.
✓ Branch 1 taken 14055629 times.
28136118 for (LocalIndexType i = 1; i < numNeighborScvs; ++i)
197 {
198 // loop over scvfs in outside scv until we find the one coinciding with current scvf
199 14080489 const auto outsideLocalScvIdx = neighborScvIndicesLocal[i];
200 14080489 const auto& flipScvfIndex = fvGeometry.gridGeometry().flipScvfIndexSet()[scvf.index()][i-1];
201 14080489 const auto& flipScvf = fvGeometry.scvf(flipScvfIndex);
202 14080489 localFaceData_.emplace_back(faceIdxLocal, // iv-local scvf idx
203 outsideLocalScvIdx, // iv-local scv index
204 28160978 i-1, // scvf-local index in outside faces
205 14080489 flipScvf.index()); // global scvf index
206 }
207 }
208 }
209 4639837 }
210
211 //! returns the number of primary scvfs of this interaction volume
212 661846704 std::size_t numFaces() const
213
30/44
✓ Branch 1 taken 52030642 times.
✓ Branch 2 taken 3894164 times.
✓ Branch 4 taken 2128778 times.
✓ Branch 5 taken 82083226 times.
✓ Branch 6 taken 13660904 times.
✓ Branch 7 taken 192 times.
✓ Branch 9 taken 36395860 times.
✓ Branch 10 taken 192 times.
✓ Branch 12 taken 38524062 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 142853452 times.
✓ Branch 15 taken 38524062 times.
✓ Branch 17 taken 125079990 times.
✓ Branch 18 taken 31121668 times.
✓ Branch 20 taken 2607662 times.
✓ Branch 21 taken 2143706 times.
✓ Branch 22 taken 470464 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 826560 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 3434222 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 2470992 times.
✓ Branch 31 taken 3434222 times.
✓ Branch 33 taken 10156344 times.
✓ Branch 34 taken 2607662 times.
✓ Branch 36 taken 826560 times.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✓ Branch 44 taken 826560 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 826560 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 2470992 times.
✓ Branch 50 taken 826560 times.
✗ Branch 24 not taken.
✗ Branch 32 not taken.
✓ Branch 8 taken 470464 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 470464 times.
✓ Branch 19 taken 470464 times.
661846704 { return numFaces_; }
214
215 //! returns the number of intermediate unknowns within this interaction volume
216 189505140 std::size_t numUnknowns() const
217
32/42
✗ Branch 0 not taken.
✓ Branch 1 taken 38989111 times.
✓ Branch 2 taken 6399514 times.
✓ Branch 3 taken 5557393 times.
✓ Branch 4 taken 42830498 times.
✓ Branch 5 taken 7226266 times.
✓ Branch 6 taken 3425610 times.
✓ Branch 7 taken 35568916 times.
✓ Branch 8 taken 2128586 times.
✓ Branch 9 taken 30466426 times.
✓ Branch 11 taken 3425610 times.
✓ Branch 12 taken 29169402 times.
✓ Branch 14 taken 3420074 times.
✓ Branch 15 taken 29169402 times.
✓ Branch 17 taken 1297024 times.
✓ Branch 18 taken 2607662 times.
✓ Branch 19 taken 832096 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 2607662 times.
✓ Branch 22 taken 826560 times.
✓ Branch 24 taken 826560 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 826560 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 826560 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 826560 times.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 826560 times.
✓ Branch 38 taken 826560 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 826560 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 826560 times.
✗ Branch 45 not taken.
✓ Branch 10 taken 6399514 times.
✓ Branch 13 taken 6405050 times.
✓ Branch 16 taken 5536 times.
✓ Branch 23 taken 2607662 times.
✓ Branch 26 taken 2607662 times.
✓ Branch 29 taken 2607662 times.
319271064 { return numUnknowns_; }
218
219 //! returns the number of (in this context) known solution values within this interaction volume
220 183012336 std::size_t numKnowns() const
221
9/21
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 38524062 times.
✓ Branch 6 taken 470464 times.
✓ Branch 8 taken 38524062 times.
✓ Branch 9 taken 470464 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 15 taken 3434222 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3434222 times.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 25 taken 826560 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 826560 times.
✗ Branch 29 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
183012336 { return numKnowns_; }
222
223 //! returns the number of scvs embedded in this interaction volume
224 511268529 std::size_t numScvs() const
225
9/9
✓ Branch 1 taken 64318889 times.
✓ Branch 2 taken 116812796 times.
✓ Branch 3 taken 29996362 times.
✓ Branch 4 taken 1644553 times.
✓ Branch 5 taken 846400 times.
✓ Branch 6 taken 5536 times.
✓ Branch 7 taken 400 times.
✓ Branch 8 taken 121 times.
✓ Branch 0 taken 297643472 times.
511268408 { return scvs_.size(); }
226
227 //! returns the cell-stencil of this interaction volume
228 592682268 const Stencil& stencil() const
229
2/2
✓ Branch 1 taken 949642 times.
✓ Branch 2 taken 2331640 times.
591361878 { return *stencil_; }
230
231 //! returns the grid element corresponding to a given iv-local scv idx
232 211904 const Element& element(LocalIndexType ivLocalScvIdx) const
233
1/2
✓ Branch 1 taken 105952 times.
✗ Branch 2 not taken.
583548044 { return elements_[ivLocalScvIdx]; }
234
235 //! returns the local scvf entity corresponding to a given iv-local scvf idx
236 1231513272 const LocalScvfType& localScvf(LocalIndexType ivLocalScvfIdx) const
237
17/17
✓ Branch 0 taken 1313786 times.
✓ Branch 1 taken 829920 times.
✓ Branch 2 taken 145479136 times.
✓ Branch 3 taken 151311286 times.
✓ Branch 5 taken 304587730 times.
✓ Branch 6 taken 8493106 times.
✓ Branch 9 taken 14789762 times.
✓ Branch 10 taken 13136642 times.
✓ Branch 11 taken 11601382 times.
✓ Branch 12 taken 10783510 times.
✓ Branch 4 taken 143938542 times.
✓ Branch 7 taken 20960 times.
✓ Branch 8 taken 2491952 times.
✓ Branch 15 taken 2470992 times.
✓ Branch 16 taken 2470992 times.
✓ Branch 17 taken 817872 times.
✓ Branch 18 taken 817872 times.
1231513272 { return scvfs_[ivLocalScvfIdx]; }
238
239 //! returns the local scv entity corresponding to a given iv-local scv idx
240 1198725484 const LocalScvType& localScv(LocalIndexType ivLocalScvIdx) const
241
25/26
✓ Branch 1 taken 3486924 times.
✓ Branch 2 taken 10000216 times.
✓ Branch 3 taken 4553556 times.
✓ Branch 4 taken 11055384 times.
✓ Branch 5 taken 400456 times.
✓ Branch 6 taken 408888 times.
✓ Branch 8 taken 5110748 times.
✓ Branch 9 taken 1754286 times.
✓ Branch 10 taken 5900264 times.
✓ Branch 11 taken 904792 times.
✓ Branch 12 taken 292648 times.
✓ Branch 13 taken 292648 times.
✓ Branch 15 taken 291720 times.
✓ Branch 16 taken 97240 times.
✓ Branch 17 taken 109704 times.
✓ Branch 18 taken 18926 times.
✓ Branch 19 taken 21026 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 889432 times.
✓ Branch 22 taken 877944 times.
✓ Branch 23 taken 292648 times.
✓ Branch 24 taken 292648 times.
✓ Branch 25 taken 298392 times.
✓ Branch 26 taken 292648 times.
✓ Branch 14 taken 282232 times.
✓ Branch 7 taken 1769862 times.
1279275962 { return scvs_[ivLocalScvIdx]; }
242
243 //! returns a reference to the container with the local face data
244 const std::vector<LocalFaceData>& localFaceData() const
245
8/12
✓ Branch 1 taken 41851480 times.
✓ Branch 2 taken 4528174 times.
✓ Branch 3 taken 223190720 times.
✓ Branch 4 taken 168658652 times.
✓ Branch 5 taken 14613064 times.
✓ Branch 6 taken 78649612 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 0 taken 112621152 times.
✓ Branch 7 taken 9683622 times.
733662780 { return localFaceData_; }
246
247 //! returns a reference to the information container on Dirichlet BCs within this iv
248 const std::vector<DirichletData>& dirichletData() const
249 95146826 { return dirichletData_; }
250
251 //! returns the geometry of the i-th local scv
252 template< class FVElementGeometry >
253 400 auto getScvGeometry(LocalIndexType ivLocalScvIdx, const FVElementGeometry& fvGeometry) const
254
1/2
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
400 { return CCMpfaOScvGeometryHelper<LocalScvType>::computeScvGeometry(ivLocalScvIdx, *this, fvGeometry); }
255
256 //! returns the number of interaction volumes living around a vertex
257 template< class NI >
258 static constexpr std::size_t numIVAtVertex(const NI& nodalIndexSet)
259 { return 1; }
260
261 //! adds the iv index sets living around a vertex to a given container
262 //! and stores the the corresponding index in a map for each scvf
263 template< class IvIndexSetContainer,
264 class ScvfIndexMap,
265 class NodalIndexSet,
266 class FlipScvfIndexSet >
267 79874 static void addIVIndexSets(IvIndexSetContainer& ivIndexSetContainer,
268 ScvfIndexMap& scvfIndexMap,
269 const NodalIndexSet& nodalIndexSet,
270 const FlipScvfIndexSet& flipScvfIndexSet)
271 {
272 // the global index of the iv index set that is about to be created
273 79874 const auto curGlobalIndex = ivIndexSetContainer.size();
274
275 // make the one index set for this node
276 79874 ivIndexSetContainer.emplace_back(nodalIndexSet, flipScvfIndexSet);
277
278 // store the index mapping
279
2/2
✓ Branch 0 taken 630616 times.
✓ Branch 1 taken 79024 times.
716634 for (const auto scvfIdx : nodalIndexSet.gridScvfIndices())
280 636760 scvfIndexMap[scvfIdx] = curGlobalIndex;
281 79874 }
282
283 private:
284 // pointer to cell stencil (in iv index set)
285 const Stencil* stencil_;
286
287 // Variables defining the local scope
288 std::vector<Element> elements_;
289 std::vector<LocalScvType> scvs_;
290 std::vector<LocalScvfType> scvfs_;
291 std::vector<LocalFaceData> localFaceData_;
292 std::vector<DirichletData> dirichletData_;
293
294 // sizes involved in the local system equations
295 std::size_t numFaces_;
296 std::size_t numUnknowns_;
297 std::size_t numKnowns_;
298 };
299
300 } // end namespace Dumux
301
302 #endif
303