GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/facecentered/diamond/fvelementgeometry.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 37 44 84.1%
Functions: 18 60 30.0%
Branches: 95 172 55.2%

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 DiamondDiscretization
10 * \copydoc Dumux::FaceCenteredDiamondFVElementGeometry
11 */
12 #ifndef DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_ELEMENT_GEOMETRY_HH
13 #define DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_ELEMENT_GEOMETRY_HH
14
15 #include <type_traits>
16 #include <optional>
17
18 #include <dune/common/reservedvector.hh>
19 #include <dune/common/iteratorrange.hh>
20
21 #include <dumux/common/indextraits.hh>
22 #include <dumux/discretization/scvandscvfiterators.hh>
23 #include <dumux/discretization/facecentered/diamond/geometryhelper.hh>
24
25 namespace Dumux {
26
27 /*!
28 * \ingroup DiamondDiscretization
29 * \brief Element-wise grid geometry (local view)
30 */
31 template<class GG, bool cachingEnabled>
32 class FaceCenteredDiamondFVElementGeometry;
33
34 /*!
35 * \ingroup DiamondDiscretization
36 * \brief Element-wise grid geometry (local view)
37 */
38 template<class GG>
39
12/35
✗ Branch 0 not taken.
✓ Branch 1 taken 63156 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 10278 times.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 10278 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 10278 times.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 30834 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 30834 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 30834 times.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 20 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
227698 class FaceCenteredDiamondFVElementGeometry<GG, /*cachingEnabled*/true>
40 {
41 using ThisType = FaceCenteredDiamondFVElementGeometry<GG, /*cachingEnabled*/true>;
42 using GridView = typename GG::GridView;
43 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
44 using LocalIndexType = typename IndexTraits<GridView>::SmallLocalIndex;
45 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
46 using GGCache = typename GG::Cache;
47 using GeometryHelper = typename GGCache::GeometryHelper;
48
49 public:
50 //! export type of subcontrol volume face
51 using SubControlVolume = typename GG::SubControlVolume;
52 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
53 using Element = typename GridView::template Codim<0>::Entity;
54 using GridGeometry = GG;
55
56 //! the maximum number of scvs per element
57 static constexpr std::size_t maxNumElementScvs = 2*GridView::dimension;
58
59 FaceCenteredDiamondFVElementGeometry(const GGCache& ggCache)
60
24/35
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 11 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 11 times.
✓ Branch 13 taken 42002 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 10278 times.
✓ Branch 16 taken 42002 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 10278 times.
✓ Branch 19 taken 603 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 30836 times.
✓ Branch 22 taken 603 times.
✓ Branch 23 taken 2 times.
✓ Branch 24 taken 30836 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 2 times.
✓ Branch 27 taken 22 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 22 times.
✗ Branch 31 not taken.
✓ Branch 39 taken 2 times.
✗ Branch 40 not taken.
✓ Branch 42 taken 2 times.
✗ Branch 43 not taken.
1451300 : ggCache_(&ggCache)
61 {}
62
63 //! Get a sub control volume with a local scv index
64 const SubControlVolume& scv(LocalIndexType scvIdx) const
65
9/12
✓ Branch 0 taken 5600 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5600 times.
✓ Branch 3 taken 36608 times.
✓ Branch 4 taken 80016 times.
✓ Branch 5 taken 36608 times.
✓ Branch 6 taken 80016 times.
✓ Branch 7 taken 36608 times.
✓ Branch 8 taken 80016 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5600 times.
✗ Branch 11 not taken.
94067250 { return ggCache_->scvs(eIdx_)[scvIdx]; }
66
67 //! Get a sub control volume face with a local scvf index
68 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
69 { return ggCache_->scvf(eIdx_)[scvfIdx]; }
70
71 //! iterator range for sub control volumes. Iterates over
72 //! all scvs of the bound element (not including neighbor scvs)
73 //! This is a free function found by means of ADL
74 //! To iterate over all sub control volumes of this FVElementGeometry use
75 //! for (auto&& scv : scvs(fvGeometry))
76 friend inline auto
77 scvs(const FaceCenteredDiamondFVElementGeometry& fvGeometry)
78 {
79 using Iter = typename std::vector<SubControlVolume>::const_iterator;
80 30902548 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
81 92707644 return Dune::IteratorRange<Iter>(s.begin(), s.end());
82 }
83
84 //! iterator range for sub control volumes faces. Iterates over
85 //! all scvfs of the bound element.
86 //! This is a free function found by means of ADL
87 //! To iterate over all sub control volume faces of this FVElementGeometry use
88 //! for (auto&& scvf : scvfs(fvGeometry))
89 friend inline auto
90 scvfs(const FaceCenteredDiamondFVElementGeometry& fvGeometry)
91 {
92 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
93 4072693 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
94 12218079 return Dune::IteratorRange<Iter>(s.begin(), s.end());
95 }
96
97 //! Get a local finite element basis
98 7961546 const FeLocalBasis& feLocalBasis() const
99 {
100 7961546 return gridGeometry().feCache().get(element().type()).localBasis();
101 }
102
103 //! number of sub control volumes in this fv element geometry
104 std::size_t numScv() const
105 {
106
8/12
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 155224 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 155224 times.
✓ Branch 5 taken 34914 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 34914 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 30834 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 30834 times.
✗ Branch 15 not taken.
14033234 return ggCache_->scvs(eIdx_).size();
107 }
108
109 //! number of sub control volumes in this fv element geometry
110 std::size_t numScvf() const
111 {
112
2/4
✓ Branch 1 taken 10278 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10278 times.
✗ Branch 5 not taken.
239930 return ggCache_->scvfs(eIdx_).size();
113 }
114
115 //! Returns whether one of the geometry's scvfs lies on a boundary
116 bool hasBoundaryScvf() const
117
4/8
✓ Branch 0 taken 682 times.
✓ Branch 1 taken 28267 times.
✓ Branch 2 taken 682 times.
✓ Branch 3 taken 28267 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
57898 { return ggCache_->hasBoundaryScvf(eIdx_); }
118
119 /*!
120 * \brief bind the local view (r-value overload)
121 * This overload is called when an instance of this class is a temporary in the usage context
122 * This allows a usage like this: `const auto view = localView(...).bind(element);`
123 */
124 FaceCenteredDiamondFVElementGeometry bind(const Element& element) &&
125 {
126
1/2
✓ Branch 1 taken 10278 times.
✗ Branch 2 not taken.
77365 this->bindElement(element);
127
1/2
✓ Branch 0 taken 67087 times.
✗ Branch 1 not taken.
144452 return std::move(*this);
128 }
129
130 void bind(const Element& element) &
131 {
132
2/7
✓ Branch 1 taken 55304 times.
✓ Branch 2 taken 31043 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
748261 this->bindElement(element);
133 }
134
135 /*!
136 * \brief bind the local view (r-value overload)
137 * This overload is called when an instance of this class is a temporary in the usage context
138 * This allows a usage like this: `const auto view = localView(...).bindElement(element);`
139 */
140 FaceCenteredDiamondFVElementGeometry bindElement(const Element& element) &&
141 {
142
2/3
✓ Branch 1 taken 30834 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
574289 this->bindElement(element);
143
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
1117744 return std::move(*this);
144 }
145
146 //! Bind only element-local
147 3375926 void bindElement(const Element& element) &
148 {
149
2/2
✓ Branch 0 taken 2132838 times.
✓ Branch 1 taken 1140308 times.
3375926 element_ = element;
150 3375926 eIdx_ = gridGeometry().elementMapper().index(element);
151 3375926 }
152
153 //! Returns true if bind/bindElement has already been called
154 bool isBound() const
155
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
322 { return static_cast<bool>(element_); }
156
157 //! The bound element
158 const Element& element() const
159
2/4
✓ Branch 3 taken 55304 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 55304 times.
✗ Branch 7 not taken.
62006434 { return *element_; }
160
161 //! The grid geometry we are a restriction of
162 const GridGeometry& gridGeometry() const
163
14/24
✓ Branch 1 taken 240 times.
✓ Branch 2 taken 17272 times.
✓ Branch 3 taken 384936 times.
✓ Branch 4 taken 6820 times.
✓ Branch 5 taken 861620 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 9 taken 55304 times.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 10278 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 10487 times.
✓ Branch 17 taken 20556 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 10487 times.
✗ Branch 20 not taken.
✓ Branch 26 taken 8208 times.
✓ Branch 27 taken 655440 times.
✓ Branch 40 taken 2 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 2 times.
✗ Branch 44 not taken.
15145388 { return ggCache_->gridGeometry(); }
164
165 //! The bound element index
166 std::size_t elementIndex() const
167 39435 { return eIdx_; }
168
169 //! Geometry of a sub control volume
170 6 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
171 {
172
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
12 assert(isBound());
173 12 const auto geo = element().geometry();
174 return {
175 SubControlVolume::Traits::geometryType(geo.type()),
176 GeometryHelper(geo).getScvCorners(scv.indexInElement())
177 18 };
178 }
179
180 //! Geometry of a sub control volume face
181 178 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
182 {
183
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 178 times.
356 assert(isBound());
184
2/4
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 160 times.
✗ Branch 3 not taken.
356 const auto geo = element().geometry();
185
2/2
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 12 times.
178 if (scvf.boundary())
186 {
187 // use the information that each boundary scvf corresponds to one scv constructed around the same facet
188 166 const auto localFacetIndex = scvf.insideScvIdx();
189 return {
190 166 referenceElement(geo).type(localFacetIndex, 1),
191 GeometryHelper(geo).getBoundaryScvfCorners(localFacetIndex)
192 166 };
193 }
194 else
195 {
196 return {
197 SubControlVolumeFace::Traits::interiorGeometryType(geo.type()),
198 GeometryHelper(geo).getScvfCorners(scvf.index())
199 24 };
200 }
201 }
202
203 private:
204 std::optional<Element> element_;
205 GridIndexType eIdx_;
206 const GGCache* ggCache_;
207 };
208
209 } // end namespace Dumux
210
211 #endif
212