GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/cellcentered/tpfa/fvelementgeometry.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 250 251 99.6%
Functions: 202 240 84.2%
Branches: 623 917 67.9%

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 CCTpfaDiscretization
10 * \brief Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models
11 * This builds up the sub control volumes and sub control volume faces
12 * for each element in the local scope we are restricting to, e.g. stencil or element.
13 */
14 #ifndef DUMUX_DISCRETIZATION_CCTPFA_FV_ELEMENT_GEOMETRY_HH
15 #define DUMUX_DISCRETIZATION_CCTPFA_FV_ELEMENT_GEOMETRY_HH
16
17 #include <optional>
18 #include <algorithm>
19 #include <array>
20 #include <vector>
21 #include <utility>
22
23 #include <dune/common/exceptions.hh>
24 #include <dumux/common/indextraits.hh>
25 #include <dune/common/iteratorrange.hh>
26 #include <dumux/discretization/scvandscvfiterators.hh>
27
28 namespace Dumux {
29
30 namespace Detail::Tpfa {
31
32 template<class GridIndexType>
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 762824989 times.
762824989 auto findLocalIndex(const GridIndexType idx,
34 const std::vector<GridIndexType>& indices)
35 {
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 762824989 times.
762824989 auto it = std::find(indices.begin(), indices.end(), idx);
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 762824989 times.
762824989 assert(it != indices.end() && "Could not find the scv/scvf! Make sure to properly bind this class!");
38 762824989 return std::distance(indices.begin(), it);
39 }
40
41 } // end namespace Detail::Tpfa
42
43 /*!
44 * \ingroup CCTpfaDiscretization
45 * \brief Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models
46 * This builds up the sub control volumes and sub control volume faces
47 * for each element in the local scope we are restricting to, e.g. stencil or element.
48 * \tparam GG the finite volume grid geometry type
49 * \tparam enableGridGeometryCache if the grid geometry is cached or not
50 * \note This class is specialized for versions with and without caching the fv geometries on the grid view
51 */
52 template<class GG, bool enableGridGeometryCache>
53 class CCTpfaFVElementGeometry;
54
55 /*!
56 * \ingroup CCTpfaDiscretization
57 * \brief Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models
58 * Specialization for grid caching enabled
59 * \note The finite volume geometries are stored in the corresponding GridGeometry
60 */
61 template<class GG>
62
26/52
✓ Branch 0 taken 14322 times.
✓ Branch 1 taken 19700959 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14224 times.
✓ Branch 4 taken 21193998 times.
✓ Branch 5 taken 6600 times.
✓ Branch 6 taken 3118317 times.
✓ Branch 7 taken 3470 times.
✓ Branch 8 taken 37917 times.
✓ Branch 9 taken 413040 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 386400 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 482051 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 482048 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 6 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
✓ Branch 25 taken 480 times.
✓ Branch 27 taken 3 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 1212652 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 1768 times.
✗ Branch 33 not taken.
✓ Branch 35 taken 1768 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 1768 times.
✓ Branch 38 taken 3 times.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✓ Branch 44 taken 5304 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 5304 times.
✗ Branch 47 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 26 not taken.
✓ Branch 31 taken 1212652 times.
✗ Branch 34 not taken.
✗ Branch 39 not taken.
52937636 class CCTpfaFVElementGeometry<GG, true>
63 {
64 using ThisType = CCTpfaFVElementGeometry<GG, true>;
65 using GridView = typename GG::GridView;
66 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
67 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
68
69 public:
70 //! export type of the element
71 using Element = typename GridView::template Codim<0>::Entity;
72 //! export type of subcontrol volume
73 using SubControlVolume = typename GG::SubControlVolume;
74 //! export type of subcontrol volume face
75 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
76 //! export type of finite volume grid geometry
77 using GridGeometry = GG;
78
79 //! the maximum number of scvs per element
80 static constexpr std::size_t maxNumElementScvs = 1;
81 //! the maximum number of scvfs per element (use cubes for maximum)
82 static constexpr std::size_t maxNumElementScvfs = 2*GridView::dimension;
83
84 //! Constructor
85 98297388 CCTpfaFVElementGeometry(const GridGeometry& gridGeometry)
86
32/40
✓ Branch 1 taken 2022 times.
✓ Branch 2 taken 180103 times.
✓ Branch 4 taken 973119 times.
✓ Branch 5 taken 14238659 times.
✓ Branch 7 taken 3967132 times.
✓ Branch 8 taken 395019 times.
✓ Branch 10 taken 20063055 times.
✓ Branch 11 taken 307 times.
✓ Branch 14 taken 909536 times.
✓ Branch 15 taken 3471 times.
✓ Branch 17 taken 36 times.
✓ Branch 18 taken 1747 times.
✓ Branch 20 taken 34 times.
✓ Branch 21 taken 1736 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 5304 times.
✓ Branch 27 taken 520 times.
✓ Branch 28 taken 79 times.
✓ Branch 30 taken 1087 times.
✓ Branch 31 taken 79 times.
✓ Branch 3 taken 1233769 times.
✓ Branch 9 taken 282253 times.
✓ Branch 12 taken 800003 times.
✓ Branch 13 taken 895103 times.
✓ Branch 16 taken 505 times.
✓ Branch 19 taken 1212672 times.
✓ Branch 22 taken 1771 times.
✓ Branch 6 taken 2597613 times.
✓ Branch 23 taken 29 times.
✓ Branch 26 taken 24 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 38 taken 63 times.
✗ Branch 39 not taken.
✓ Branch 33 taken 669 times.
✗ Branch 34 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 29 not taken.
✗ Branch 32 not taken.
98297388 : gridGeometryPtr_(&gridGeometry) {}
87
88 //! Get an element sub control volume with a global scv index
89 //! We separate element and neighbor scvs to speed up mapping
90 3567878992 const SubControlVolume& scv(GridIndexType scvIdx) const
91 {
92
13/17
✓ Branch 3 taken 56387765 times.
✓ Branch 4 taken 476211 times.
✓ Branch 6 taken 487102 times.
✓ Branch 7 taken 34000 times.
✓ Branch 1 taken 277452054 times.
✓ Branch 2 taken 111592 times.
✓ Branch 5 taken 528463 times.
✓ Branch 8 taken 830262 times.
✗ Branch 0 not taken.
✓ Branch 11 taken 3575610 times.
✗ Branch 12 not taken.
✓ Branch 9 taken 12320 times.
✓ Branch 13 taken 20401 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 909500 times.
✗ Branch 17 not taken.
✓ Branch 10 taken 31938 times.
1062304335 return gridGeometry().scv(scvIdx);
93 }
94
95 //! Get an element sub control volume face with a global scvf index
96 //! We separate element and neighbor scvfs to speed up mapping
97 1297750834 const SubControlVolumeFace& scvf(GridIndexType scvfIdx) const
98 {
99
20/20
✓ Branch 0 taken 3748362 times.
✓ Branch 1 taken 219408852 times.
✓ Branch 3 taken 1196432 times.
✓ Branch 4 taken 26166443 times.
✓ Branch 6 taken 10506255 times.
✓ Branch 7 taken 1082827 times.
✓ Branch 8 taken 1500586 times.
✓ Branch 9 taken 546612 times.
✓ Branch 10 taken 345646 times.
✓ Branch 11 taken 24428 times.
✓ Branch 12 taken 333642 times.
✓ Branch 13 taken 315221 times.
✓ Branch 14 taken 120369 times.
✓ Branch 15 taken 288712 times.
✓ Branch 5 taken 6206847 times.
✓ Branch 2 taken 894664 times.
✓ Branch 16 taken 35204 times.
✓ Branch 17 taken 144812 times.
✓ Branch 18 taken 5562 times.
✓ Branch 19 taken 70 times.
357990050 return gridGeometry().scvf(scvfIdx);
100 }
101
102 //! Get the scvf on the same face but from the other side
103 //! Note that e.g. the normals might be different in the case of surface grids
104 50568433 const SubControlVolumeFace& flipScvf(GridIndexType scvfIdx, unsigned int outsideScvIdx = 0) const
105 {
106
5/7
✓ Branch 2 taken 176032 times.
✓ Branch 3 taken 34979 times.
✓ Branch 4 taken 3050 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3050 times.
✗ Branch 7 not taken.
✓ Branch 1 taken 16322 times.
38981328 return gridGeometry().flipScvf(scvfIdx, outsideScvIdx);
107 }
108
109 //! iterator range for sub control volumes. Iterates over
110 //! all scvs of the bound element (not including neighbor scvs)
111 //! This is a free function found by means of ADL
112 //! To iterate over all sub control volumes of this FVElementGeometry use
113 //! for (auto&& scv : scvs(fvGeometry))
114 friend inline Dune::IteratorRange< ScvIterator<SubControlVolume, std::array<GridIndexType, 1>, ThisType> >
115 552229311 scvs(const CCTpfaFVElementGeometry& fvGeometry)
116 {
117 using ScvIterator = Dumux::ScvIterator<SubControlVolume, std::array<GridIndexType, 1>, ThisType>;
118
5/6
✓ Branch 1 taken 144919782 times.
✓ Branch 2 taken 17688390 times.
✓ Branch 5 taken 6600 times.
✗ Branch 6 not taken.
✓ Branch 0 taken 57355904 times.
✓ Branch 3 taken 48356 times.
552229335 return Dune::IteratorRange<ScvIterator>(ScvIterator(fvGeometry.scvIndices_.begin(), fvGeometry),
119
8/9
✓ Branch 0 taken 2293211 times.
✓ Branch 1 taken 2293211 times.
✓ Branch 2 taken 58259444 times.
✓ Branch 3 taken 145823322 times.
✓ Branch 4 taken 17870933 times.
✓ Branch 5 taken 230899 times.
✓ Branch 6 taken 1768 times.
✓ Branch 7 taken 8368 times.
✗ Branch 8 not taken.
558639230 ScvIterator(fvGeometry.scvIndices_.end(), fvGeometry));
120 }
121
122 //! iterator range for sub control volumes faces. Iterates over
123 //! all scvfs of the bound element (not including neighbor scvfs)
124 //! This is a free function found by means of ADL
125 //! To iterate over all sub control volume faces of this FVElementGeometry use
126 //! for (auto&& scvf : scvfs(fvGeometry))
127 friend inline Dune::IteratorRange< ScvfIterator<SubControlVolumeFace, std::vector<GridIndexType>, ThisType> >
128 234463401 scvfs(const CCTpfaFVElementGeometry& fvGeometry)
129 {
130 234463401 const auto& g = fvGeometry.gridGeometry();
131 19396619 const auto scvIdx = fvGeometry.scvIndices_[0];
132 using ScvfIterator = Dumux::ScvfIterator<SubControlVolumeFace, std::vector<GridIndexType>, ThisType>;
133
1/2
✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
232351424 return Dune::IteratorRange<ScvfIterator>(ScvfIterator(g.scvfIndicesOfScv(scvIdx).begin(), fvGeometry),
134
1/2
✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
232351424 ScvfIterator(g.scvfIndicesOfScv(scvIdx).end(), fvGeometry));
135 }
136
137 //! number of sub control volumes in this fv element geometry
138 std::size_t numScv() const
139 {
140
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
204068783 return scvIndices_.size();
141 }
142
143 //! number of sub control volumes in this fv element geometry
144 26099430 std::size_t numScvf() const
145 {
146
1/2
✓ Branch 1 taken 165000 times.
✗ Branch 2 not taken.
15051728 return gridGeometry().scvfIndicesOfScv(scvIndices_[0]).size();
147 }
148
149 /*!
150 * \brief bind the local view (r-value overload)
151 * This overload is called when an instance of this class is a temporary in the usage context
152 * This allows a usage like this: `const auto view = localView(...).bind(element);`
153 */
154 7261502 CCTpfaFVElementGeometry bind(const Element& element) &&
155 {
156
3/6
✓ Branch 1 taken 5874092 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1363672 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 23642 times.
✗ Branch 8 not taken.
7261502 this->bindElement(element);
157
4/7
✓ Branch 1 taken 5869250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1254313 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 23642 times.
✗ Branch 8 not taken.
✓ Branch 0 taken 96 times.
7261502 return std::move(*this);
158 }
159
160 50850920 void bind(const Element& element) &
161 {
162
5/11
✓ Branch 1 taken 161053 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7000 times.
✓ Branch 11 taken 1735 times.
✗ Branch 12 not taken.
✓ Branch 4 taken 259 times.
✓ Branch 7 taken 943 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 8 not taken.
50850920 this->bindElement(element);
163 169255 }
164
165 /*!
166 * \brief bind the local view (r-value overload)
167 * This overload is called when an instance of this class is a temporary in the usage context
168 * This allows a usage like this: `const auto view = localView(...).bindElement(element);`
169 */
170 40272082 CCTpfaFVElementGeometry bindElement(const Element& element) &&
171 {
172
6/9
✓ Branch 1 taken 15016568 times.
✓ Branch 2 taken 559872 times.
✓ Branch 4 taken 22786735 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1539322 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 17380 times.
✗ Branch 11 not taken.
✓ Branch 6 taken 2 times.
40272082 this->bindElement(element);
173
3/4
✓ Branch 0 taken 42228 times.
✓ Branch 1 taken 559872 times.
✓ Branch 2 taken 6600 times.
✗ Branch 3 not taken.
40272082 return std::move(*this);
174 }
175
176 //! Bind only element-local
177 172473887 void bindElement(const Element& element) &
178 {
179
16/24
✓ Branch 0 taken 15843924 times.
✓ Branch 1 taken 92119282 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 175134 times.
✓ Branch 7 taken 101 times.
✓ Branch 8 taken 1734 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1734 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 173500 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 3470 times.
✓ Branch 17 taken 1735 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1623797 times.
✓ Branch 20 taken 2408203 times.
✓ Branch 22 taken 1735 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 1734 times.
✓ Branch 25 taken 1 times.
172473887 element_ = element;
180
2/4
✓ Branch 1 taken 1735 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1735 times.
✗ Branch 5 not taken.
335815014 scvIndices_[0] = gridGeometry().elementMapper().index(*element_);
181 171760802 }
182
183 //! Returns true if bind/bindElement has already been called
184 12 bool isBound() const
185
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 { return static_cast<bool>(element_); }
186
187 //! The bound element
188 7481006 const Element& element() const
189
2/3
✓ Branch 2 taken 139982 times.
✗ Branch 3 not taken.
✓ Branch 1 taken 540 times.
8492770 { return *element_; }
190
191 //! The global finite volume geometry we are a restriction of
192 5563463760 const GridGeometry& gridGeometry() const
193
61/67
✓ Branch 1 taken 165600 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 231703040 times.
✓ Branch 5 taken 924160 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 100885850 times.
✓ Branch 13 taken 184638410 times.
✓ Branch 14 taken 20397210 times.
✓ Branch 17 taken 74428449 times.
✓ Branch 18 taken 75930049 times.
✓ Branch 21 taken 44829867 times.
✓ Branch 22 taken 7362370 times.
✓ Branch 28 taken 2053906 times.
✓ Branch 29 taken 1716190 times.
✓ Branch 38 taken 1160560 times.
✓ Branch 39 taken 3062449 times.
✓ Branch 40 taken 1370533 times.
✓ Branch 41 taken 909256 times.
✓ Branch 48 taken 247212 times.
✓ Branch 49 taken 270052 times.
✓ Branch 69 taken 504 times.
✓ Branch 70 taken 504 times.
✓ Branch 72 taken 504 times.
✗ Branch 73 not taken.
✓ Branch 76 taken 1735 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 3344 times.
✓ Branch 79 taken 126 times.
✓ Branch 0 taken 2400 times.
✓ Branch 19 taken 87017405 times.
✓ Branch 23 taken 7768318 times.
✓ Branch 25 taken 6973848 times.
✓ Branch 26 taken 14493438 times.
✓ Branch 7 taken 66701126 times.
✓ Branch 11 taken 27426486 times.
✓ Branch 12 taken 290105332 times.
✓ Branch 15 taken 171206573 times.
✓ Branch 30 taken 9801508 times.
✓ Branch 31 taken 1981620 times.
✓ Branch 32 taken 1645070 times.
✓ Branch 34 taken 1477220 times.
✓ Branch 35 taken 1328334 times.
✓ Branch 36 taken 2038367 times.
✓ Branch 37 taken 3457003 times.
✓ Branch 42 taken 1817068 times.
✓ Branch 44 taken 399904 times.
✓ Branch 45 taken 340708 times.
✓ Branch 3 taken 3668212 times.
✓ Branch 6 taken 58594774 times.
✓ Branch 16 taken 39379854 times.
✓ Branch 10 taken 32968088 times.
✓ Branch 27 taken 13317072 times.
✓ Branch 33 taken 2775576 times.
✓ Branch 43 taken 321840 times.
✓ Branch 46 taken 306712 times.
✓ Branch 47 taken 453032 times.
✓ Branch 50 taken 159916 times.
✓ Branch 51 taken 35928 times.
✓ Branch 53 taken 37708 times.
✗ Branch 54 not taken.
✓ Branch 20 taken 82037065 times.
✓ Branch 52 taken 38500 times.
✓ Branch 55 taken 91040 times.
✓ Branch 56 taken 20640 times.
✓ Branch 24 taken 34059 times.
✓ Branch 58 taken 20640 times.
✗ Branch 59 not taken.
5804428041 { return *gridGeometryPtr_; }
194
195 //! Returns whether one of the geometry's scvfs lies on a boundary
196 59113042 bool hasBoundaryScvf() const
197
12/12
✓ Branch 0 taken 2930721 times.
✓ Branch 1 taken 32684318 times.
✓ Branch 2 taken 6258328 times.
✓ Branch 3 taken 17214483 times.
✓ Branch 4 taken 7282 times.
✓ Branch 5 taken 8240 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.
59113042 { return gridGeometry().hasBoundaryScvf(scvIndices_[0]); }
198
199 325 typename Element::Geometry geometry(const SubControlVolume& scv) const
200
2/4
✓ Branch 1 taken 325 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 325 times.
✗ Branch 5 not taken.
650 { return gridGeometryPtr_->element(scv.dofIndex()).geometry(); }
201
202 120540 typename GridView::Intersection::Geometry geometry(const SubControlVolumeFace& scvf) const
203 {
204 120540 const auto element = gridGeometryPtr_->element(scvf.insideScvIdx());
205 120540 const auto& scvfIndices = gridGeometryPtr_->scvfIndicesOfScv(scvf.insideScvIdx());
206 120540 const LocalIndexType localScvfIdx = Detail::Tpfa::findLocalIndex(scvf.index(), scvfIndices);
207 120540 LocalIndexType localIdx = 0;
208
6/12
✓ Branch 1 taken 3724 times.
✓ Branch 2 taken 610887 times.
✓ Branch 5 taken 550303 times.
✓ Branch 6 taken 60584 times.
✓ Branch 7 taken 4136 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 7860 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
668623 for (const auto& intersection : intersections(gridGeometryPtr_->gridView(), element))
209 {
210
3/4
✓ Branch 0 taken 124714 times.
✓ Branch 1 taken 4164 times.
✓ Branch 2 taken 3696 times.
✗ Branch 3 not taken.
145374 if (intersection.neighbor() || intersection.boundary())
211 {
212
2/2
✓ Branch 0 taken 115592 times.
✓ Branch 1 taken 503155 times.
630399 if (localIdx == localScvfIdx)
213 120540 return intersection.geometry();
214 else
215 509859 ++localIdx;
216 }
217 }
218
219
0/29
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 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 6 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 30 not taken.
7344 DUNE_THROW(Dune::InvalidStateException, "Could not find scvf geometry");
220 7344 }
221
222 private:
223
224 std::optional<Element> element_;
225 std::array<GridIndexType, 1> scvIndices_;
226 const GridGeometry* gridGeometryPtr_;
227 };
228
229 /*!
230 * \ingroup CCTpfaDiscretization
231 * \brief Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models
232 * Specialization for grid caching disabled
233 */
234 template<class GG>
235 class CCTpfaFVElementGeometry<GG, false>
236 {
237 using ThisType = CCTpfaFVElementGeometry<GG, false>;
238 using GridView = typename GG::GridView;
239 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
240 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
241
242 static const int dim = GridView::dimension;
243 static const int dimWorld = GridView::dimensionworld;
244
245 public:
246 //! export type of the element
247 using Element = typename GridView::template Codim<0>::Entity;
248 //! export type of subcontrol volume
249 using SubControlVolume = typename GG::SubControlVolume;
250 //! export type of subcontrol volume face
251 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
252 //! export type of finite volume grid geometry
253 using GridGeometry = GG;
254 //! the maximum number of scvs per element
255 static constexpr std::size_t maxNumElementScvs = 1;
256 //! the maximum number of scvfs per element (use cubes for maximum)
257 static constexpr std::size_t maxNumElementScvfs = 2*dim;
258
259 //! Constructor
260 17393183 CCTpfaFVElementGeometry(const GridGeometry& gridGeometry)
261
24/33
✓ Branch 1 taken 1762 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 387704 times.
✓ Branch 5 taken 5084 times.
✓ Branch 7 taken 2010870 times.
✓ Branch 8 taken 15 times.
✓ Branch 10 taken 11796697 times.
✓ Branch 11 taken 264 times.
✓ Branch 13 taken 84352 times.
✓ Branch 14 taken 12 times.
✓ Branch 16 taken 40490 times.
✓ Branch 17 taken 12 times.
✓ Branch 19 taken 514541 times.
✓ Branch 20 taken 264 times.
✓ Branch 22 taken 50123 times.
✓ Branch 23 taken 5781 times.
✗ Branch 0 not taken.
✓ Branch 3 taken 50451 times.
✓ Branch 6 taken 11 times.
✓ Branch 9 taken 321 times.
✓ Branch 12 taken 384559 times.
✓ Branch 15 taken 312744 times.
✓ Branch 25 taken 52746 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1098436 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 134500 times.
✗ Branch 32 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
17393183 : gridGeometryPtr_(&gridGeometry) {}
262
263 //! Get an element sub control volume with a global scv index
264 //! We separate element and neighbor scvs to speed up mapping
265 1364691402 const SubControlVolume& scv(GridIndexType scvIdx) const
266 {
267
85/88
✓ Branch 0 taken 97532621 times.
✓ Branch 1 taken 77488199 times.
✓ Branch 2 taken 93398607 times.
✓ Branch 3 taken 96831023 times.
✓ Branch 4 taken 95791231 times.
✓ Branch 5 taken 95078007 times.
✓ Branch 6 taken 74328901 times.
✓ Branch 7 taken 70484920 times.
✓ Branch 8 taken 41143080 times.
✓ Branch 9 taken 69875077 times.
✓ Branch 10 taken 41346068 times.
✓ Branch 11 taken 47062422 times.
✓ Branch 12 taken 88206986 times.
✓ Branch 13 taken 60145712 times.
✓ Branch 14 taken 50379295 times.
✓ Branch 15 taken 71111922 times.
✓ Branch 16 taken 18936675 times.
✓ Branch 17 taken 34776939 times.
✓ Branch 18 taken 2991427 times.
✓ Branch 19 taken 29930120 times.
✓ Branch 20 taken 4340543 times.
✓ Branch 21 taken 785930 times.
✓ Branch 22 taken 1688989 times.
✓ Branch 23 taken 21670825 times.
✓ Branch 24 taken 17586480 times.
✓ Branch 25 taken 2115022 times.
✓ Branch 26 taken 11835760 times.
✓ Branch 27 taken 227834 times.
✓ Branch 28 taken 6237017 times.
✓ Branch 29 taken 4849644 times.
✓ Branch 30 taken 14410576 times.
✓ Branch 31 taken 6191376 times.
✓ Branch 32 taken 617783 times.
✓ Branch 33 taken 548572 times.
✓ Branch 34 taken 33482 times.
✓ Branch 35 taken 2724566 times.
✓ Branch 36 taken 692946 times.
✓ Branch 37 taken 614037 times.
✓ Branch 38 taken 277540 times.
✓ Branch 39 taken 16982 times.
✓ Branch 40 taken 231170 times.
✓ Branch 41 taken 630582 times.
✓ Branch 42 taken 143428 times.
✓ Branch 43 taken 653478 times.
✓ Branch 44 taken 47148 times.
✓ Branch 45 taken 537410 times.
✓ Branch 46 taken 1134866 times.
✓ Branch 47 taken 2044 times.
✓ Branch 48 taken 1055519 times.
✓ Branch 49 taken 5302 times.
✓ Branch 50 taken 49496 times.
✓ Branch 51 taken 3013580 times.
✓ Branch 52 taken 222110 times.
✓ Branch 53 taken 167594 times.
✓ Branch 54 taken 92486 times.
✓ Branch 55 taken 64712 times.
✓ Branch 56 taken 784 times.
✓ Branch 57 taken 211316 times.
✓ Branch 58 taken 89122 times.
✓ Branch 59 taken 2172 times.
✓ Branch 60 taken 113110 times.
✓ Branch 61 taken 4268 times.
✓ Branch 62 taken 6232 times.
✓ Branch 63 taken 329460 times.
✓ Branch 64 taken 83724 times.
✓ Branch 65 taken 5524 times.
✓ Branch 66 taken 90068 times.
✓ Branch 67 taken 4016 times.
✓ Branch 68 taken 965582 times.
✓ Branch 69 taken 154488 times.
✓ Branch 70 taken 129371 times.
✓ Branch 71 taken 33096 times.
✓ Branch 72 taken 6045 times.
✓ Branch 73 taken 1512 times.
✓ Branch 74 taken 2217 times.
✓ Branch 75 taken 23577 times.
✓ Branch 76 taken 39336 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 400 times.
✓ Branch 79 taken 528 times.
✓ Branch 80 taken 12 times.
✓ Branch 81 taken 864 times.
✓ Branch 82 taken 8376 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 5781 times.
✓ Branch 85 taken 24056 times.
✗ Branch 86 not taken.
✓ Branch 87 taken 304 times.
1348406896 if (scvIdx == scvIndices_[0])
268 649794484 return scvs_[0];
269 else
270 606466171 return neighborScvs_[Detail::Tpfa::findLocalIndex(scvIdx, neighborScvIndices_)];
271 }
272
273 //! Get an element sub control volume face with a global scvf index
274 //! We separate element and neighbor scvfs to speed up mapping
275 221002112 const SubControlVolumeFace& scvf(GridIndexType scvfIdx) const
276 {
277
2/2
✓ Branch 0 taken 54718540 times.
✓ Branch 1 taken 149614172 times.
221002112 auto it = std::find(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx);
278
2/2
✓ Branch 0 taken 54718540 times.
✓ Branch 1 taken 149614172 times.
221002112 if (it != scvfIndices_.end())
279 59088440 return scvfs_[std::distance(scvfIndices_.begin(), it)];
280 else
281 161913672 return neighborScvfs_[Detail::Tpfa::findLocalIndex(scvfIdx, neighborScvfIndices_)];
282 }
283
284 //! Get the scvf on the same face but from the other side
285 //! Note that e.g. the normals might be different in the case of surface grids
286 26096080 const SubControlVolumeFace& flipScvf(GridIndexType scvfIdx, unsigned int outsideScvIdx = 0) const
287 {
288
2/2
✓ Branch 0 taken 6788452 times.
✓ Branch 1 taken 6623410 times.
26096080 auto it = std::find(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx);
289
2/2
✓ Branch 0 taken 6788452 times.
✓ Branch 1 taken 6623410 times.
26096080 if (it != scvfIndices_.end())
290 {
291 13134413 const auto localScvfIdx = std::distance(scvfIndices_.begin(), it);
292 13134413 return neighborScvfs_[flippedScvfIndices_[localScvfIdx][outsideScvIdx]];
293 }
294 else
295 {
296 12961667 const auto localScvfIdx = Detail::Tpfa::findLocalIndex(scvfIdx, neighborScvfIndices_);
297
2/2
✓ Branch 0 taken 6611488 times.
✓ Branch 1 taken 11922 times.
12961667 const auto localFlippedIndex = flippedNeighborScvfIndices_[localScvfIdx][outsideScvIdx];
298
2/2
✓ Branch 0 taken 6611488 times.
✓ Branch 1 taken 11922 times.
12961667 if (localFlippedIndex < scvfs_.size())
299 12948413 return scvfs_[localFlippedIndex];
300 else
301 13254 return neighborScvfs_[localFlippedIndex - scvfs_.size()];
302 }
303 }
304
305 //! iterator range for sub control volumes. Iterates over
306 //! all scvs of the bound element (not including neighbor scvs)
307 //! This is a free function found by means of ADL
308 //! To iterate over all sub control volumes of this FVElementGeometry use
309 //! for (auto&& scv : scvs(fvGeometry))
310 friend inline Dune::IteratorRange<typename std::array<SubControlVolume, 1>::const_iterator>
311 63124726 scvs(const ThisType& g)
312 {
313 using IteratorType = typename std::array<SubControlVolume, 1>::const_iterator;
314
9/12
✓ Branch 1 taken 4368224 times.
✓ Branch 2 taken 5280 times.
✓ Branch 4 taken 5680 times.
✓ Branch 5 taken 48356 times.
✓ Branch 7 taken 1242 times.
✓ Branch 8 taken 3920 times.
✓ Branch 10 taken 10 times.
✗ Branch 11 not taken.
✓ Branch 0 taken 1959248 times.
✗ Branch 9 not taken.
✓ Branch 3 taken 6060 times.
✗ Branch 6 not taken.
63124726 return Dune::IteratorRange<IteratorType>(g.scvs_.begin(), g.scvs_.end());
315 }
316
317 //! iterator range for sub control volumes faces. Iterates over
318 //! all scvfs of the bound element (not including neighbor scvfs)
319 //! This is a free function found by means of ADL
320 //! To iterate over all sub control volume faces of this FVElementGeometry use
321 //! for (auto&& scvf : scvfs(fvGeometry))
322 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
323 57178122 scvfs(const ThisType& g)
324 {
325 using IteratorType = typename std::vector<SubControlVolumeFace>::const_iterator;
326
4/8
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10 times.
✗ Branch 11 not taken.
57178122 return Dune::IteratorRange<IteratorType>(g.scvfs_.begin(), g.scvfs_.end());
327 }
328
329 //! number of sub control volumes in this fv element geometry
330 std::size_t numScv() const
331
1/2
✓ Branch 1 taken 4285 times.
✗ Branch 2 not taken.
54926178 { return scvs_.size(); }
332
333 //! number of sub control volumes in this fv element geometry
334 16944428 std::size_t numScvf() const
335
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 660936 times.
✓ Branch 3 taken 660936 times.
✗ Branch 4 not taken.
✓ Branch 2 taken 2580 times.
✗ Branch 5 not taken.
16944428 { return scvfs_.size(); }
336
337 /*!
338 * \brief bind the local view (r-value overload)
339 * This overload is called when an instance of this class is a temporary in the usage context
340 * This allows a usage like this: `const auto view = localView(...).bind(element);`
341 */
342 55749 CCTpfaFVElementGeometry bind(const Element& element) &&
343 {
344
3/6
✓ Branch 1 taken 5637 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50012 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 100 times.
✗ Branch 8 not taken.
55749 this->bind_(element);
345 55749 return std::move(*this);
346 }
347
348 16255214 void bind(const Element& element) &
349 {
350
8/14
✓ Branch 1 taken 563461 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87740 times.
✓ Branch 5 taken 36914 times.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10 times.
✗ Branch 11 not taken.
✓ Branch 17 taken 100 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1928 times.
✗ Branch 21 not taken.
✗ Branch 6 not taken.
✓ Branch 9 taken 76900 times.
16255214 this->bind_(element);
351 767063 }
352
353 /*!
354 * \brief bind the local view (r-value overload)
355 * This overload is called when an instance of this class is a temporary in the usage context
356 * This allows a usage like this: `const auto view = localView(...).bindElement(element);`
357 */
358 1009311 CCTpfaFVElementGeometry bindElement(const Element& element) &&
359 {
360
4/8
✓ Branch 1 taken 392461 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 387680 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 225250 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 3920 times.
✗ Branch 11 not taken.
1009311 this->bindElement_(element);
361 1009311 return std::move(*this);
362 }
363
364 5917884 void bindElement(const Element& element) &
365 {
366
12/24
✓ Branch 1 taken 966481 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 446847 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 633194 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2459261 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 342480 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 392401 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 522446 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1502 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 52048 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 100528 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 320 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 376 times.
✗ Branch 35 not taken.
5917884 this->bindElement_(element);
367 5917884 }
368
369 //! Returns true if bind/bindElement has already been called
370 4 bool isBound() const
371
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
8 { return static_cast<bool>(element_); }
372
373 //! The bound element
374 1179580 const Element& element() const
375
1/2
✓ Branch 2 taken 3920 times.
✗ Branch 3 not taken.
1183500 { return *element_; }
376
377 //! The global finite volume geometry we are a restriction of
378 887253315 const GridGeometry& gridGeometry() const
379
10/15
✓ Branch 0 taken 160392 times.
✓ Branch 1 taken 149525328 times.
✓ Branch 2 taken 14759504 times.
✓ Branch 3 taken 131404616 times.
✓ Branch 4 taken 1563264 times.
✓ Branch 5 taken 5733192 times.
✓ Branch 6 taken 3453696 times.
✓ Branch 7 taken 10721256 times.
✗ Branch 8 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 123548 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 8622096 times.
481073279 { return *gridGeometryPtr_; }
380
381 //! Returns whether one of the geometry's scvfs lies on a boundary
382 16678876 bool hasBoundaryScvf() const
383
8/8
✓ Branch 0 taken 2412803 times.
✓ Branch 1 taken 12486155 times.
✓ Branch 2 taken 118190 times.
✓ Branch 3 taken 1647171 times.
✓ Branch 4 taken 2012 times.
✓ Branch 5 taken 4433 times.
✓ Branch 6 taken 280 times.
✓ Branch 7 taken 7832 times.
16678876 { return hasBoundaryScvf_; }
384
385 1680 typename Element::Geometry geometry(const SubControlVolume& scv) const
386 1680 { return gridGeometryPtr_->element(scv.dofIndex()).geometry(); }
387
388 6464 typename GridView::Intersection::Geometry geometry(const SubControlVolumeFace& scvf) const
389 {
390 6464 const auto element = gridGeometryPtr_->element(scvf.insideScvIdx());
391 6464 const auto& scvfIndices = gridGeometryPtr_->scvfIndicesOfScv(scvf.insideScvIdx());
392 6464 const LocalIndexType localScvfIdx = Detail::Tpfa::findLocalIndex(scvf.index(), scvfIndices);
393 6464 LocalIndexType localIdx = 0;
394
7/13
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 12620 times.
✓ Branch 7 taken 176 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 280 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 5 taken 10172 times.
✓ Branch 6 taken 2430 times.
✓ Branch 4 taken 18 times.
14384 for (const auto& intersection : intersections(gridGeometryPtr_->gridView(), element))
395 {
396
3/4
✓ Branch 0 taken 4886 times.
✓ Branch 1 taken 216 times.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
5208 if (intersection.neighbor() || intersection.boundary())
397 {
398
2/2
✓ Branch 0 taken 5644 times.
✓ Branch 1 taken 7256 times.
13720 if (localIdx == localScvfIdx)
399 6464 return intersection.geometry();
400 else
401 7256 ++localIdx;
402 }
403 }
404
405
0/29
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
✗ Branch 28 not taken.
104 DUNE_THROW(Dune::InvalidStateException, "Could not find scvf geometry");
406 104 }
407
408 private:
409 //! Binding of an element preparing the geometries of the whole stencil
410 //! called by the local jacobian to prepare element assembly
411 17713512 void bind_(const Element& element)
412 {
413 17713512 bindElement_(element);
414
415 22154039 neighborScvs_.reserve(element.subEntities(1));
416 22154039 neighborScvfIndices_.reserve(element.subEntities(1));
417 22154039 neighborScvfs_.reserve(element.subEntities(1));
418
419
1/2
✓ Branch 1 taken 16270563 times.
✗ Branch 2 not taken.
17713512 std::vector<GridIndexType> handledNeighbors;
420
1/2
✓ Branch 1 taken 16310963 times.
✗ Branch 2 not taken.
17713512 handledNeighbors.reserve(element.subEntities(1));
421
422
16/17
✓ Branch 1 taken 16280563 times.
✓ Branch 2 taken 35040984 times.
✓ Branch 7 taken 11478427 times.
✓ Branch 8 taken 373404 times.
✓ Branch 9 taken 15006780 times.
✓ Branch 10 taken 595214 times.
✓ Branch 11 taken 658664 times.
✓ Branch 12 taken 632862 times.
✓ Branch 4 taken 17110213 times.
✓ Branch 5 taken 1767064 times.
✓ Branch 3 taken 16449641 times.
✓ Branch 6 taken 287622 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 40000 times.
✓ Branch 15 taken 10000 times.
✓ Branch 17 taken 234962 times.
✓ Branch 18 taken 112366 times.
112658317 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
423 {
424 // for inner intersections and periodic (according to grid interface) intersections make neighbor geometry
425
4/6
✓ Branch 1 taken 922295 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 649328 times.
✗ Branch 5 not taken.
✓ Branch 0 taken 11683668 times.
✓ Branch 3 taken 39800 times.
84010731 if (intersection.neighbor())
426 {
427 48056062 const auto outside = intersection.outside();
428
3/5
✓ Branch 1 taken 43635170 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11892310 times.
✗ Branch 4 not taken.
✓ Branch 0 taken 12276 times.
48056062 const auto outsideIdx = gridGeometry().elementMapper().index(outside);
429
430 // make outside geometries only if not done yet (could happen on non-conforming grids)
431
1/2
✓ Branch 0 taken 43647446 times.
✗ Branch 1 not taken.
48056062 if ( std::find(handledNeighbors.begin(), handledNeighbors.end(), outsideIdx) == handledNeighbors.end() )
432 {
433
1/2
✓ Branch 1 taken 43647446 times.
✗ Branch 2 not taken.
48056062 makeNeighborGeometries(outside, outsideIdx);
434
1/2
✓ Branch 1 taken 43647446 times.
✗ Branch 2 not taken.
48056062 handledNeighbors.push_back(outsideIdx);
435 }
436 15326648 }
437 }
438
439 // build flip index set for network, surface, and periodic grids
440
2/2
✓ Branch 0 taken 40400 times.
✓ Branch 1 taken 16023996 times.
17280799 if (dim < dimWorld || gridGeometry().isPeriodic())
441 {
442
1/2
✓ Branch 1 taken 286967 times.
✗ Branch 2 not taken.
473113 flippedScvfIndices_.resize(scvfs_.size());
443
2/2
✓ Branch 0 taken 915380 times.
✓ Branch 1 taken 286967 times.
2021831 for (unsigned int localScvfIdx = 0; localScvfIdx < scvfs_.size(); ++localScvfIdx)
444 {
445
2/2
✓ Branch 0 taken 27764 times.
✓ Branch 1 taken 887616 times.
1548718 const auto& scvf = scvfs_[localScvfIdx];
446
2/2
✓ Branch 0 taken 27764 times.
✓ Branch 1 taken 887616 times.
1548718 if (scvf.boundary())
447 50078 continue;
448
449
1/2
✓ Branch 1 taken 887616 times.
✗ Branch 2 not taken.
1498640 flippedScvfIndices_[localScvfIdx].resize(scvf.numOutsideScvs());
450
2/2
✓ Branch 0 taken 912198 times.
✓ Branch 1 taken 887616 times.
3034078 for (unsigned int localOutsideScvIdx = 0; localOutsideScvIdx < scvf.numOutsideScvs(); ++localOutsideScvIdx)
451 {
452 1535438 const auto globalOutsideScvIdx = scvf.outsideScvIdx(localOutsideScvIdx);
453
1/2
✓ Branch 0 taken 2050064 times.
✗ Branch 1 not taken.
3485557 for (unsigned int localNeighborScvfIdx = 0; localNeighborScvfIdx < neighborScvfs_.size(); ++localNeighborScvfIdx)
454 {
455
2/2
✓ Branch 0 taken 912198 times.
✓ Branch 1 taken 1137866 times.
3485557 if (neighborScvfs_[localNeighborScvfIdx].insideScvIdx() == globalOutsideScvIdx)
456 {
457 1535438 flippedScvfIndices_[localScvfIdx][localOutsideScvIdx] = localNeighborScvfIdx;
458 1535438 break;
459 }
460 }
461 }
462 }
463
464
1/2
✓ Branch 1 taken 286967 times.
✗ Branch 2 not taken.
473113 flippedNeighborScvfIndices_.resize(neighborScvfs_.size());
465
2/2
✓ Branch 0 taken 912198 times.
✓ Branch 1 taken 286967 times.
2008551 for (unsigned int localScvfIdx = 0; localScvfIdx < neighborScvfs_.size(); ++localScvfIdx)
466 {
467
1/2
✓ Branch 1 taken 912198 times.
✗ Branch 2 not taken.
1535438 const auto& neighborScvf = neighborScvfs_[localScvfIdx];
468
1/2
✓ Branch 1 taken 912198 times.
✗ Branch 2 not taken.
1535438 flippedNeighborScvfIndices_[localScvfIdx].resize(neighborScvf.numOutsideScvs());
469
2/2
✓ Branch 0 taken 986214 times.
✓ Branch 1 taken 912198 times.
3181540 for (unsigned int localOutsideScvIdx = 0; localOutsideScvIdx < neighborScvf.numOutsideScvs(); ++localOutsideScvIdx)
470 {
471
1/2
✓ Branch 1 taken 986214 times.
✗ Branch 2 not taken.
1646102 flippedNeighborScvfIndices_[localScvfIdx][localOutsideScvIdx] = findFlippedScvfIndex_(neighborScvf.insideScvIdx(), neighborScvf.outsideScvIdx(localOutsideScvIdx));
472 }
473 }
474 }
475 17713512 }
476
477 //! Binding of an element preparing the geometries only inside the element
478 24962583 void bindElement_(const Element& element)
479 {
480 24962583 clear();
481
2/2
✓ Branch 0 taken 3696183 times.
✓ Branch 1 taken 14271596 times.
24962583 element_ = element;
482 31525445 scvfs_.reserve(element.subEntities(1));
483 31525445 scvfIndices_.reserve(element.subEntities(1));
484 24962583 makeElementGeometries(element);
485 24962583 }
486
487 1646102 GridIndexType findFlippedScvfIndex_(GridIndexType insideScvIdx, GridIndexType globalOutsideScvIdx)
488 {
489
2/2
✓ Branch 0 taken 3373096 times.
✓ Branch 1 taken 912198 times.
7247810 for (unsigned int localNeighborScvfIdx = 0; localNeighborScvfIdx < neighborScvfs_.size(); ++localNeighborScvfIdx)
490 {
491
2/2
✓ Branch 0 taken 74016 times.
✓ Branch 1 taken 3299080 times.
5712372 if (neighborScvfs_[localNeighborScvfIdx].insideScvIdx() == globalOutsideScvIdx)
492 {
493 110664 return scvfs_.size() + localNeighborScvfIdx;
494 }
495 }
496
497 // go over all potential scvfs of the outside scv
498
1/2
✓ Branch 0 taken 2030409 times.
✗ Branch 1 not taken.
3468497 for (unsigned int localOutsideScvfIdx = 0; localOutsideScvfIdx < scvfs_.size(); ++localOutsideScvfIdx)
499 {
500 3468497 const auto& outsideScvf = scvfs_[localOutsideScvfIdx];
501
2/2
✓ Branch 0 taken 2079939 times.
✓ Branch 1 taken 1118211 times.
5475668 for (unsigned int j = 0; j < outsideScvf.numOutsideScvs(); ++j)
502 {
503
2/2
✓ Branch 0 taken 912198 times.
✓ Branch 1 taken 1167741 times.
3542609 if (outsideScvf.outsideScvIdx(j) == insideScvIdx)
504 {
505 1535438 return localOutsideScvfIdx;
506 }
507 }
508 }
509
510 DUNE_THROW(Dune::InvalidStateException, "No flipped version of this scvf found!");
511 }
512
513 //! create scvs and scvfs of the bound element
514 24962583 void makeElementGeometries(const Element& element)
515 {
516 using ScvfGridIndexStorage = typename SubControlVolumeFace::Traits::GridIndexStorage;
517
518 24962583 const auto eIdx = gridGeometry().elementMapper().index(element);
519
1/2
✓ Branch 1 taken 6025937 times.
✗ Branch 2 not taken.
24988105 scvs_[0] = SubControlVolume(element.geometry(), eIdx);
520 24962583 scvIndices_[0] = eIdx;
521
522
1/2
✓ Branch 1 taken 6552036 times.
✗ Branch 2 not taken.
24962583 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdx);
523
1/2
✓ Branch 1 taken 6552036 times.
✗ Branch 2 not taken.
24962583 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdx);
524
525 // for network grids there might be multiple intersection with the same geometryInInside
526 // we identify those by the indexInInside for now (assumes conforming grids at branching facets)
527 // here we keep track of them
528
1/2
✓ Branch 1 taken 1170561 times.
✗ Branch 2 not taken.
24962583 std::vector<bool> handledScvf;
529 if (dim < dimWorld)
530
1/2
✓ Branch 1 taken 1170561 times.
✗ Branch 2 not taken.
1554986 handledScvf.resize(element.subEntities(1), false);
531
532 24962583 int scvfCounter = 0;
533
14/16
✓ Branch 1 taken 23720558 times.
✓ Branch 2 taken 48506536 times.
✓ Branch 7 taken 18836149 times.
✓ Branch 8 taken 3302694 times.
✓ Branch 9 taken 25774941 times.
✓ Branch 10 taken 462260 times.
✓ Branch 11 taken 923084 times.
✓ Branch 12 taken 552163 times.
✓ Branch 4 taken 18710538 times.
✓ Branch 5 taken 181093 times.
✗ Branch 0 not taken.
✓ Branch 3 taken 160800 times.
✓ Branch 6 taken 2914168 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2288540 times.
✓ Branch 13 taken 40000 times.
198518765 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
534 {
535 if (dim < dimWorld)
536
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2914168 times.
✓ Branch 2 taken 258836 times.
✓ Branch 3 taken 2655332 times.
4050588 if (handledScvf[intersection.indexInInside()])
537 312196 continue;
538
539
2/2
✓ Branch 0 taken 46264474 times.
✓ Branch 1 taken 4321778 times.
76821826 const auto& scvfNeighborVolVarIndices = neighborVolVarIndices[scvfCounter];
540
5/5
✓ Branch 0 taken 4594590 times.
✓ Branch 1 taken 21968163 times.
✓ Branch 2 taken 394179 times.
✓ Branch 3 taken 141849 times.
✓ Branch 4 taken 392163 times.
35307491 if (intersection.neighbor() || intersection.boundary())
541 {
542
3/4
✓ Branch 0 taken 68770074 times.
✓ Branch 1 taken 71425406 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 68770074 times.
149892140 ScvfGridIndexStorage scvIndices;
543
1/3
✓ Branch 1 taken 71425406 times.
✗ Branch 2 not taken.
✗ Branch 0 not taken.
76815266 scvIndices.resize(scvfNeighborVolVarIndices.size() + 1);
544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68770074 times.
76815266 scvIndices[0] = eIdx;
545
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 68845010 times.
✓ Branch 2 taken 7836963 times.
✓ Branch 3 taken 43877633 times.
149892140 std::copy(scvfNeighborVolVarIndices.begin(), scvfNeighborVolVarIndices.end(), scvIndices.begin()+1);
546
547
4/4
✓ Branch 0 taken 4597390 times.
✓ Branch 1 taken 65226813 times.
✓ Branch 2 taken 3600 times.
✓ Branch 3 taken 393379 times.
76830465 const bool onBoundary = intersection.boundary() && !intersection.neighbor();
548
2/2
✓ Branch 0 taken 6462048 times.
✓ Branch 1 taken 64963358 times.
76815266 hasBoundaryScvf_ = (hasBoundaryScvf_ || onBoundary);
549
550
1/2
✓ Branch 1 taken 20326878 times.
✗ Branch 2 not taken.
110121034 scvfs_.emplace_back(intersection,
551
1/2
✓ Branch 1 taken 51098528 times.
✗ Branch 2 not taken.
51568376 intersection.geometry(),
552
1/2
✓ Branch 1 taken 39816710 times.
✗ Branch 2 not taken.
76815266 scvFaceIndices[scvfCounter],
553 scvIndices,
554 onBoundary);
555
1/2
✓ Branch 1 taken 71425406 times.
✗ Branch 2 not taken.
76815266 scvfIndices_.emplace_back(scvFaceIndices[scvfCounter]);
556
1/3
✓ Branch 1 taken 3864372 times.
✗ Branch 2 not taken.
✗ Branch 0 not taken.
76815266 scvfCounter++;
557
558 // for surface and network grids mark that we handled this face
559 if (dim < dimWorld)
560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2655332 times.
3738392 handledScvf[intersection.indexInInside()] = true;
561 3738392 }
562 }
563 24962583 }
564
565 //! create the necessary scvs and scvfs of the neighbor elements to the bound elements
566 48056062 void makeNeighborGeometries(const Element& element, const GridIndexType eIdx)
567 {
568 using ScvfGridIndexStorage = typename SubControlVolumeFace::Traits::GridIndexStorage;
569
570 // create the neighbor scv
571
1/2
✓ Branch 2 taken 11040428 times.
✗ Branch 3 not taken.
48056062 neighborScvs_.emplace_back(element.geometry(), eIdx);
572 48056062 neighborScvIndices_.push_back(eIdx);
573
574
1/2
✓ Branch 1 taken 12179996 times.
✗ Branch 2 not taken.
48056062 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdx);
575
1/2
✓ Branch 1 taken 12179996 times.
✗ Branch 2 not taken.
48056062 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdx);
576
577 // for network grids there might be multiple intersection with the same geometryInInside
578 // we identify those by the indexInInside for now (assumes conforming grids at branching facets)
579 // here we keep track of them
580
1/2
✓ Branch 1 taken 751806 times.
✗ Branch 2 not taken.
48056062 std::vector<bool> handledScvf;
581 if (dim < dimWorld)
582
1/2
✓ Branch 1 taken 751806 times.
✗ Branch 2 not taken.
1375046 handledScvf.resize(element.subEntities(1), false);
583
584 48056062 int scvfCounter = 0;
585
13/15
✓ Branch 1 taken 43526854 times.
✓ Branch 2 taken 93294740 times.
✓ Branch 4 taken 33610759 times.
✓ Branch 5 taken 56530235 times.
✓ Branch 7 taken 39877776 times.
✓ Branch 8 taken 843180 times.
✓ Branch 9 taken 55408468 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 2860390 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2626880 times.
✓ Branch 15 taken 656720 times.
✓ Branch 11 taken 3889728 times.
✓ Branch 6 taken 6415218 times.
✓ Branch 3 taken 482368 times.
399448682 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
586 {
587 if (dim < dimWorld)
588
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2610974 times.
✓ Branch 2 taken 98670 times.
✓ Branch 3 taken 2512304 times.
4915082 if (handledScvf[intersection.indexInInside()])
589 147606 continue;
590
591
2/2
✓ Branch 0 taken 42406834 times.
✓ Branch 1 taken 8147178 times.
64978228 if (intersection.neighbor())
592 {
593 // this catches inner and periodic scvfs
594
2/3
✓ Branch 1 taken 126682930 times.
✗ Branch 2 not taken.
✓ Branch 0 taken 479360 times.
144370334 const auto& scvfNeighborVolVarIndices = neighborVolVarIndices[scvfCounter];
595
4/5
✓ Branch 1 taken 129717588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39312200 times.
✓ Branch 4 taken 87370730 times.
✓ Branch 0 taken 479360 times.
144370334 if (scvfNeighborVolVarIndices[0] < gridGeometry().gridView().size(0))
596 {
597 // only create subcontrol faces where the outside element is the bound element
598 if (dim == dimWorld)
599 {
600
4/4
✓ Branch 1 taken 73208322 times.
✓ Branch 2 taken 54537380 times.
✓ Branch 3 taken 11388390 times.
✓ Branch 4 taken 30312682 times.
139720332 if (scvfNeighborVolVarIndices[0] == gridGeometry().elementMapper().index(*element_))
601 {
602 46681016 ScvfGridIndexStorage scvIndices({eIdx, scvfNeighborVolVarIndices[0]});
603
1/2
✓ Branch 1 taken 10931862 times.
✗ Branch 2 not taken.
62338992 neighborScvfs_.emplace_back(intersection,
604
1/2
✓ Branch 1 taken 31963778 times.
✗ Branch 2 not taken.
31966854 intersection.geometry(),
605 46681016 scvFaceIndices[scvfCounter],
606 scvIndices,
607
1/2
✓ Branch 1 taken 27080312 times.
✗ Branch 2 not taken.
46681016 false);
608
609
1/2
✓ Branch 1 taken 42895640 times.
✗ Branch 2 not taken.
46681016 neighborScvfIndices_.push_back(scvFaceIndices[scvfCounter]);
610 }
611 }
612 // for network grids we can't use the intersection.outside() index as we can't assure that the
613 // first intersection with this indexInInside is the one that has our bound element as outside
614 // instead we check if the bound element's index is in the outsideScvIndices of the candidate scvf
615 // (will be optimized away for dim == dimWorld)
616 else
617 {
618
2/2
✓ Branch 0 taken 2512872 times.
✓ Branch 1 taken 1699440 times.
8017160 for (unsigned outsideScvIdx = 0; outsideScvIdx < scvfNeighborVolVarIndices.size(); ++outsideScvIdx)
619 {
620
5/5
✓ Branch 1 taken 2212666 times.
✓ Branch 2 taken 287930 times.
✓ Branch 3 taken 503920 times.
✓ Branch 4 taken 1460140 times.
✓ Branch 0 taken 12276 times.
4742204 if (scvfNeighborVolVarIndices[outsideScvIdx] == gridGeometry().elementMapper().index(*element_))
621 {
622
1/2
✓ Branch 1 taken 751806 times.
✗ Branch 2 not taken.
1375046 ScvfGridIndexStorage scvIndices;
623
1/2
✓ Branch 1 taken 751806 times.
✗ Branch 2 not taken.
1375046 scvIndices.resize(scvfNeighborVolVarIndices.size() + 1);
624 1375046 scvIndices[0] = eIdx;
625 1375046 std::copy(scvfNeighborVolVarIndices.begin(), scvfNeighborVolVarIndices.end(), scvIndices.begin()+1);
626
1/2
✓ Branch 1 taken 503920 times.
✗ Branch 2 not taken.
1742252 neighborScvfs_.emplace_back(intersection,
627
1/2
✓ Branch 1 taken 247886 times.
✗ Branch 2 not taken.
367206 intersection.geometry(),
628 1375046 scvFaceIndices[scvfCounter],
629 scvIndices,
630
1/2
✓ Branch 1 taken 751806 times.
✗ Branch 2 not taken.
1375046 false);
631
632
1/2
✓ Branch 1 taken 751806 times.
✗ Branch 2 not taken.
1375046 neighborScvfIndices_.push_back(scvFaceIndices[scvfCounter]);
633 break;
634 1375046 }
635 }
636 }
637
638 // for surface and network grids mark that we handled this face
639 if (dim < dimWorld)
640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2451246 times.
4650002 handledScvf[intersection.indexInInside()] = true;
641 144370334 scvfCounter++;
642 }
643 }
644
645 // only increase counter for boundary intersections
646 // (exclude periodic boundaries according to dune grid interface, they have been handled in neighbor==true)
647
2/3
✓ Branch 0 taken 17282 times.
✓ Branch 1 taken 8910158 times.
✗ Branch 2 not taken.
9190034 else if (intersection.boundary())
648 {
649 if (dim < dimWorld)
650
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51620 times.
117474 handledScvf[intersection.indexInInside()] = true;
651 8405176 scvfCounter++;
652 }
653 }
654 48056062 }
655
656 //! Clear all local data
657 24962583 void clear()
658 {
659
2/2
✓ Branch 0 taken 5395776 times.
✓ Branch 1 taken 17842382 times.
24962583 scvfIndices_.clear();
660
2/2
✓ Branch 0 taken 5395776 times.
✓ Branch 1 taken 17842382 times.
24962583 scvfs_.clear();
661
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 23237960 times.
24962583 flippedScvfIndices_.clear();
662
663
2/2
✓ Branch 0 taken 797351 times.
✓ Branch 1 taken 22440807 times.
24962583 neighborScvIndices_.clear();
664
2/2
✓ Branch 0 taken 797351 times.
✓ Branch 1 taken 22440807 times.
24962583 neighborScvfIndices_.clear();
665
2/2
✓ Branch 0 taken 797351 times.
✓ Branch 1 taken 22440807 times.
24962583 neighborScvs_.clear();
666
2/2
✓ Branch 0 taken 797351 times.
✓ Branch 1 taken 22440807 times.
24962583 neighborScvfs_.clear();
667
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 23237960 times.
24962583 flippedNeighborScvfIndices_.clear();
668
669 24962583 hasBoundaryScvf_ = false;
670 24962583 }
671
672 std::optional<Element> element_; //!< the element to which this fvgeometry is bound
673 const GridGeometry* gridGeometryPtr_; //!< the grid fvgeometry
674
675 // local storage after binding an element
676 std::array<GridIndexType, 1> scvIndices_;
677 std::array<SubControlVolume, 1> scvs_;
678
679 std::vector<GridIndexType> scvfIndices_;
680 std::vector<SubControlVolumeFace> scvfs_;
681 std::vector<std::vector<GridIndexType>> flippedScvfIndices_;
682
683 std::vector<GridIndexType> neighborScvIndices_;
684 std::vector<SubControlVolume> neighborScvs_;
685
686 std::vector<GridIndexType> neighborScvfIndices_;
687 std::vector<SubControlVolumeFace> neighborScvfs_;
688 std::vector<std::vector<GridIndexType>> flippedNeighborScvfIndices_;
689
690 bool hasBoundaryScvf_ = false;
691 };
692
693 } // end namespace Dumux
694
695 #endif
696