GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/multidomain/facet/box/fvelementgeometry.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 68 72 94.4%
Functions: 12 19 63.2%
Branches: 267 447 59.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-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 FacetCoupling
10 * \brief \copydoc Dumux::BoxFacetCouplingFVElementGeometry
11 */
12 #ifndef DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
13 #define DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
14
15 #include <algorithm>
16 #include <optional>
17
18 #include <dune/geometry/type.hh>
19
20 #include <dumux/common/indextraits.hh>
21 #include <dumux/discretization/scvandscvfiterators.hh>
22 #include <dumux/discretization/box/boxgeometryhelper.hh>
23
24 namespace Dumux {
25
26 /*!
27 * \ingroup FacetCoupling
28 * \brief Base class for the element-local finite volume geometry for box models
29 * in the context of models considering coupling of different domains across the
30 * bulk grid facets. This builds up the sub control volumes and sub control volume
31 * faces for an element.
32 * \tparam GG the finite volume grid geometry type
33 * \tparam enableGridGeometryCache if the grid geometry is cached or not
34 */
35 template<class GG, bool enableGridGeometryCache>
36 class BoxFacetCouplingFVElementGeometry;
37
38 //! specialization in case the FVElementGeometries are stored
39 template<class GG>
40
4/14
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
136 class BoxFacetCouplingFVElementGeometry<GG, true>
41 {
42 using GridView = typename GG::GridView;
43 static constexpr int dim = GridView::dimension;
44 static constexpr int dimWorld = GridView::dimensionworld;
45 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
46 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
47 using CoordScalar = typename GridView::ctype;
48 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
49
50 using GeometryHelper = typename GG::GeometryHelper;
51 public:
52 //! export type of the element
53 using Element = typename GridView::template Codim<0>::Entity;
54 //! export type of subcontrol volume
55 using SubControlVolume = typename GG::SubControlVolume;
56 //! export type of subcontrol volume face
57 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
58 //! export type of finite volume grid geometry
59 using GridGeometry = GG;
60 //! the maximum number of scvs per element (2^dim for cubes)
61 static constexpr std::size_t maxNumElementScvs = (1<<dim);
62
63 //! Constructor
64 BoxFacetCouplingFVElementGeometry(const GridGeometry& gridGeometry)
65 272 : gridGeometryPtr_(&gridGeometry)
66 {}
67
68 //! Get a sub control volume with a local scv index
69 const SubControlVolume& scv(LocalIndexType scvIdx) const
70
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 768 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 768 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 768 times.
2304 { return gridGeometry().scvs(eIdx_)[scvIdx]; }
71
72 //! Get a sub control volume face with a local scvf index
73 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
74
11/22
✓ Branch 1 taken 768 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 768 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 768 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 768 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 768 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 768 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 768 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 768 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 768 times.
✓ Branch 25 taken 768 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 768 times.
✗ Branch 29 not taken.
6912 { return gridGeometry().scvfs(eIdx_)[scvfIdx]; }
75
76 //! iterator range for sub control volumes. Iterates over
77 //! all scvs of the bound element.
78 //! This is a free function found by means of ADL
79 //! To iterate over all sub control volumes of this FVElementGeometry use
80 //! for (auto&& scv : scvs(fvGeometry))
81 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
82 scvs(const BoxFacetCouplingFVElementGeometry& fvGeometry)
83 {
84 const auto& g = fvGeometry.gridGeometry();
85 using Iter = typename std::vector<SubControlVolume>::const_iterator;
86 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
87 }
88
89 //! iterator range for sub control volumes faces. Iterates over
90 //! all scvfs of the bound element.
91 //! This is a free function found by means of ADL
92 //! To iterate over all sub control volume faces of this FVElementGeometry use
93 //! for (auto&& scvf : scvfs(fvGeometry))
94 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
95 scvfs(const BoxFacetCouplingFVElementGeometry& fvGeometry)
96 {
97 256 const auto& g = fvGeometry.gridGeometry();
98 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
99 1280 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
100 }
101
102 //! Get a local finite element basis
103 const FeLocalBasis& feLocalBasis() const
104 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
105
106 //! The total number of sub control volumes
107 std::size_t numScv() const
108 { return gridGeometry().scvs(eIdx_).size(); }
109
110 //! The total number of sub control volume faces
111 std::size_t numScvf() const
112 { return gridGeometry().scvfs(eIdx_).size(); }
113
114 /*!
115 * \brief bind the local view (r-value overload)
116 * This overload is called when an instance of this class is a temporary in the usage context
117 * This allows a usage like this: `const auto view = localView(...).bind(element);`
118 */
119 BoxFacetCouplingFVElementGeometry bind(const Element& element) &&
120 {
121 this->bindElement(element);
122 return std::move(*this);
123 }
124
125 //! this function is for compatibility reasons with cc methods
126 //! The box stencil is always element-local so bind and bindElement
127 //! are identical.
128 void bind(const Element& element) &
129
2/4
✓ Branch 1 taken 224 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 256 times.
✗ Branch 5 not taken.
480 { this->bindElement(element); }
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(...).bindElement(element);`
135 */
136 BoxFacetCouplingFVElementGeometry bindElement(const Element& element) &&
137 {
138 this->bindElement(element);
139 return std::move(*this);
140 }
141
142 //! Binding of an element, has to be called before using the fvgeometries
143 //! Prepares all the volume variables within the element
144 //! For compatibility reasons with the FVGeometry cache being disabled
145 736 void bindElement(const Element& element) &
146 {
147
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 68 times.
736 element_ = element;
148 1472 eIdx_ = gridGeometry().elementMapper().index(element);
149 736 }
150
151 //! The global finite volume geometry we are a restriction of
152 const GridGeometry& gridGeometry() const
153 { return *gridGeometryPtr_; }
154
155 //! Returns true if bind/bindElement has already been called
156 bool isBound() const
157 { return static_cast<bool>(element_); }
158
159 //! The bound element
160 const Element& element() const
161 { return *element_; }
162
163 //! Create the geometry of a given sub control volume
164 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
165 {
166 assert(isBound());
167 const auto geo = element().geometry();
168 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
169 }
170
171 //! Create the geometry of a given sub control volume face
172 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
173 {
174 assert(isBound());
175 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
176 const GeometryHelper geometryHelper(element().geometry());
177 if (scvf.boundary() || scvf.interiorBoundary())
178 return {
179 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
180 geometryHelper.getBoundaryScvfCorners(
181 scvf.facetIndexInElement(),
182 scvf.indexInElementFacet()
183 )
184 };
185
186 return {
187 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
188 geometryHelper.getScvfCorners(scvf.index())
189 };
190 }
191
192 private:
193 const GridGeometry* gridGeometryPtr_;
194
195 GridIndexType eIdx_;
196 std::optional<Element> element_;
197 };
198
199 //! specialization in case the geometries are not stored grid-wide
200 template<class GG>
201 class BoxFacetCouplingFVElementGeometry<GG, false>
202 {
203 using GridView = typename GG::GridView;
204 static constexpr int dim = GridView::dimension;
205 static constexpr int dimWorld = GridView::dimensionworld;
206
207 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
208 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
209
210 using CoordScalar = typename GridView::ctype;
211 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
212
213 using GeometryHelper = typename GG::GeometryHelper;
214 public:
215 //! export type of the element
216 using Element = typename GridView::template Codim<0>::Entity;
217 //! export type of subcontrol volume
218 using SubControlVolume = typename GG::SubControlVolume;
219 //! export type of subcontrol volume face
220 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
221 //! export type of finite volume grid geometry
222 using GridGeometry = GG;
223 //! the maximum number of scvs per element (2^dim for cubes)
224 static constexpr std::size_t maxNumElementScvs = (1<<dim);
225
226 //! Constructor
227 BoxFacetCouplingFVElementGeometry(const GridGeometry& gridGeometry)
228
92/148
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 9 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 12 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 12 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 12 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 12 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 4477 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 4477 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 4477 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 352 times.
✓ Branch 34 taken 4477 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 352 times.
✓ Branch 37 taken 19 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 352 times.
✓ Branch 40 taken 19 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 352 times.
✓ Branch 43 taken 19 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 16 times.
✓ Branch 46 taken 19 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 16 times.
✓ Branch 49 taken 419 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 16 times.
✓ Branch 52 taken 419 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 16 times.
✓ Branch 55 taken 419 times.
✗ Branch 56 not taken.
✓ Branch 57 taken 64 times.
✓ Branch 58 taken 419 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 64 times.
✓ Branch 61 taken 8789 times.
✗ Branch 62 not taken.
✓ Branch 63 taken 64 times.
✓ Branch 64 taken 8789 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 64 times.
✓ Branch 67 taken 8789 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 8789 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 260097 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 260097 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 260097 times.
✗ Branch 80 not taken.
✓ Branch 81 taken 1 times.
✓ Branch 82 taken 260097 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 1 times.
✓ Branch 85 taken 788 times.
✗ Branch 86 not taken.
✓ Branch 87 taken 1 times.
✓ Branch 88 taken 788 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 1 times.
✓ Branch 91 taken 788 times.
✗ Branch 92 not taken.
✓ Branch 93 taken 1 times.
✓ Branch 94 taken 788 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 1 times.
✓ Branch 97 taken 50000 times.
✗ Branch 98 not taken.
✓ Branch 99 taken 1 times.
✓ Branch 100 taken 50000 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 1 times.
✓ Branch 103 taken 50000 times.
✗ Branch 104 not taken.
✓ Branch 105 taken 1 times.
✓ Branch 106 taken 50000 times.
✗ Branch 107 not taken.
✓ Branch 108 taken 1 times.
✓ Branch 109 taken 98500 times.
✗ Branch 110 not taken.
✓ Branch 111 taken 1 times.
✓ Branch 112 taken 98500 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 1 times.
✓ Branch 115 taken 98500 times.
✗ Branch 116 not taken.
✓ Branch 117 taken 640 times.
✓ Branch 118 taken 98500 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 640 times.
✓ Branch 121 taken 7712 times.
✗ Branch 122 not taken.
✓ Branch 123 taken 640 times.
✓ Branch 124 taken 7712 times.
✗ Branch 125 not taken.
✓ Branch 126 taken 640 times.
✓ Branch 127 taken 7712 times.
✗ Branch 128 not taken.
✓ Branch 129 taken 352 times.
✓ Branch 130 taken 7712 times.
✗ Branch 131 not taken.
✓ Branch 132 taken 352 times.
✓ Branch 133 taken 964000 times.
✗ Branch 134 not taken.
✓ Branch 135 taken 352 times.
✓ Branch 136 taken 964000 times.
✗ Branch 137 not taken.
✓ Branch 138 taken 352 times.
✓ Branch 139 taken 964000 times.
✗ Branch 140 not taken.
✓ Branch 141 taken 7708 times.
✓ Branch 142 taken 964000 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 7708 times.
✓ Branch 145 taken 297 times.
✗ Branch 146 not taken.
✓ Branch 147 taken 7708 times.
✓ Branch 148 taken 297 times.
✗ Branch 149 not taken.
✓ Branch 150 taken 7708 times.
✓ Branch 151 taken 297 times.
✗ Branch 152 not taken.
✓ Branch 154 taken 297 times.
✗ Branch 155 not taken.
✓ Branch 157 taken 1 times.
✗ Branch 158 not taken.
✓ Branch 160 taken 1 times.
✗ Branch 161 not taken.
✓ Branch 163 taken 1 times.
✗ Branch 164 not taken.
✓ Branch 166 taken 1 times.
✗ Branch 167 not taken.
5845880 : gridGeometryPtr_(&gridGeometry)
229 {}
230
231 //! Get a sub control volume with a local scv index
232 const SubControlVolume& scv(LocalIndexType scvIdx) const
233
44/48
✓ Branch 0 taken 36640 times.
✓ Branch 1 taken 92544 times.
✓ Branch 2 taken 9013792 times.
✓ Branch 3 taken 92544 times.
✓ Branch 4 taken 9024228 times.
✓ Branch 5 taken 45468 times.
✓ Branch 6 taken 1105972 times.
✓ Branch 7 taken 11979900 times.
✓ Branch 8 taken 1690136 times.
✓ Branch 9 taken 14826432 times.
✓ Branch 10 taken 7308192 times.
✓ Branch 11 taken 8149480 times.
✓ Branch 12 taken 8137932 times.
✓ Branch 13 taken 6697204 times.
✓ Branch 14 taken 1460994 times.
✓ Branch 15 taken 1574430 times.
✓ Branch 16 taken 4242044 times.
✓ Branch 17 taken 136772 times.
✓ Branch 18 taken 4242030 times.
✓ Branch 19 taken 2066 times.
✓ Branch 20 taken 745473 times.
✓ Branch 21 taken 8484223 times.
✓ Branch 22 taken 745473 times.
✓ Branch 23 taken 8484223 times.
✓ Branch 24 taken 4761904 times.
✓ Branch 25 taken 4010136 times.
✓ Branch 26 taken 4761904 times.
✓ Branch 27 taken 4010136 times.
✓ Branch 28 taken 214047 times.
✓ Branch 29 taken 115521 times.
✓ Branch 30 taken 214047 times.
✓ Branch 31 taken 115521 times.
✓ Branch 32 taken 401 times.
✓ Branch 33 taken 66839 times.
✓ Branch 34 taken 401 times.
✓ Branch 35 taken 66839 times.
✓ Branch 36 taken 2913 times.
✓ Branch 37 taken 2871 times.
✓ Branch 38 taken 2913 times.
✓ Branch 39 taken 2871 times.
✓ Branch 40 taken 1 times.
✓ Branch 41 taken 37039 times.
✓ Branch 42 taken 1 times.
✓ Branch 43 taken 37039 times.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
158316660 { return scvs_[scvIdx]; }
234
235 //! Get a sub control volume face with a local scvf index
236 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
237
14/28
✗ Branch 0 not taken.
✓ Branch 1 taken 715792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 715792 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 169712 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 169712 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6912 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 252684 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 258444 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 316672 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 304000 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 12640 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 13440 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 800 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 22368 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 22368 times.
3236600 { return scvfs_[scvfIdx]; }
238
239 //! iterator range for sub control volumes. Iterates over
240 //! all scvs of the bound element.
241 //! This is a free function found by means of ADL
242 //! To iterate over all sub control volumes of this FVElementGeometry use
243 //! for (auto&& scv : scvs(fvGeometry))
244 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
245 scvs(const BoxFacetCouplingFVElementGeometry& fvGeometry)
246 {
247 using Iter = typename std::vector<SubControlVolume>::const_iterator;
248 163084713 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
249 }
250
251 //! iterator range for sub control volumes faces. Iterates over
252 //! all scvfs of the bound element.
253 //! This is a free function found by means of ADL
254 //! To iterate over all sub control volume faces of this FVElementGeometry use
255 //! for (auto&& scvf : scvfs(fvGeometry))
256 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
257 scvfs(const BoxFacetCouplingFVElementGeometry& fvGeometry)
258 {
259 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
260 13972236 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
261 }
262
263 //! Get a local finite element basis
264 const FeLocalBasis& feLocalBasis() const
265
10/19
✓ Branch 1 taken 4820256 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4820256 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4884264 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4884264 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 64008 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 36690 times.
✓ Branch 16 taken 64008 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 36690 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 36690 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 36690 times.
✗ Branch 25 not taken.
19690856 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
266
267 //! The total number of sub control volumes
268 std::size_t numScv() const
269
11/14
✓ Branch 1 taken 4820256 times.
✓ Branch 2 taken 64008 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 31467 times.
✓ Branch 5 taken 416 times.
✓ Branch 6 taken 36690 times.
✓ Branch 7 taken 67104 times.
✓ Branch 8 taken 22368 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 2111 times.
✓ Branch 19 taken 704 times.
✗ Branch 20 not taken.
20350060 { return scvs_.size(); }
270
271 //! The total number of sub control volume faces
272 std::size_t numScvf() const
273
1/2
✓ Branch 3 taken 1928 times.
✗ Branch 4 not taken.
1354280 { return scvfs_.size(); }
274
275 /*!
276 * \brief bind the local view (r-value overload)
277 * This overload is called when an instance of this class is a temporary in the usage context
278 * This allows a usage like this: `const auto view = localView(...).bind(element);`
279 */
280 BoxFacetCouplingFVElementGeometry bind(const Element& element) &&
281 {
282 this->bindElement(element);
283 return std::move(*this);
284 }
285
286 //! this function is for compatibility reasons with cc methods
287 //! The box stencil is always element-local so bind and bindElement
288 //! are identical.
289 void bind(const Element& element) &
290
6/17
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 8788 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 13 taken 1504 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 64 times.
✓ Branch 17 taken 100000 times.
✗ Branch 18 not taken.
✓ Branch 21 taken 200 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 1928 times.
✗ Branch 25 not taken.
1352352 { this->bindElement(element); }
291
292 /*!
293 * \brief bind the local view (r-value overload)
294 * This overload is called when an instance of this class is a temporary in the usage context
295 * This allows a usage like this: `const auto view = localView(...).bindElement(element);`
296 */
297 BoxFacetCouplingFVElementGeometry bindElement(const Element& element) &&
298 {
299
5/10
✓ Branch 1 taken 5218 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9592 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 50064 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 99140 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 297 times.
✗ Branch 14 not taken.
164311 this->bindElement(element);
300 164311 return std::move(*this);
301 }
302
303 //! Binding of an element, has to be called before using the fvgeometries
304 //! Prepares all the volume variables within the element
305 //! For compatibility reasons with the FVGeometry cache being disabled
306 1695153 void bindElement(const Element& element) &
307 {
308
2/2
✓ Branch 0 taken 623 times.
✓ Branch 1 taken 1449 times.
1695153 element_ = element;
309 3390306 eIdx_ = gridGeometry().elementMapper().index(element);
310 1695153 makeElementGeometries_();
311 1695153 }
312
313 //! The global finite volume geometry we are a restriction of
314 const GridGeometry& gridGeometry() const
315 { return *gridGeometryPtr_; }
316
317 //! Returns true if bind/bindElement has already been called
318 bool isBound() const
319 { return static_cast<bool>(element_); }
320
321 //! The bound element
322 const Element& element() const
323 4114912 { return *element_; }
324
325 //! Create the geometry of a given sub control volume
326 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
327 {
328 assert(isBound());
329 const auto geo = element().geometry();
330 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
331 }
332
333 //! Create the geometry of a given sub control volume face
334 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
335 {
336 assert(isBound());
337 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
338 GeometryHelper geometryHelper(element().geometry());
339
340 if (scvf.boundary() || scvf.interiorBoundary())
341 return {
342 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
343 geometryHelper.getBoundaryScvfCorners(
344 scvf.facetIndexInElement(),
345 scvf.indexInElementFacet()
346 )
347 };
348
349 return {
350 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
351 geometryHelper.getScvfCorners(scvf.index())
352 };
353 }
354
355 private:
356
357 1695153 void makeElementGeometries_()
358 {
359 // get the element geometry
360 1695153 const auto& element = *element_;
361 1695153 const auto elementGeometry = element.geometry();
362
1/2
✓ Branch 1 taken 1671794 times.
✗ Branch 2 not taken.
1695153 const auto refElement = referenceElement(elementGeometry);
363
364 // get the sub control volume geometries of this element
365
2/2
✓ Branch 0 taken 157046 times.
✓ Branch 1 taken 1516820 times.
1695153 GeometryHelper geometryHelper(elementGeometry);
366
367 // construct the sub control volumes
368
2/2
✓ Branch 0 taken 157046 times.
✓ Branch 1 taken 1516820 times.
1695153 scvs_.clear();
369
2/4
✓ Branch 1 taken 1671794 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1671794 times.
✗ Branch 5 not taken.
3390306 scvs_.reserve(elementGeometry.corners());
370 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
371
4/4
✓ Branch 0 taken 5395663 times.
✓ Branch 1 taken 1673866 times.
✓ Branch 2 taken 5395663 times.
✓ Branch 3 taken 1673866 times.
12652631 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
372
1/2
✓ Branch 1 taken 5389447 times.
✗ Branch 2 not taken.
5478739 scvs_.emplace_back(geometryHelper.getScvCorners(scvLocalIdx),
373 scvLocalIdx,
374
1/2
✓ Branch 1 taken 5389447 times.
✗ Branch 2 not taken.
5478739 eIdx_,
375
2/4
✓ Branch 1 taken 5389447 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5389447 times.
✗ Branch 5 not taken.
10957478 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
376
377 // construct the sub control volume faces
378
1/2
✓ Branch 1 taken 1671794 times.
✗ Branch 2 not taken.
1695153 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
379 1695153 scvfs_.clear();
380
1/2
✓ Branch 1 taken 1671794 times.
✗ Branch 2 not taken.
1695153 scvfs_.reserve(numInnerScvf);
381
382 1695153 unsigned int scvfLocalIdx = 0;
383
2/2
✓ Branch 0 taken 5434093 times.
✓ Branch 1 taken 1673866 times.
7250752 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
384 {
385 // find the local scv indices this scvf is connected to
386
2/6
✓ Branch 3 taken 5434093 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5434093 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
16666797 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
387
1/2
✓ Branch 2 taken 5427877 times.
✗ Branch 3 not taken.
5555599 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
388
389 // create the sub-control volume face
390 11111198 scvfs_.emplace_back(geometryHelper,
391 element,
392 elementGeometry,
393 scvfLocalIdx,
394
1/2
✓ Branch 1 taken 5434093 times.
✗ Branch 2 not taken.
5555599 std::move(localScvIndices));
395 }
396
397 // construct the sub control volume faces on the domain/interior boundaries
398 // skip handled facets (necessary for e.g. Dune::FoamGrid)
399
1/5
✓ Branch 1 taken 1673866 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3386162 std::vector<unsigned int> handledFacets;
400
7/17
✓ Branch 1 taken 1673866 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1673866 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 7070649 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 13 taken 5391519 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 5396783 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 7336 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1671794 times.
✗ Branch 22 not taken.
17750858 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
401 {
402
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5396783 times.
✓ Branch 2 taken 1120 times.
✓ Branch 3 taken 6216 times.
✓ Branch 4 taken 5389447 times.
10961958 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
403 2240 continue;
404
405
2/4
✓ Branch 1 taken 5395663 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5395663 times.
✗ Branch 5 not taken.
5491171 handledFacets.push_back(intersection.indexInInside());
406
407 // determine if all corners live on the facet grid
408
1/2
✓ Branch 1 taken 5395663 times.
✗ Branch 2 not taken.
10945046 const auto isGeometry = intersection.geometry();
409
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 5395663 times.
✗ Branch 2 not taken.
5478739 const auto numFaceCorners = isGeometry.corners();
410
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 5395663 times.
✗ Branch 2 not taken.
5478739 const auto idxInInside = intersection.indexInInside();
411
1/2
✓ Branch 1 taken 6216 times.
✗ Branch 2 not taken.
5478739 const auto boundary = intersection.boundary();
412
413
3/6
✓ Branch 1 taken 5395663 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5395663 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5395663 times.
✗ Branch 7 not taken.
21914956 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
414
2/2
✓ Branch 0 taken 10868186 times.
✓ Branch 1 taken 5395663 times.
16589937 for (int i = 0; i < numFaceCorners; ++i)
415 11111198 vIndicesLocal[i] = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, i, dim));
416
417 // if all vertices are living on the facet grid, this is an interiour boundary
418
1/2
✓ Branch 1 taken 5395663 times.
✗ Branch 2 not taken.
5478739 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
419
420
4/4
✓ Branch 0 taken 4994493 times.
✓ Branch 1 taken 401170 times.
✓ Branch 2 taken 85227 times.
✓ Branch 3 taken 4909266 times.
5478739 if (isOnFacet || boundary)
421 {
422
4/4
✓ Branch 0 taken 983234 times.
✓ Branch 1 taken 486397 times.
✓ Branch 2 taken 983234 times.
✓ Branch 3 taken 486397 times.
2532105 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
423 {
424 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
425
3/10
✓ Branch 1 taken 983234 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 983234 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 983234 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
4068072 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
426
427 // create the sub-control volume face
428 2034036 scvfs_.emplace_back(geometryHelper,
429 intersection,
430 isGeometry,
431 isScvfLocalIdx,
432 scvfLocalIdx,
433
1/2
✓ Branch 1 taken 983234 times.
✗ Branch 2 not taken.
1017018 std::move(localScvIndices),
434 boundary,
435 isOnFacet);
436
437 // increment local counter
438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 983234 times.
1017018 scvfLocalIdx++;
439 }
440 }
441 }
442 1695153 }
443
444 //! The global geometry this is a restriction of
445 const GridGeometry* gridGeometryPtr_;
446
447 //! The bound element
448 GridIndexType eIdx_;
449 std::optional<Element> element_;
450
451 //! vectors to store the geometries locally after binding an element
452 std::vector<SubControlVolume> scvs_;
453 std::vector<SubControlVolumeFace> scvfs_;
454 };
455
456 } // end namespace Dumux
457
458 #endif
459