GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/staggered/fvgridgeometry.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 69 127 54.3%
Functions: 14 55 25.5%
Branches: 317 953 33.3%

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 StaggeredDiscretization
10 * \copydoc Dumux::StaggeredFVGridGeometry
11 */
12 #ifndef DUMUX_DISCRETIZATION_STAGGERED_FV_GRID_GEOMETRY
13 #define DUMUX_DISCRETIZATION_STAGGERED_FV_GRID_GEOMETRY
14
15 #include <utility>
16
17 #include <dumux/common/indextraits.hh>
18 #include <dumux/discretization/basegridgeometry.hh>
19 #include <dumux/discretization/checkoverlapsize.hh>
20 #include <dumux/discretization/method.hh>
21 #include <dumux/discretization/extrusion.hh>
22
23 namespace Dumux {
24
25 /*!
26 * \ingroup StaggeredDiscretization
27 * \brief Base class for cell center of face specific auxiliary FvGridGeometry classes.
28 * Provides a common interface and a pointer to the actual gridGeometry.
29 */
30 template<class ActualGridGeometry>
31 class GridGeometryView
32 {
33 public:
34
35 100 explicit GridGeometryView(const ActualGridGeometry* actualGridGeometry)
36 100 : gridGeometry_(actualGridGeometry) {}
37
38 //! export the GridView type and the discretization method
39 using GridView = typename ActualGridGeometry::GridView;
40
41 //! export the discretization method this geometry belongs to
42 using DiscretizationMethod = DiscretizationMethods::Staggered;
43 static constexpr DiscretizationMethod discMethod{};
44
45 using LocalView = typename ActualGridGeometry::LocalView;
46
47 /*!
48 * \brief Returns true if this view if related to cell centered dofs
49 */
50 static constexpr bool isCellCenter() { return false; }
51
52 /*!
53 * \brief Returns true if this view if related to face dofs
54 */
55 static constexpr bool isFace() {return false; }
56
57 /*!
58 * \brief Return an integral constant index for cell centered dofs
59 */
60 static constexpr auto cellCenterIdx()
61 { return typename ActualGridGeometry::DofTypeIndices::CellCenterIdx{}; }
62
63 /*!
64 * \brief Return an integral constant index for face dofs
65 */
66 static constexpr auto faceIdx()
67 { return typename ActualGridGeometry::DofTypeIndices::FaceIdx{}; }
68
69 /*!
70 * \brief Return the gridView this grid geometry object lives on
71 */
72 const auto& gridView() const
73
39/92
✓ Branch 1 taken 4474 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4474 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4474 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4474 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 20 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 4454 times.
✓ Branch 18 taken 20 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 4454 times.
✓ Branch 21 taken 20 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4474 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 4454 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 17 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 17 times.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✓ Branch 42 taken 17 times.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 17 times.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 17 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✓ Branch 51 taken 17 times.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✓ Branch 54 taken 17 times.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 3 times.
✗ Branch 58 not taken.
✓ Branch 60 taken 3 times.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✓ Branch 63 taken 3 times.
✗ Branch 64 not taken.
✓ Branch 65 taken 30 times.
✓ Branch 66 taken 3 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 30 times.
✓ Branch 69 taken 3 times.
✗ Branch 70 not taken.
✓ Branch 71 taken 30 times.
✓ Branch 72 taken 3 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 30 times.
✓ Branch 75 taken 3 times.
✗ Branch 76 not taken.
✓ Branch 77 taken 30 times.
✓ Branch 78 taken 3 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 30 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 30 times.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✓ Branch 86 taken 30 times.
✗ Branch 87 not taken.
✓ Branch 89 taken 17 times.
✗ Branch 90 not taken.
✓ Branch 92 taken 17 times.
✗ Branch 93 not taken.
✓ Branch 95 taken 17 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 17 times.
✗ Branch 99 not taken.
36260 { return gridGeometry_->gridView(); }
74
75 /*!
76 * \brief Returns the connectivity map of which dofs have derivatives with respect
77 * to a given dof.
78 */
79 const auto& connectivityMap() const // TODO return correct map
80 200 { return gridGeometry_->connectivityMap(); }
81
82 /*!
83 * \brief Returns the mapper for vertices to indices for possibly adaptive grids.
84 */
85 const auto& vertexMapper() const
86 { return gridGeometry_->vertexMapper(); }
87
88 /*!
89 * \brief Returns the mapper for elements to indices for constant grids.
90 */
91 const auto& elementMapper() const
92
4/8
✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7000 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7000 times.
✗ Branch 11 not taken.
499680 { return gridGeometry_->elementMapper(); }
93
94 /*!
95 * \brief Returns the actual gridGeometry we are a restriction of
96 */
97 const ActualGridGeometry& actualGridGeometry() const
98 { return *gridGeometry_; }
99
100 protected:
101 const ActualGridGeometry* gridGeometry_;
102
103 };
104
105 /*!
106 * \ingroup StaggeredDiscretization
107 * \brief Cell center specific auxiliary FvGridGeometry classes.
108 * Required for the Dumux multi-domain framework.
109 */
110 template <class ActualGridGeometry>
111 class CellCenterFVGridGeometry : public GridGeometryView<ActualGridGeometry>
112 {
113 using ParentType = GridGeometryView<ActualGridGeometry>;
114 public:
115
116
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 using ParentType::ParentType;
117
118 /*!
119 * \brief Returns true because this view is related to cell centered dofs
120 */
121 static constexpr bool isCellCenter() { return true; }
122
123 /*!
124 * \brief The total number of cell centered dofs
125 */
126 std::size_t numDofs() const
127 468 { return this->gridGeometry_->numCellCenterDofs(); }
128 };
129
130 /*!
131 * \ingroup StaggeredDiscretization
132 * \brief Face specific auxiliary FvGridGeometry classes.
133 * Required for the Dumux multi-domain framework.
134 */
135 template <class ActualGridGeometry>
136 class FaceFVGridGeometry : public GridGeometryView<ActualGridGeometry>
137 {
138 using ParentType = GridGeometryView<ActualGridGeometry>;
139 public:
140
141
1/2
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
50 using ParentType::ParentType;
142
143 /*!
144 * \brief Returns true because this view is related to face dofs
145 */
146 static constexpr bool isFace() {return true; }
147
148 /*!
149 * \brief The total number of cell centered dofs
150 */
151 std::size_t numDofs() const
152 468 { return this->gridGeometry_->numFaceDofs(); }
153 };
154
155 /*!
156 * \ingroup StaggeredDiscretization
157 * \brief Base class for the finite volume geometry vector for staggered models
158 * This builds up the sub control volumes and sub control volume faces
159 * for each element.
160 */
161 template<class GridView,
162 bool cachingEnabled,
163 class Traits>
164 class StaggeredFVGridGeometry;
165
166 /*!
167 * \ingroup StaggeredDiscretization
168 * \brief Base class for the finite volume geometry vector for staggered models
169 * This builds up the sub control volumes and sub control volume faces
170 * for each element. Specialization in case the FVElementGeometries are stored.
171 */
172 template<class GV, class T>
173 class StaggeredFVGridGeometry<GV, true, T>
174 : public BaseGridGeometry<GV, T>
175 {
176 using ThisType = StaggeredFVGridGeometry<GV, true, T>;
177 using ParentType = BaseGridGeometry<GV, T>;
178 using GridIndexType = typename IndexTraits<GV>::GridIndex;
179 using LocalIndexType = typename IndexTraits<GV>::LocalIndex;
180 using Element = typename GV::template Codim<0>::Entity;
181
182 using IntersectionMapper = typename T::IntersectionMapper;
183 using GeometryHelper = typename T::GeometryHelper;
184 using ConnectivityMap = typename T::template ConnectivityMap<ThisType>;
185
186 public:
187 //! export the traits
188 using Traits = typename T::PublicTraits;
189
190 //! export the discretization method this geometry belongs to
191 using DiscretizationMethod = DiscretizationMethods::Staggered;
192 static constexpr DiscretizationMethod discMethod{};
193
194 static constexpr int upwindSchemeOrder = T::upwindSchemeOrder;
195 static constexpr bool useHigherOrder = upwindSchemeOrder > 1;
196 static constexpr bool cachingEnabled = true;
197
198 //! export the type of the fv element geometry (the local view type)
199 using LocalView = typename T::template LocalView<ThisType, true>;
200 //! export the type of sub control volume
201 using SubControlVolume = typename T::SubControlVolume;
202 //! export the type of sub control volume
203 using SubControlVolumeFace = typename T::SubControlVolumeFace;
204 //! export the type of extrusion
205 using Extrusion = Extrusion_t<T>;
206 //! export the grid view type
207 using GridView = GV;
208 //! export the dof type indices
209 using DofTypeIndices = typename T::DofTypeIndices;
210
211 //! return a integral constant for cell center dofs
212 static constexpr auto cellCenterIdx()
213 { return typename DofTypeIndices::CellCenterIdx{}; }
214
215 //! return a integral constant for face dofs
216 static constexpr auto faceIdx()
217 { return typename DofTypeIndices::FaceIdx{}; }
218
219 //! The order of the stencil built
220 static constexpr int upwindStencilOrder()
221 { return upwindSchemeOrder; }
222
223 using CellCenterFVGridGeometryType = CellCenterFVGridGeometry<ThisType>;
224 using FaceFVGridGeometryType = FaceFVGridGeometry<ThisType>;
225
226 using FVGridGeometryTuple = std::tuple< CellCenterFVGridGeometry<ThisType>, FaceFVGridGeometry<ThisType> >;
227
228 //! Constructor
229 52 StaggeredFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
230 : ParentType(gridView)
231
7/20
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
52 , intersectionMapper_(gridView)
232 {
233 // Check if the overlap size is what we expect
234
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 49 times.
52 if (!CheckOverlapSize<DiscretizationMethod>::isValid(gridView))
235 DUNE_THROW(Dune::InvalidStateException, "The staggered discretization method needs at least an overlap of 1 for parallel computations. "
236 << " Set the parameter \"Grid.Overlap\" in the input file.");
237
238
1/2
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
52 update_();
239 52 }
240
241 //! The total number of sub control volumes
242 std::size_t numScv() const
243 {
244
9/18
✓ Branch 1 taken 1322 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1355444 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1355444 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1355444 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1355444 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 50 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 5569 times.
✓ Branch 22 taken 80 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 80 times.
✗ Branch 26 not taken.
5428877 return scvs_.size();
245 }
246
247 //! The total number of sub control volume faces
248 std::size_t numScvf() const
249 {
250 5669 return scvfs_.size();
251 }
252
253 //! The total number of boundary sub control volume faces
254 std::size_t numBoundaryScvf() const
255 {
256
2/6
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 29 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
80 return numBoundaryScvf_;
257 }
258
259
260 //! The total number of intersections
261 std::size_t numIntersections() const
262 {
263 return intersectionMapper_.numIntersections();
264 }
265
266 //! the total number of dofs
267 std::size_t numDofs() const
268 { return numCellCenterDofs() + numFaceDofs(); }
269
270 std::size_t numCellCenterDofs() const
271
12/23
✓ Branch 6 taken 17 times.
✗ Branch 7 not taken.
✓ Branch 23 taken 30 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 30 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 2 times.
✓ Branch 29 taken 30 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 11 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 20 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 15 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 6 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 6 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 6 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 6 times.
✗ Branch 50 not taken.
676 { return this->gridView().size(0); }
272
273 std::size_t numFaceDofs() const
274
22/36
✓ Branch 6 taken 17 times.
✗ Branch 7 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 30 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 79 times.
✓ Branch 32 taken 30 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 81 times.
✓ Branch 35 taken 30 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 94 times.
✓ Branch 38 taken 1 times.
✓ Branch 39 taken 3 times.
✓ Branch 40 taken 94 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 92 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 85 times.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 6 times.
✓ Branch 50 taken 1 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 6 times.
✓ Branch 53 taken 1 times.
✗ Branch 54 not taken.
✓ Branch 55 taken 2 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 2 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 2 times.
✗ Branch 62 not taken.
1248 { return this->gridView().size(1); }
275
276 //! update all fvElementGeometries (call this after grid adaption)
277 void update(const GridView& gridView)
278 {
279 ParentType::update(gridView);
280 updateIntersectionMapper_();
281 update_();
282 }
283
284 //! update all fvElementGeometries (call this after grid adaption)
285 void update(GridView&& gridView)
286 {
287 ParentType::update(std::move(gridView));
288 updateIntersectionMapper_();
289 update_();
290 }
291
292 //! Get a sub control volume with a global scv index
293 const SubControlVolume& scv(GridIndexType scvIdx) const
294 {
295
33/39
✓ Branch 6 taken 12248 times.
✓ Branch 7 taken 72 times.
✓ Branch 8 taken 12248 times.
✓ Branch 9 taken 72 times.
✓ Branch 11 taken 1016712 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 302736 times.
✓ Branch 14 taken 1016712 times.
✓ Branch 15 taken 4629476 times.
✓ Branch 16 taken 302736 times.
✓ Branch 17 taken 2298384 times.
✓ Branch 18 taken 4617436 times.
✓ Branch 19 taken 1494372 times.
✓ Branch 20 taken 2276904 times.
✓ Branch 21 taken 1170912 times.
✓ Branch 22 taken 1471020 times.
✓ Branch 23 taken 3424672 times.
✓ Branch 24 taken 1141400 times.
✓ Branch 25 taken 432672 times.
✓ Branch 26 taken 3407840 times.
✓ Branch 27 taken 226320 times.
✓ Branch 28 taken 426880 times.
✓ Branch 29 taken 798080 times.
✓ Branch 30 taken 221760 times.
✓ Branch 31 taken 38240 times.
✓ Branch 32 taken 798080 times.
✓ Branch 33 taken 8160 times.
✓ Branch 34 taken 38240 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 8160 times.
✓ Branch 37 taken 102468 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 48356 times.
✓ Branch 40 taken 54112 times.
✗ Branch 41 not taken.
✓ Branch 47 taken 20640 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 20640 times.
✗ Branch 51 not taken.
2217394392 return scvs_[scvIdx];
296 }
297
298 //! Get a sub control volume face with a global scvf index
299 const SubControlVolumeFace& scvf(GridIndexType scvfIdx) const
300 {
301
53/60
✓ Branch 2 taken 22664 times.
✓ Branch 3 taken 68004 times.
✓ Branch 4 taken 2412226 times.
✓ Branch 5 taken 147762 times.
✓ Branch 6 taken 3623270 times.
✓ Branch 7 taken 79770 times.
✓ Branch 8 taken 1433848 times.
✓ Branch 9 taken 2392888 times.
✓ Branch 10 taken 200152 times.
✓ Branch 11 taken 1276152 times.
✓ Branch 12 taken 2350432 times.
✓ Branch 13 taken 186000 times.
✓ Branch 14 taken 2885344 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1837648 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1651648 times.
✓ Branch 20 taken 1234 times.
✓ Branch 21 taken 23382 times.
✓ Branch 22 taken 1653458 times.
✓ Branch 23 taken 4966 times.
✓ Branch 24 taken 20576 times.
✓ Branch 25 taken 46864 times.
✓ Branch 26 taken 9724 times.
✓ Branch 27 taken 11364 times.
✓ Branch 28 taken 55004 times.
✓ Branch 29 taken 287524 times.
✓ Branch 30 taken 1032270 times.
✓ Branch 31 taken 378414 times.
✓ Branch 32 taken 1854958 times.
✓ Branch 33 taken 577086 times.
✓ Branch 34 taken 582444 times.
✓ Branch 35 taken 557348 times.
✓ Branch 36 taken 35916 times.
✓ Branch 37 taken 642900 times.
✓ Branch 38 taken 19272 times.
✓ Branch 39 taken 249912 times.
✓ Branch 40 taken 326608 times.
✓ Branch 41 taken 555696 times.
✓ Branch 42 taken 387528 times.
✓ Branch 43 taken 436616 times.
✓ Branch 44 taken 413031 times.
✓ Branch 45 taken 174617 times.
✓ Branch 46 taken 49431 times.
✓ Branch 47 taken 58393 times.
✓ Branch 48 taken 3056 times.
✓ Branch 49 taken 281168 times.
✓ Branch 50 taken 33876 times.
✓ Branch 51 taken 407500 times.
✓ Branch 52 taken 31636 times.
✓ Branch 53 taken 140940 times.
✓ Branch 54 taken 22120 times.
✓ Branch 55 taken 18328 times.
✓ Branch 56 taken 22120 times.
✓ Branch 57 taken 18328 times.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
847943562 return scvfs_[scvfIdx];
302 }
303
304 //! Get the sub control volume face indices of an scv by global index
305 const std::vector<GridIndexType>& scvfIndicesOfScv(GridIndexType scvIdx) const
306 {
307
5/10
✓ Branch 1 taken 1355444 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1355444 times.
✗ Branch 5 not taken.
✓ Branch 11 taken 7000 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 7000 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 7000 times.
✗ Branch 18 not taken.
320778045 return scvfIndicesOfScv_[scvIdx];
308 }
309
310 GridIndexType localToGlobalScvfIndex(GridIndexType eIdx, LocalIndexType localScvfIdx) const
311 {
312
15/19
✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 600 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 12 taken 400406 times.
✓ Branch 13 taken 278986698 times.
✓ Branch 15 taken 48 times.
✓ Branch 16 taken 284208837 times.
✓ Branch 17 taken 3895192 times.
✓ Branch 18 taken 10782296 times.
✓ Branch 19 taken 205788594 times.
✓ Branch 20 taken 73514054 times.
✓ Branch 21 taken 22308 times.
✓ Branch 22 taken 168856 times.
✓ Branch 23 taken 5190392 times.
✓ Branch 24 taken 517420 times.
✓ Branch 25 taken 800 times.
1428764635 return localToGlobalScvfIndices_[eIdx][localScvfIdx];
313 }
314
315 const SubControlVolumeFace& scvf(GridIndexType eIdx, LocalIndexType localScvfIdx) const
316 {
317
45/59
✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 600 times.
✓ Branch 2 taken 2400 times.
✓ Branch 3 taken 600 times.
✓ Branch 4 taken 2400 times.
✓ Branch 5 taken 600 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 34 taken 53878 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 346528 times.
✓ Branch 37 taken 279040576 times.
✓ Branch 38 taken 346528 times.
✓ Branch 39 taken 278986698 times.
✓ Branch 40 taken 400406 times.
✓ Branch 41 taken 278986698 times.
✓ Branch 45 taken 48 times.
✓ Branch 46 taken 284208837 times.
✓ Branch 47 taken 48 times.
✓ Branch 48 taken 284208837 times.
✓ Branch 49 taken 3895240 times.
✓ Branch 50 taken 284208837 times.
✓ Branch 51 taken 3895192 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 3895192 times.
✓ Branch 54 taken 10782296 times.
✓ Branch 55 taken 202085552 times.
✓ Branch 56 taken 10782296 times.
✓ Branch 57 taken 205788594 times.
✓ Branch 58 taken 83640454 times.
✓ Branch 59 taken 205788594 times.
✓ Branch 60 taken 73514054 times.
✓ Branch 61 taken 3712842 times.
✓ Branch 62 taken 73514054 times.
✓ Branch 63 taken 22308 times.
✓ Branch 64 taken 656828 times.
✓ Branch 65 taken 22308 times.
✓ Branch 66 taken 168856 times.
✓ Branch 67 taken 5168192 times.
✓ Branch 68 taken 168856 times.
✓ Branch 69 taken 5190392 times.
✓ Branch 70 taken 650144 times.
✓ Branch 71 taken 5190392 times.
✓ Branch 72 taken 517420 times.
✓ Branch 73 taken 35508 times.
✓ Branch 74 taken 517420 times.
✓ Branch 75 taken 800 times.
✓ Branch 76 taken 35200 times.
✓ Branch 77 taken 800 times.
4286293905 return scvf(localToGlobalScvfIndex(eIdx, localScvfIdx));
318 }
319
320 /*!
321 * \brief Returns the connectivity map of which dofs have derivatives with respect
322 * to a given dof.
323 */
324 const ConnectivityMap &connectivityMap() const
325
3/6
✓ Branch 3 taken 50 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 50 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 12502432 times.
✗ Branch 10 not taken.
20724588 { return connectivityMap_; }
326
327 //! Returns a pointer the cell center specific auxiliary class. Required for the multi-domain FVAssembler's ctor.
328 std::unique_ptr<CellCenterFVGridGeometry<ThisType>> cellCenterFVGridGeometryPtr() const
329 {
330
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 return std::make_unique<CellCenterFVGridGeometry<ThisType>>(this);
331 }
332
333 //! Returns a pointer the face specific auxiliary class. Required for the multi-domain FVAssembler's ctor.
334 std::unique_ptr<FaceFVGridGeometry<ThisType>> faceFVGridGeometryPtr() const
335 {
336
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 return std::make_unique<FaceFVGridGeometry<ThisType>>(this);
337 }
338
339 //! Return a copy of the cell center specific auxiliary class.
340 CellCenterFVGridGeometry<ThisType> cellCenterFVGridGeometry() const
341 {
342 return CellCenterFVGridGeometry<ThisType>(this);
343 }
344
345 //! Return a copy of the face specific auxiliary class.
346 FaceFVGridGeometry<ThisType> faceFVGridGeometry() const
347 {
348 return FaceFVGridGeometry<ThisType>(this);
349 }
350
351 //! Returns whether one of the geometry's scvfs lies on a boundary
352 bool hasBoundaryScvf(GridIndexType eIdx) const
353
8/10
✓ Branch 0 taken 165957 times.
✓ Branch 1 taken 1521959 times.
✓ Branch 2 taken 165957 times.
✓ Branch 3 taken 1521959 times.
✓ Branch 4 taken 531955 times.
✓ Branch 5 taken 1593613 times.
✓ Branch 6 taken 531955 times.
✓ Branch 7 taken 1593613 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
7626968 { return hasBoundaryScvf_[eIdx]; }
354
355 private:
356
357 void updateIntersectionMapper_()
358 {
359 intersectionMapper_.update(this->gridView());
360 }
361
362 52 void update_()
363 {
364 // clear containers (necessary after grid refinement)
365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 scvs_.clear();
366 52 scvfs_.clear();
367 52 scvfIndicesOfScv_.clear();
368 52 localToGlobalScvfIndices_.clear();
369
370 // determine size of containers
371 104 std::size_t numScvs = this->gridView().size(0);
372 52 std::size_t numScvf = 0;
373
1/2
✓ Branch 2 taken 89577 times.
✗ Branch 3 not taken.
96629 for (const auto& element : elements(this->gridView()))
374 179050 numScvf += element.subEntities(1);
375
376 // reserve memory
377 52 scvs_.resize(numScvs);
378 52 scvfs_.reserve(numScvf);
379 52 scvfIndicesOfScv_.resize(numScvs);
380 52 localToGlobalScvfIndices_.resize(numScvs);
381 52 hasBoundaryScvf_.assign(numScvs, false);
382
383 // Build the scvs and scv faces
384 52 GridIndexType scvfIdx = 0;
385 52 numBoundaryScvf_ = 0;
386
1/2
✓ Branch 2 taken 89577 times.
✗ Branch 3 not taken.
179154 for (const auto& element : elements(this->gridView()))
387 {
388 179050 auto eIdx = this->elementMapper().index(element);
389
390 // reserve memory for the localToGlobalScvfIdx map
391 89525 auto numLocalFaces = intersectionMapper_.numFaces(element);
392 179050 localToGlobalScvfIndices_[eIdx].resize(numLocalFaces);
393
394
2/3
✓ Branch 2 taken 125 times.
✓ Branch 3 taken 89400 times.
✗ Branch 4 not taken.
268450 scvs_[eIdx] = SubControlVolume(element.geometry(), eIdx);
395
396 // the element-wise index sets for finite volume geometry
397
2/6
✓ Branch 1 taken 89525 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 89525 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
268575 std::vector<GridIndexType> scvfsIndexSet;
398
1/2
✓ Branch 1 taken 89525 times.
✗ Branch 2 not taken.
89525 scvfsIndexSet.reserve(numLocalFaces);
399
400 179050 GeometryHelper geometryHelper(element, this->gridView());
401
402
12/17
✓ Branch 1 taken 7000 times.
✓ Branch 2 taken 82525 times.
✓ Branch 3 taken 330350 times.
✓ Branch 4 taken 7000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7000 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7000 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 28000 times.
✓ Branch 13 taken 7000 times.
✓ Branch 14 taken 28000 times.
✓ Branch 15 taken 7000 times.
✓ Branch 17 taken 28000 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 28000 times.
✗ Branch 21 not taken.
551400 for (const auto& intersection : intersections(this->gridView(), element))
403 {
404
2/3
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 358324 times.
✗ Branch 2 not taken.
358350 geometryHelper.updateLocalFace(intersectionMapper_, intersection);
405
2/2
✓ Branch 0 taken 355686 times.
✓ Branch 1 taken 2664 times.
358350 const int localFaceIndex = geometryHelper.localFaceIndex();
406
407 // inner sub control volume faces
408
2/2
✓ Branch 0 taken 355686 times.
✓ Branch 1 taken 2664 times.
358350 if (intersection.neighbor())
409 {
410
3/6
✓ Branch 1 taken 27400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 27400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 27400 times.
✗ Branch 8 not taken.
1029866 auto nIdx = this->elementMapper().index(intersection.outside());
411
5/12
✓ Branch 1 taken 352422 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 352422 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 352422 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 352422 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 352422 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
1057266 scvfs_.emplace_back(intersection,
412 intersection.geometry(),
413 scvfIdx,
414 std::vector<GridIndexType>({eIdx, nIdx}),
415 geometryHelper);
416
2/4
✓ Branch 1 taken 352422 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 352422 times.
✗ Branch 5 not taken.
704844 localToGlobalScvfIndices_[eIdx][localFaceIndex] = scvfIdx;
417
1/2
✓ Branch 1 taken 352422 times.
✗ Branch 2 not taken.
352422 scvfsIndexSet.push_back(scvfIdx++);
418 }
419 // boundary sub control volume faces
420
1/2
✓ Branch 0 taken 5328 times.
✗ Branch 1 not taken.
5928 else if (intersection.boundary())
421 {
422
6/13
✓ Branch 1 taken 5328 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 600 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5928 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 5328 times.
✓ Branch 8 taken 600 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5328 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
17784 scvfs_.emplace_back(intersection,
423 intersection.geometry(),
424 scvfIdx,
425
4/7
✓ Branch 1 taken 5328 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 600 times.
✓ Branch 4 taken 5328 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5328 times.
✗ Branch 8 not taken.
11856 std::vector<GridIndexType>({eIdx, this->gridView().size(0) + numBoundaryScvf_++}),
426 geometryHelper);
427
2/4
✓ Branch 1 taken 5928 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5928 times.
✗ Branch 5 not taken.
11856 localToGlobalScvfIndices_[eIdx][localFaceIndex] = scvfIdx;
428
1/4
✓ Branch 1 taken 5928 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
5928 scvfsIndexSet.push_back(scvfIdx++);
429
430 17784 hasBoundaryScvf_[eIdx] = true;
431 }
432 }
433
434 // Save the scvf indices belonging to this scv to build up fv element geometries fast
435
2/4
✓ Branch 1 taken 89525 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 89525 times.
✗ Branch 5 not taken.
179050 scvfIndicesOfScv_[eIdx] = scvfsIndexSet;
436 }
437
438 // build the connectivity map for an efficient assembly
439 52 connectivityMap_.update(*this);
440 52 }
441
442 // mappers
443 ConnectivityMap connectivityMap_;
444 IntersectionMapper intersectionMapper_;
445
446 std::vector<SubControlVolume> scvs_;
447 std::vector<SubControlVolumeFace> scvfs_;
448 std::vector<std::vector<GridIndexType>> scvfIndicesOfScv_;
449 std::vector<std::vector<GridIndexType>> localToGlobalScvfIndices_;
450 GridIndexType numBoundaryScvf_;
451 std::vector<bool> hasBoundaryScvf_;
452 };
453
454 /*!
455 * \ingroup StaggeredDiscretization
456 * \brief Base class for the finite volume geometry vector for staggered models
457 * This builds up the sub control volumes and sub control volume faces
458 * for each element. Specialization in case the FVElementGeometries are stored.
459 */
460 template<class GV, class T>
461 class StaggeredFVGridGeometry<GV, false, T>
462 : public BaseGridGeometry<GV, T>
463 {
464 using ThisType = StaggeredFVGridGeometry<GV, false, T>;
465 using ParentType = BaseGridGeometry<GV, T>;
466 using GridIndexType = typename IndexTraits<GV>::GridIndex;
467 using LocalIndexType = typename IndexTraits<GV>::LocalIndex;
468 using Element = typename GV::template Codim<0>::Entity;
469
470 using IntersectionMapper = typename T::IntersectionMapper;
471 using ConnectivityMap = typename T::template ConnectivityMap<ThisType>;
472
473 public:
474 //! export the traits
475 using Traits = typename T::PublicTraits;
476
477 //! export the discretization method this geometry belongs to
478 using DiscretizationMethod = DiscretizationMethods::Staggered;
479 static constexpr DiscretizationMethod discMethod{};
480
481 static constexpr int upwindSchemeOrder = T::upwindSchemeOrder;
482 static constexpr bool useHigherOrder = upwindSchemeOrder > 1;
483 static constexpr bool cachingEnabled = false;
484
485 using GeometryHelper = typename T::GeometryHelper;
486
487 //! export the type of the fv element geometry (the local view type)
488 using LocalView = typename T::template LocalView<ThisType, false>;
489 //! export the type of sub control volume
490 using SubControlVolume = typename T::SubControlVolume;
491 //! export the type of sub control volume
492 using SubControlVolumeFace = typename T::SubControlVolumeFace;
493 //! export the type of extrusion
494 using Extrusion = Extrusion_t<T>;
495 //! export the grid view type
496 using GridView = GV;
497 //! export the dof type indices
498 using DofTypeIndices = typename T::DofTypeIndices;
499
500 //! return a integral constant for cell center dofs
501 static constexpr auto cellCenterIdx()
502 { return typename DofTypeIndices::CellCenterIdx{}; }
503
504 //! return a integral constant for face dofs
505 static constexpr auto faceIdx()
506 { return typename DofTypeIndices::FaceIdx{}; }
507
508 //! The order of the stencil built
509 static constexpr int upwindStencilOrder()
510 { return upwindSchemeOrder; }
511
512 using CellCenterFVGridGeometryType = CellCenterFVGridGeometry<ThisType>;
513 using FaceFVGridGeometryType = FaceFVGridGeometry<ThisType>;
514
515 using FVGridGeometryTuple = std::tuple< CellCenterFVGridGeometry<ThisType>, FaceFVGridGeometry<ThisType> >;
516
517 //! Constructor
518 StaggeredFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
519 : ParentType(gridView)
520 , intersectionMapper_(gridView)
521 {
522 // Check if the overlap size is what we expect
523 if (!CheckOverlapSize<DiscretizationMethod>::isValid(gridView))
524 DUNE_THROW(Dune::InvalidStateException, "The staggered discretization method needs at least an overlap of 1 for parallel computations. "
525 << " Set the parameter \"Grid.Overlap\" in the input file.");
526
527 update_();
528 }
529
530
531 //! update all fvElementGeometries (call this after grid adaption)
532 void update(const GridView& gridView)
533 {
534 ParentType::update(gridView);
535 updateIntersectionMapper_();
536 update_();
537 }
538
539 //! update all fvElementGeometries (call this after grid adaption)
540 void update(GridView&& gridView)
541 {
542 ParentType::update(std::move(gridView));
543 updateIntersectionMapper_();
544 update_();
545 }
546
547 //! The total number of sub control volumes
548 std::size_t numScv() const
549 {
550 return numScvs_;
551 }
552
553 //! The total number of sub control volume faces
554 std::size_t numScvf() const
555 {
556 return numScvf_;
557 }
558
559 //! The total number of boundary sub control volume faces
560 std::size_t numBoundaryScvf() const
561 {
562 return numBoundaryScvf_;
563 }
564
565 //! The total number of intersections
566 std::size_t numIntersections() const
567 {
568 return intersectionMapper_.numIntersections();
569 }
570
571 //! the total number of dofs
572 std::size_t numDofs() const
573 { return numCellCenterDofs() + numFaceDofs(); }
574
575 std::size_t numCellCenterDofs() const
576 { return this->gridView().size(0); }
577
578 std::size_t numFaceDofs() const
579 { return this->gridView().size(1); }
580
581 const std::vector<GridIndexType>& scvfIndicesOfScv(GridIndexType scvIdx) const
582 { return scvfIndicesOfScv_[scvIdx]; }
583
584 GridIndexType localToGlobalScvfIndex(GridIndexType eIdx, LocalIndexType localScvfIdx) const
585 {
586 return localToGlobalScvfIndices_[eIdx][localScvfIdx];
587 }
588
589 /*!
590 * \brief Returns the connectivity map of which dofs have derivatives with respect
591 * to a given dof.
592 */
593 const ConnectivityMap &connectivityMap() const
594 { return connectivityMap_; }
595
596 //! Returns a pointer the cell center specific auxiliary class. Required for the multi-domain FVAssembler's ctor.
597 std::unique_ptr<CellCenterFVGridGeometry<ThisType>> cellCenterFVGridGeometryPtr() const
598 {
599 return std::make_unique<CellCenterFVGridGeometry<ThisType>>(this);
600 }
601
602 //! Returns a pointer the face specific auxiliary class. Required for the multi-domain FVAssembler's ctor.
603 std::unique_ptr<FaceFVGridGeometry<ThisType>> faceFVGridGeometryPtr() const
604 {
605 return std::make_unique<FaceFVGridGeometry<ThisType>>(this);
606 }
607
608 //! Return a copy of the cell center specific auxiliary class.
609 CellCenterFVGridGeometry<ThisType> cellCenterFVGridGeometry() const
610 {
611 return CellCenterFVGridGeometry<ThisType>(this);
612 }
613
614 //! Return a copy of the face specific auxiliary class.
615 FaceFVGridGeometry<ThisType> faceFVGridGeometry() const
616 {
617 return FaceFVGridGeometry<ThisType>(this);
618 }
619
620 //! Return a reference to the intersection mapper
621 const IntersectionMapper& intersectionMapper() const
622 {
623 return intersectionMapper_;
624 }
625
626 //! Return the neighbor volVar indices for all scvfs in the scv with index scvIdx
627 const std::vector<GridIndexType>& neighborVolVarIndices(GridIndexType scvIdx) const
628 { return neighborVolVarIndices_[scvIdx]; }
629
630 private:
631
632 void updateIntersectionMapper_()
633 {
634 intersectionMapper_.update(this->gridView());
635 }
636
637 void update_()
638 {
639 // clear containers (necessary after grid refinement)
640 scvfIndicesOfScv_.clear();
641 neighborVolVarIndices_.clear();
642 localToGlobalScvfIndices_.clear();
643
644 numScvs_ = numCellCenterDofs();
645 numScvf_ = 0;
646 numBoundaryScvf_ = 0;
647 scvfIndicesOfScv_.resize(numScvs_);
648 localToGlobalScvfIndices_.resize(numScvs_);
649 neighborVolVarIndices_.resize(numScvs_);
650
651 // Build the scvs and scv faces
652 for (const auto& element : elements(this->gridView()))
653 {
654 auto eIdx = this->elementMapper().index(element);
655
656 // the element-wise index sets for finite volume geometry
657 auto numLocalFaces = intersectionMapper_.numFaces(element);
658 std::vector<GridIndexType> scvfsIndexSet;
659 scvfsIndexSet.reserve(numLocalFaces);
660 localToGlobalScvfIndices_[eIdx].resize(numLocalFaces);
661
662 std::vector<GridIndexType> neighborVolVarIndexSet;
663 neighborVolVarIndexSet.reserve(numLocalFaces);
664
665 for (const auto& intersection : intersections(this->gridView(), element))
666 {
667 const auto localFaceIndex = intersection.indexInInside();
668 localToGlobalScvfIndices_[eIdx][localFaceIndex] = numScvf_;
669 scvfsIndexSet.push_back(numScvf_++);
670
671 if (intersection.neighbor())
672 {
673 const auto nIdx = this->elementMapper().index(intersection.outside());
674 neighborVolVarIndexSet.emplace_back(nIdx);
675 }
676 else
677 neighborVolVarIndexSet.emplace_back(numScvs_ + numBoundaryScvf_++);
678 }
679
680 // Save the scvf indices belonging to this scv to build up fv element geometries fast
681 scvfIndicesOfScv_[eIdx] = scvfsIndexSet;
682 neighborVolVarIndices_[eIdx] = neighborVolVarIndexSet;
683 }
684
685 // build the connectivity map for an efficient assembly
686 connectivityMap_.update(*this);
687 }
688
689 //! Information on the global number of geometries
690 std::size_t numScvs_;
691 std::size_t numScvf_;
692 std::size_t numBoundaryScvf_;
693 std::vector<std::vector<GridIndexType>> localToGlobalScvfIndices_;
694 std::vector<std::vector<GridIndexType>> neighborVolVarIndices_;
695
696 // mappers
697 ConnectivityMap connectivityMap_;
698 IntersectionMapper intersectionMapper_;
699
700 //! vectors that store the global data
701 std::vector<std::vector<GridIndexType>> scvfIndicesOfScv_;
702 };
703
704 } // end namespace
705
706 #endif
707