GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/box/fvelementgeometry.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 136 136 100.0%
Functions: 65 67 97.0%
Branches: 326 534 61.0%

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 BoxDiscretization
10 * \brief Base class for the local finite volume geometry for box models
11 * This builds up the sub control volumes and sub control volume faces
12 * for an element.
13 */
14 #ifndef DUMUX_DISCRETIZATION_BOX_FV_ELEMENT_GEOMETRY_HH
15 #define DUMUX_DISCRETIZATION_BOX_FV_ELEMENT_GEOMETRY_HH
16
17 #include <optional>
18 #include <utility>
19 #include <unordered_map>
20 #include <array>
21 #include <vector>
22
23 #include <dune/geometry/type.hh>
24 #include <dune/localfunctions/lagrange/pqkfactory.hh>
25
26 #include <dumux/common/indextraits.hh>
27 #include <dumux/discretization/scvandscvfiterators.hh>
28 #include <dumux/discretization/box/boxgeometryhelper.hh>
29
30 namespace Dumux {
31
32 /*!
33 * \ingroup BoxDiscretization
34 * \brief Base class for the finite volume geometry vector for box models
35 * This builds up the sub control volumes and sub control volume faces
36 * for each element.
37 * \tparam GG the finite volume grid geometry type
38 * \tparam enableGridGeometryCache if the grid geometry is cached or not
39 */
40 template<class GG, bool enableGridGeometryCache>
41 class BoxFVElementGeometry;
42
43 //! specialization in case the FVElementGeometries are stored
44 template<class GG>
45
55/113
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 926114 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2688 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 2685 times.
✓ Branch 16 taken 452613 times.
✓ Branch 17 taken 2685 times.
✓ Branch 18 taken 444390 times.
✓ Branch 19 taken 8224 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 8224 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 937437 times.
✓ Branch 25 taken 470 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 937437 times.
✓ Branch 28 taken 666145 times.
✓ Branch 29 taken 1148333 times.
✓ Branch 30 taken 7200 times.
✓ Branch 31 taken 863040 times.
✓ Branch 32 taken 14001 times.
✓ Branch 33 taken 870240 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 21200 times.
✓ Branch 36 taken 2 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 2253 times.
✓ Branch 41 taken 3 times.
✓ Branch 42 taken 21601 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 21607 times.
✓ Branch 45 taken 1189858 times.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 1189860 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 1189858 times.
✓ Branch 51 taken 1 times.
✓ Branch 52 taken 2 times.
✓ Branch 53 taken 1 times.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 56 taken 1 times.
✓ Branch 57 taken 3 times.
✓ Branch 59 taken 1 times.
✗ Branch 60 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✓ Branch 68 taken 3200 times.
✗ Branch 69 not taken.
✓ Branch 71 taken 3200 times.
✗ Branch 72 not taken.
✓ Branch 73 taken 3200 times.
✗ Branch 74 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✓ Branch 80 taken 9600 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 9600 times.
✗ Branch 83 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✓ Branch 89 taken 3200 times.
✗ Branch 90 not taken.
✓ Branch 92 taken 3200 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 3200 times.
✗ Branch 95 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✓ Branch 101 taken 9600 times.
✗ Branch 102 not taken.
✓ Branch 104 taken 9600 times.
✗ Branch 105 not taken.
✓ Branch 106 taken 9600 times.
✗ Branch 107 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✓ Branch 113 taken 1 times.
✗ Branch 114 not taken.
✓ Branch 115 taken 1 times.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 58 not taken.
20146876 class BoxFVElementGeometry<GG, true>
46 {
47 using GridView = typename GG::GridView;
48 static constexpr int dim = GridView::dimension;
49 static constexpr int dimWorld = GridView::dimensionworld;
50 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
51 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
52 using CoordScalar = typename GridView::ctype;
53 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
54 using GGCache = typename GG::Cache;
55 using GeometryHelper = typename GGCache::GeometryHelper;
56 public:
57 //! export the element type
58 using Element = typename GridView::template Codim<0>::Entity;
59 //! export type of subcontrol volume
60 using SubControlVolume = typename GG::SubControlVolume;
61 //! export type of subcontrol volume face
62 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
63 //! export type of finite volume grid geometry
64 using GridGeometry = GG;
65 //! the maximum number of scvs per element (2^dim for cubes)
66 static constexpr std::size_t maxNumElementScvs = (1<<dim);
67
68 /*!
69 * \brief Constructor
70 * \note Never use this directly and always construct this class via `localView(gridGeometry)`
71 */
72 13178220 BoxFVElementGeometry(const GGCache& ggCache)
73
29/45
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 711 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 32 times.
✓ Branch 8 taken 4 times.
✓ Branch 10 taken 1182336 times.
✓ Branch 11 taken 2690 times.
✓ Branch 13 taken 444393 times.
✓ Branch 14 taken 945663 times.
✓ Branch 16 taken 473 times.
✓ Branch 17 taken 673344 times.
✓ Branch 19 taken 210899 times.
✓ Branch 20 taken 23852 times.
✓ Branch 22 taken 5 times.
✓ Branch 23 taken 8 times.
✓ Branch 27 taken 2 times.
✓ Branch 28 taken 3 times.
✓ Branch 30 taken 2 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 39 taken 3200 times.
✗ Branch 40 not taken.
✓ Branch 42 taken 9600 times.
✗ Branch 43 not taken.
✓ Branch 45 taken 3200 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 9600 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✓ Branch 51 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 21 taken 22 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 24 not taken.
✓ Branch 3 taken 926074 times.
✓ Branch 25 taken 1189858 times.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
10911938 : ggCache_(&ggCache) {}
74
75 //! Get a sub control volume with a local scv index
76 703582536 const SubControlVolume& scv(LocalIndexType scvIdx) const
77 {
78
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 189774972 times.
✓ Branch 2 taken 188958572 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 65234916 times.
✓ Branch 6 taken 65234916 times.
✗ Branch 7 not taken.
444052648 return ggCache_->scvs(eIdx_)[scvIdx];
79 }
80
81 //! Get a sub control volume face with a local scvf index
82 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
83 {
84 return ggCache_->scvfs(eIdx_)[scvfIdx];
85 }
86
87 //! iterator range for sub control volumes. Iterates over
88 //! all scvs of the bound element.
89 //! This is a free function found by means of ADL
90 //! To iterate over all sub control volumes of this FVElementGeometry use
91 //! for (auto&& scv : scvs(fvGeometry))
92 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
93 745766733 scvs(const BoxFVElementGeometry& fvGeometry)
94 {
95 using Iter = typename std::vector<SubControlVolume>::const_iterator;
96
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
745766733 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
97
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
745766733 return Dune::IteratorRange<Iter>(s.begin(), s.end());
98 }
99
100 //! iterator range for sub control volumes faces. Iterates over
101 //! all scvfs of the bound element.
102 //! This is a free function found by means of ADL
103 //! To iterate over all sub control volume faces of this FVElementGeometry use
104 //! for (auto&& scvf : scvfs(fvGeometry))
105 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
106 42420359 scvfs(const BoxFVElementGeometry& fvGeometry)
107 {
108 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
109 42420359 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
110 42420359 return Dune::IteratorRange<Iter>(s.begin(), s.end());
111 }
112
113 //! Get a local finite element basis
114 8828525 const FeLocalBasis& feLocalBasis() const
115 {
116
9/19
✓ Branch 2 taken 250900 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 249600 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1300680 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 1121920 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 249600 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 9920 times.
✗ Branch 22 not taken.
✓ Branch 25 taken 9920 times.
✗ Branch 26 not taken.
✓ Branch 17 taken 22120 times.
✓ Branch 1 taken 4952441 times.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
8828525 return gridGeometry().feCache().get(element_->type()).localBasis();
117 }
118
119 //! The total number of sub control volumes
120 101511171 std::size_t numScv() const
121 {
122
11/15
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 230709 times.
✓ Branch 6 taken 947357 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1199778 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 9600 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 9600 times.
✗ Branch 16 not taken.
✓ Branch 2 taken 158504 times.
✓ Branch 3 taken 8697 times.
✓ Branch 5 taken 174168 times.
✓ Branch 8 taken 666144 times.
✓ Branch 4 taken 4887560 times.
101511171 return ggCache_->scvs(eIdx_).size();
123 }
124
125 //! The total number of sub control volume faces
126 1331459 std::size_t numScvf() const
127 {
128
2/4
✓ Branch 1 taken 21309 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3200 times.
✗ Branch 5 not taken.
1331459 return ggCache_->scvfs(eIdx_).size();
129 }
130
131 /*!
132 * \brief bind the local view (r-value overload)
133 * This overload is called when an instance of this class is a temporary in the usage context
134 * This allows a usage like this: `const auto view = localView(...).bind(element);`
135 */
136 149133 BoxFVElementGeometry bind(const Element& element) &&
137 {
138
2/4
✓ Branch 1 taken 139074 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10059 times.
✗ Branch 5 not taken.
149133 this->bindElement(element);
139 149133 return std::move(*this);
140 }
141
142 //! this function is for compatibility reasons with cc methods
143 //! The box stencil is always element-local so bind and bindElement
144 //! are identical.
145 6442470 void bind(const Element& element) &
146
3/6
✓ Branch 1 taken 759 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 138216 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
6442470 { this->bindElement(element); }
147
148 /*!
149 * \brief bind the local view (r-value overload)
150 * This overload is called when an instance of this class is a temporary in the usage context
151 * This allows a usage like this: `const auto view = localView(...).bindElement(element);`
152 */
153 7028239 BoxFVElementGeometry bindElement(const Element& element) &&
154 {
155
5/7
✓ Branch 1 taken 2079169 times.
✓ Branch 2 taken 105046 times.
✓ Branch 4 taken 227357 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1189858 times.
✗ Branch 8 not taken.
✓ Branch 3 taken 15287 times.
7028239 this->bindElement(element);
156
2/3
✓ Branch 1 taken 8430 times.
✗ Branch 2 not taken.
✓ Branch 0 taken 105044 times.
7028239 return std::move(*this);
157 }
158
159 //! Binding of an element, has to be called before using the fvgeometries
160 //! Prepares all the volume variables within the element
161 //! For compatibility reasons with the FVGeometry cache being disabled
162 16568392 void bindElement(const Element& element) &
163 {
164
2/2
✓ Branch 0 taken 1634092 times.
✓ Branch 1 taken 6859127 times.
16568392 element_ = element;
165 // cache element index
166 16568392 eIdx_ = gridGeometry().elementMapper().index(element);
167 16568392 }
168
169 //! Returns true if bind/bindElement has already been called
170 101153 bool isBound() const
171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
101109 { return static_cast<bool>(element_); }
172
173 //! The bound element
174 27979871 const Element& element() const
175
6/9
✓ Branch 0 taken 57576 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 143336 times.
✓ Branch 3 taken 16728 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 608 times.
✗ Branch 8 not taken.
✓ Branch 5 taken 608 times.
✗ Branch 6 not taken.
33528927 { return *element_; }
176
177 //! The bound element's index in the grid view
178 252800 GridIndexType elementIndex() const
179 252800 { return eIdx_; }
180
181 //! The grid geometry we are a restriction of
182 67564745 const GridGeometry& gridGeometry() const
183
32/46
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 9773783 times.
✓ Branch 8 taken 2565 times.
✓ Branch 10 taken 212686 times.
✓ Branch 11 taken 192840 times.
✓ Branch 13 taken 5020153 times.
✓ Branch 14 taken 8216 times.
✓ Branch 16 taken 4562888 times.
✓ Branch 17 taken 131816 times.
✓ Branch 19 taken 4366642 times.
✓ Branch 20 taken 42076 times.
✓ Branch 25 taken 1093766 times.
✓ Branch 26 taken 14000 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 10909 times.
✓ Branch 34 taken 948 times.
✓ Branch 35 taken 75820 times.
✓ Branch 36 taken 950 times.
✓ Branch 37 taken 18252 times.
✓ Branch 46 taken 9920 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 9920 times.
✗ Branch 50 not taken.
✓ Branch 53 taken 3200 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 3200 times.
✗ Branch 57 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 6 taken 764951 times.
✓ Branch 9 taken 999 times.
✓ Branch 12 taken 25192 times.
✓ Branch 15 taken 213072 times.
✓ Branch 18 taken 1379696 times.
✓ Branch 23 taken 1182327 times.
✓ Branch 24 taken 48540 times.
✗ Branch 27 not taken.
✓ Branch 32 taken 1548 times.
✓ Branch 33 taken 41654 times.
✓ Branch 38 taken 22120 times.
✗ Branch 39 not taken.
✓ Branch 42 taken 7200 times.
✗ Branch 43 not taken.
✗ Branch 1 not taken.
✗ Branch 30 not taken.
67735399 { return ggCache_->gridGeometry(); }
184
185 //! Returns whether one of the geometry's scvfs lies on a boundary
186 2291779 bool hasBoundaryScvf() const
187
12/12
✓ Branch 0 taken 214192 times.
✓ Branch 1 taken 1733943 times.
✓ Branch 2 taken 302372 times.
✓ Branch 3 taken 23020 times.
✓ Branch 4 taken 6778 times.
✓ Branch 5 taken 1804 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 28 times.
✓ Branch 8 taken 432 times.
✓ Branch 9 taken 592 times.
✓ Branch 10 taken 6778 times.
✓ Branch 11 taken 1804 times.
2291779 { return ggCache_->hasBoundaryScvf(eIdx_); }
188
189 //! Geometry of a sub control volume
190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27584 times.
28424 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
191 {
192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27584 times.
28424 assert(isBound());
193
1/2
✓ Branch 1 taken 17944 times.
✗ Branch 2 not taken.
28424 const auto geo = element().geometry();
194
2/4
✓ Branch 1 taken 26952 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26952 times.
✗ Branch 5 not taken.
28424 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
195 9008 }
196
197 //! Geometry of a sub control volume face
198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73568 times.
89644 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
199 {
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73568 times.
89644 assert(isBound());
201
2/3
✓ Branch 0 taken 62696 times.
✓ Branch 1 taken 10872 times.
✗ Branch 2 not taken.
89644 const auto geo = element().geometry();
202
2/2
✓ Branch 0 taken 73556 times.
✓ Branch 1 taken 12 times.
89644 const GeometryHelper geometryHelper(geo);
203
2/2
✓ Branch 0 taken 73556 times.
✓ Branch 1 taken 12 times.
89644 if (scvf.boundary())
204 {
205
1/2
✓ Branch 1 taken 10860 times.
✗ Branch 2 not taken.
89632 const auto localBoundaryIndex = scvf.index() - geometryHelper.numInteriorScvf();
206
2/4
✓ Branch 1 taken 10860 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10860 times.
✗ Branch 5 not taken.
89632 const auto& key = ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localBoundaryIndex];
207
1/2
✓ Branch 1 taken 10860 times.
✗ Branch 2 not taken.
179072 return { Dune::GeometryTypes::cube(dim-1), geometryHelper.getBoundaryScvfCorners(key[0], key[1]) };
208 }
209 else
210
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12 return { Dune::GeometryTypes::cube(dim-1), geometryHelper.getScvfCorners(scvf.index()) };
211 21720 }
212
213 private:
214 const GGCache* ggCache_;
215 GridIndexType eIdx_;
216
217 std::optional<Element> element_;
218 };
219
220 //! specialization in case the FVElementGeometries are not stored
221 template<class GG>
222 class BoxFVElementGeometry<GG, false>
223 {
224 using GridView = typename GG::GridView;
225 static constexpr int dim = GridView::dimension;
226 static constexpr int dimWorld = GridView::dimensionworld;
227 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
228 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
229 using CoordScalar = typename GridView::ctype;
230 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
231 using GGCache = typename GG::Cache;
232 using GeometryHelper = typename GGCache::GeometryHelper;
233 public:
234 //! export the element type
235 using Element = typename GridView::template Codim<0>::Entity;
236 //! export type of subcontrol volume
237 using SubControlVolume = typename GG::SubControlVolume;
238 //! export type of subcontrol volume face
239 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
240 //! export type of finite volume grid geometry
241 using GridGeometry = GG;
242 //! the maximum number of scvs per element (2^dim for cubes)
243 static constexpr std::size_t maxNumElementScvs = (1<<dim);
244
245 /*!
246 * \brief Constructor
247 * \note Never use this directly and always construct this class via `localView(gridGeometry)`
248 */
249 5405932 BoxFVElementGeometry(const GGCache& ggCache)
250
15/23
✓ Branch 1 taken 267 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11376 times.
✓ Branch 5 taken 4466 times.
✓ Branch 7 taken 2324442 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1732932 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 108849 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 387697 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 32261 times.
✗ Branch 20 not taken.
✓ Branch 6 taken 16 times.
✓ Branch 3 taken 5541 times.
✗ Branch 0 not taken.
✓ Branch 9 taken 2 times.
✓ Branch 12 taken 30330 times.
✓ Branch 15 taken 1 times.
✓ Branch 18 taken 2 times.
✓ Branch 22 taken 604311 times.
✗ Branch 23 not taken.
5405932 : ggCache_(&ggCache) {}
251
252 //! Get a sub control volume with a local scv index
253 983342804 const SubControlVolume& scv(LocalIndexType scvIdx) const
254 {
255
11/13
✗ Branch 0 not taken.
✓ Branch 1 taken 177421638 times.
✓ Branch 2 taken 166701475 times.
✓ Branch 3 taken 11282051 times.
✓ Branch 5 taken 212974988 times.
✓ Branch 6 taken 212812296 times.
✓ Branch 7 taken 1624396 times.
✓ Branch 8 taken 161900 times.
✓ Branch 9 taken 2919449 times.
✓ Branch 10 taken 313071 times.
✓ Branch 11 taken 16 times.
✓ Branch 12 taken 112548 times.
✗ Branch 4 not taken.
590725178 return scvs_[scvIdx];
256 }
257
258 //! Get a sub control volume face with a local scvf index
259 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
260 {
261 return scvfs_[scvfIdx];
262 }
263
264 //! iterator range for sub control volumes. Iterates over
265 //! all scvs of the bound element.
266 //! This is a free function found by means of ADL
267 //! To iterate over all sub control volumes of this FVElementGeometry use
268 //! for (auto&& scv : scvs(fvGeometry))
269 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
270 1152810231 scvs(const BoxFVElementGeometry& fvGeometry)
271 {
272 using Iter = typename std::vector<SubControlVolume>::const_iterator;
273
1/2
✓ Branch 1 taken 234 times.
✗ Branch 2 not taken.
1152810231 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
274 }
275
276 //! iterator range for sub control volumes faces. Iterates over
277 //! all scvfs of the bound element.
278 //! This is a free function found by means of ADL
279 //! To iterate over all sub control volume faces of this FVElementGeometry use
280 //! for (auto&& scvf : scvfs(fvGeometry))
281 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
282 45932916 scvfs(const BoxFVElementGeometry& fvGeometry)
283 {
284 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
285 45932916 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
286 }
287
288 //! Get a local finite element basis
289 16696687 const FeLocalBasis& feLocalBasis() const
290 {
291
1/2
✓ Branch 1 taken 5362908 times.
✗ Branch 2 not taken.
16696687 return gridGeometry().feCache().get(element_->type()).localBasis();
292 }
293
294 //! The total number of sub control volumes
295 124044318 std::size_t numScv() const
296 {
297
14/19
✓ Branch 1 taken 495969 times.
✓ Branch 2 taken 244172 times.
✓ Branch 6 taken 1410 times.
✓ Branch 7 taken 146368 times.
✓ Branch 8 taken 695680 times.
✓ Branch 9 taken 312788 times.
✓ Branch 11 taken 52000 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 100000 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 25280 times.
✓ Branch 20 taken 12640 times.
✓ Branch 23 taken 304 times.
✗ Branch 24 not taken.
✓ Branch 4 taken 5611742 times.
✗ Branch 5 not taken.
✗ Branch 10 not taken.
✓ Branch 0 taken 3 times.
✓ Branch 3 taken 604300 times.
124044318 return scvs_.size();
298 }
299
300 //! The total number of sub control volume faces
301 4358279 std::size_t numScvf() const
302 {
303
1/2
✓ Branch 3 taken 100 times.
✗ Branch 4 not taken.
4358279 return scvfs_.size();
304 }
305
306 /*!
307 * \brief bind the local view (r-value overload)
308 * This overload is called when an instance of this class is a temporary in the usage context
309 * This allows a usage like this: `const auto view = localView(...).bind(element);`
310 */
311 BoxFVElementGeometry bind(const Element& element) &&
312 {
313 this->bindElement(element);
314 return std::move(*this);
315 }
316
317 //! this function is for compatibility reasons with cc methods
318 //! The box stencil is always element-local so bind and bindElement
319 //! are identical.
320 4360675 void bind(const Element& element) &
321
5/11
✓ Branch 1 taken 58120 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 144538 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14240 times.
✓ Branch 8 taken 14102 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 15 taken 100 times.
✗ Branch 16 not taken.
✗ Branch 9 not taken.
4360675 { this->bindElement(element); }
322
323 /*!
324 * \brief bind the local view (r-value overload)
325 * This overload is called when an instance of this class is a temporary in the usage context
326 * This allows a usage like this: `const auto view = localView(...).bindElement(element);`
327 */
328 1060899 BoxFVElementGeometry bindElement(const Element& element) &&
329 {
330
3/6
✓ Branch 1 taken 312599 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 144000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 604300 times.
✗ Branch 8 not taken.
1060899 this->bindElement(element);
331 1060899 return std::move(*this);
332 }
333
334 //! Binding of an element, has to be called before using the fvgeometries
335 //! Prepares all the volume variables within the element
336 //! For compatibility reasons with the FVGeometry cache being disabled
337 8798093 void bindElement(const Element& element) &
338 {
339
2/2
✓ Branch 0 taken 1831608 times.
✓ Branch 1 taken 3888104 times.
8798093 element_ = element;
340 8798093 eIdx_ = gridGeometry().elementMapper().index(element);
341 8798093 makeElementGeometries_();
342 8798093 }
343
344 //! Returns true if bind/bindElement has already been called
345 277 bool isBound() const
346
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
233 { return static_cast<bool>(element_); }
347
348 //! The bound element
349 40617889 const Element& element() const
350
3/5
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 100 times.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 2 not taken.
40825285 { return *element_; }
351
352 //! The bound element's index in the grid view
353 GridIndexType elementIndex() const
354 { return eIdx_; }
355
356 //! The grid geometry we are a restriction of
357 95545429 const GridGeometry& gridGeometry() const
358
12/14
✓ Branch 1 taken 5961337 times.
✓ Branch 2 taken 3750701 times.
✓ Branch 3 taken 4139071 times.
✓ Branch 4 taken 5034879 times.
✓ Branch 5 taken 203879 times.
✓ Branch 6 taken 1418494 times.
✓ Branch 7 taken 16434 times.
✓ Branch 8 taken 5850 times.
✓ Branch 0 taken 2480 times.
✓ Branch 9 taken 58416 times.
✓ Branch 10 taken 12077286 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2999526 times.
✗ Branch 14 not taken.
95337697 { return ggCache_->gridGeometry(); }
359
360 //! Returns whether one of the geometry's scvfs lies on a boundary
361 3028328 bool hasBoundaryScvf() const
362
4/5
✓ Branch 0 taken 399218 times.
✓ Branch 1 taken 2172812 times.
✓ Branch 2 taken 413268 times.
✓ Branch 3 taken 43030 times.
✗ Branch 4 not taken.
3028328 { return hasBoundaryScvf_; }
363
364 //! Geometry of a sub control volume
365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
366 {
367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 assert(isBound());
368
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
240 const auto geo = element().geometry();
369
2/4
✓ Branch 1 taken 240 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
472 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
370 }
371
372 //! Geometry of a sub control volume face
373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
374 {
375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 assert(isBound());
376
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 const auto geo = element().geometry();
377
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 const GeometryHelper geometryHelper(geo);
378
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 if (scvf.boundary())
379 {
380 24 const auto localBoundaryIndex = scvf.index() - geometryHelper.numInteriorScvf();
381 24 const auto& key = scvfBoundaryGeometryKeys_[localBoundaryIndex];
382 48 return { Dune::GeometryTypes::cube(dim-1), geometryHelper.getBoundaryScvfCorners(key[0], key[1]) };
383 }
384 else
385 12 return { Dune::GeometryTypes::cube(dim-1), geometryHelper.getScvfCorners(scvf.index()) };
386 }
387
388 private:
389 8798093 void makeElementGeometries_()
390 {
391 8798093 hasBoundaryScvf_ = false;
392
393 // get the element geometry
394 8798093 const auto& element = *element_;
395
1/2
✓ Branch 1 taken 3038349 times.
✗ Branch 2 not taken.
8798093 const auto elementGeometry = element.geometry();
396
1/2
✓ Branch 1 taken 3038349 times.
✗ Branch 2 not taken.
8798093 const auto refElement = referenceElement(elementGeometry);
397
398 // get the sub control volume geometries of this element
399 8798093 GeometryHelper geometryHelper(elementGeometry);
400
401 // construct the sub control volumes
402
1/2
✓ Branch 1 taken 3038349 times.
✗ Branch 2 not taken.
8798093 scvs_.resize(elementGeometry.corners());
403
3/3
✓ Branch 0 taken 29419190 times.
✓ Branch 1 taken 9034601 times.
✓ Branch 2 taken 236508 times.
38690299 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
404 {
405 // get associated dof index
406
1/2
✓ Branch 1 taken 12153396 times.
✗ Branch 2 not taken.
29892206 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
407
408 // add scv to the local container
409
1/2
✓ Branch 1 taken 12153396 times.
✗ Branch 2 not taken.
56681954 scvs_[scvLocalIdx] = SubControlVolume(
410 32994664 geometryHelper.getScvCorners(scvLocalIdx),
411 scvLocalIdx,
412 eIdx_,
413 dofIdxGlobal
414 );
415 }
416
417 // construct the sub control volume faces
418
1/2
✓ Branch 1 taken 3038349 times.
✗ Branch 2 not taken.
8798093 const auto numInnerScvf = geometryHelper.numInteriorScvf();
419
1/2
✓ Branch 1 taken 3038349 times.
✗ Branch 2 not taken.
8798093 scvfs_.resize(numInnerScvf);
420
2/2
✓ Branch 0 taken 426514 times.
✓ Branch 1 taken 8371579 times.
8798093 scvfBoundaryGeometryKeys_.clear();
421
422 8798093 LocalIndexType scvfLocalIdx = 0;
423
2/2
✓ Branch 0 taken 27339198 times.
✓ Branch 1 taken 8798093 times.
36137291 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
424 {
425 // find the local scv indices this scvf is connected to
426
1/2
✓ Branch 2 taken 27339198 times.
✗ Branch 3 not taken.
54678396 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
427
1/2
✓ Branch 2 taken 12154914 times.
✗ Branch 3 not taken.
27339198 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
428
429
1/2
✓ Branch 1 taken 27339198 times.
✗ Branch 2 not taken.
27339198 const auto& corners = geometryHelper.getScvfCorners(scvfLocalIdx);
430 29769976 scvfs_[scvfLocalIdx] = SubControlVolumeFace(
431 corners,
432
1/2
✓ Branch 1 taken 3189614 times.
✗ Branch 2 not taken.
52247618 geometryHelper.normal(corners, localScvIndices),
433 element,
434 elementGeometry,
435 scvfLocalIdx,
436 std::move(localScvIndices),
437 false
438 );
439 }
440
441 // construct the sub control volume faces on the domain boundary
442
11/13
✓ Branch 1 taken 7748139 times.
✓ Branch 2 taken 14923948 times.
✓ Branch 7 taken 15768772 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 15702481 times.
✓ Branch 10 taken 2331226 times.
✓ Branch 11 taken 18655 times.
✓ Branch 12 taken 507742 times.
✓ Branch 3 taken 209178 times.
✓ Branch 4 taken 6359847 times.
✓ Branch 5 taken 8921352 times.
✓ Branch 6 taken 802937 times.
✗ Branch 0 not taken.
78121273 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
443 {
444
4/5
✓ Branch 0 taken 532341 times.
✓ Branch 1 taken 17665274 times.
✓ Branch 2 taken 8376017 times.
✓ Branch 3 taken 3581948 times.
✗ Branch 4 not taken.
32196849 if (intersection.boundary() && !intersection.neighbor())
445 {
446 1512453 const auto isGeometry = intersection.geometry();
447 1512453 hasBoundaryScvf_ = true;
448
449
3/3
✓ Branch 0 taken 2467997 times.
✓ Branch 1 taken 1777473 times.
✓ Branch 2 taken 254412 times.
4499882 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
450 {
451 // find the scv this scvf is connected to
452
1/3
✓ Branch 1 taken 436311 times.
✗ Branch 2 not taken.
✗ Branch 0 not taken.
2987429 const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
453
1/4
✓ Branch 1 taken 2987429 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2987429 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
454
455
1/2
✓ Branch 1 taken 84374 times.
✗ Branch 2 not taken.
2987429 scvfs_.emplace_back(
456
2/4
✓ Branch 1 taken 2921981 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 416432 times.
✗ Branch 5 not taken.
3469309 geometryHelper.getBoundaryScvfCorners(intersection.indexInInside(), isScvfLocalIdx),
457
2/3
✓ Branch 0 taken 24488 times.
✓ Branch 1 taken 2962941 times.
✗ Branch 2 not taken.
2987429 intersection.centerUnitOuterNormal(),
458 intersection,
459 isGeometry,
460 isScvfLocalIdx,
461 scvfLocalIdx,
462 std::move(localScvIndices),
463
2/3
✓ Branch 0 taken 1014692 times.
✓ Branch 1 taken 1972737 times.
✗ Branch 2 not taken.
2987429 true
464 );
465
466
1/3
✓ Branch 1 taken 2987429 times.
✗ Branch 2 not taken.
✗ Branch 0 not taken.
2987429 scvfBoundaryGeometryKeys_.emplace_back(std::array<LocalIndexType, 2>{{
467
1/2
✓ Branch 1 taken 2987429 times.
✗ Branch 2 not taken.
2987429 static_cast<LocalIndexType>(intersection.indexInInside()),
468 static_cast<LocalIndexType>(isScvfLocalIdx)
469 }});
470
471 // increment local counter
472 2987429 scvfLocalIdx++;
473 }
474 463036 }
475 }
476 8798093 }
477
478 //! The bound element
479 GridIndexType eIdx_;
480 std::optional<Element> element_;
481
482 //! The global geometry cache
483 const GGCache* ggCache_;
484
485 //! vectors to store the geometries locally after binding an element
486 std::vector<SubControlVolume> scvs_;
487 std::vector<SubControlVolumeFace> scvfs_;
488 std::vector<std::array<LocalIndexType, 2>> scvfBoundaryGeometryKeys_;
489
490 bool hasBoundaryScvf_ = false;
491 };
492
493 } // end namespace Dumux
494
495 #endif
496