GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/facecentered/diamond/fvelementgeometry.hh
Date: 2025-06-28 19:18:10
Exec Total Coverage
Lines: 59 59 100.0%
Functions: 22 22 100.0%
Branches: 86 146 58.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 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/32
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 42600 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 10278 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 10278 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 10278 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 30834 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 30834 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 30834 times.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 20 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
207146 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 1383258 FaceCenteredDiamondFVElementGeometry(const GGCache& ggCache)
60
15/19
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 42002 times.
✓ Branch 10 taken 606 times.
✓ Branch 11 taken 30838 times.
✓ Branch 13 taken 3 times.
✓ Branch 14 taken 20 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
✓ Branch 8 taken 10280 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
✓ Branch 21 taken 2 times.
✗ Branch 22 not taken.
846167 : ggCache_(&ggCache)
61 {}
62
63 //! Get a sub control volume with a local scv index
64 68730968 const SubControlVolume& scv(LocalIndexType scvIdx) const
65
6/7
✓ Branch 1 taken 36608 times.
✓ Branch 2 taken 74416 times.
✓ Branch 5 taken 292492 times.
✗ Branch 6 not taken.
✓ Branch 3 taken 1007594 times.
✓ Branch 4 taken 442432 times.
✓ Branch 0 taken 5600 times.
71172992 { 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 21844593 scvs(const FaceCenteredDiamondFVElementGeometry& fvGeometry)
78 {
79 using Iter = typename std::vector<SubControlVolume>::const_iterator;
80 21844593 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
81 21844593 return Dune::IteratorRange<Iter>(s.begin(), s.end());
82 }
83
84 //! get the position related to a localdof
85 template<class LocalDof>
86 auto dofPosition(const LocalDof& localDof) const
87 {
88 return GeometryHelper::facetCenter(this->element(), localDof.index());
89 }
90
91 //! iterator range for sub control volumes faces. Iterates over
92 //! all scvfs of the bound element.
93 //! This is a free function found by means of ADL
94 //! To iterate over all sub control volume faces of this FVElementGeometry use
95 //! for (auto&& scvf : scvfs(fvGeometry))
96 friend inline auto
97 4451472 scvfs(const FaceCenteredDiamondFVElementGeometry& fvGeometry)
98 {
99 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
100 4451472 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
101 4451472 return Dune::IteratorRange<Iter>(s.begin(), s.end());
102 }
103
104 //! Get a local finite element basis
105 9802424 const FeLocalBasis& feLocalBasis() const
106 {
107 9802424 return gridGeometry().feCache().get(element().type()).localBasis();
108 }
109
110 //! The total number of element-local dofs
111 5216367 std::size_t numLocalDofs() const
112 {
113
1/2
✓ Branch 2 taken 34914 times.
✗ Branch 3 not taken.
5216367 return numScv();
114 }
115
116 //! number of sub control volumes in this fv element geometry
117 26483810 std::size_t numScv() const
118 {
119
6/8
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1502471 times.
✓ Branch 5 taken 34914 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 30834 times.
✗ Branch 9 not taken.
✓ Branch 2 taken 2400 times.
✓ Branch 3 taken 3942824 times.
25621395 return ggCache_->scvs(eIdx_).size();
120 }
121
122 //! number of sub control volumes in this fv element geometry
123 149856 std::size_t numScvf() const
124 {
125
1/2
✓ Branch 1 taken 10278 times.
✗ Branch 2 not taken.
149856 return ggCache_->scvfs(eIdx_).size();
126 }
127
128 //! Returns whether one of the geometry's scvfs lies on a boundary
129 28949 bool hasBoundaryScvf() const
130
2/4
✓ Branch 0 taken 682 times.
✓ Branch 1 taken 28267 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
28949 { return ggCache_->hasBoundaryScvf(eIdx_); }
131
132 /*!
133 * \brief bind the local view (r-value overload)
134 * This overload is called when an instance of this class is a temporary in the usage context
135 * This allows a usage like this: `const auto view = localView(...).bind(element);`
136 */
137 107256 FaceCenteredDiamondFVElementGeometry bind(const Element& element) &&
138 {
139
1/2
✓ Branch 1 taken 107256 times.
✗ Branch 2 not taken.
107256 this->bindElement(element);
140 107256 return std::move(*this);
141 }
142
143 838877 void bind(const Element& element) &
144 {
145
3/7
✓ Branch 1 taken 55304 times.
✓ Branch 2 taken 31986 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 3 taken 28948 times.
838877 this->bindElement(element);
146 116238 }
147
148 /*!
149 * \brief bind the local view (r-value overload)
150 * This overload is called when an instance of this class is a temporary in the usage context
151 * This allows a usage like this: `const auto view = localView(...).bindElement(element);`
152 */
153 664905 FaceCenteredDiamondFVElementGeometry bindElement(const Element& element) &&
154 {
155
3/5
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 1 taken 34606 times.
664905 this->bindElement(element);
156
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
664905 return std::move(*this);
157 }
158
159 //! Bind only element-local
160 4058043 void bindElement(const Element& element) &
161 {
162
2/2
✓ Branch 0 taken 2633713 times.
✓ Branch 1 taken 1321550 times.
4058043 element_ = element;
163 4058043 eIdx_ = gridGeometry().elementMapper().index(element);
164 4058043 }
165
166 //! Returns true if bind/bindElement has already been called
167 185 bool isBound() const
168
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
161 { return static_cast<bool>(element_); }
169
170 //! The bound element
171 9051737 const Element& element() const
172
4/5
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 2 taken 55464 times.
36231585 { return *element_; }
173
174 //! The grid geometry we are a restriction of
175 20176656 const GridGeometry& gridGeometry() const
176
14/23
✓ Branch 2 taken 178520 times.
✓ Branch 3 taken 1198864 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 8 taken 55304 times.
✓ Branch 9 taken 10278 times.
✓ Branch 11 taken 10487 times.
✓ Branch 12 taken 20716 times.
✓ Branch 14 taken 10487 times.
✓ Branch 15 taken 480 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 24 taken 8208 times.
✓ Branch 25 taken 655440 times.
✓ Branch 33 taken 2 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 2 times.
✗ Branch 37 not taken.
✓ Branch 1 taken 82886 times.
✓ Branch 0 taken 1280 times.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
18096522 { return ggCache_->gridGeometry(); }
177
178 //! The bound element index
179 2208050 std::size_t elementIndex() const
180
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 712908 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 356454 times.
1137745 { return eIdx_; }
181
182 //! Geometry of a sub control volume
183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
184 {
185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 assert(isBound());
186
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 const auto geo = element().geometry();
187 return {
188
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 SubControlVolume::Traits::geometryType(geo.type()),
189
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 GeometryHelper(geo).getScvCorners(scv.indexInElement())
190 6 };
191 }
192
193 //! Geometry of a sub control volume face
194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
195 {
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 assert(isBound());
197
2/2
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 12 times.
178 const auto geo = element().geometry();
198
2/2
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 12 times.
178 if (scvf.boundary())
199 {
200 // use the information that each boundary scvf corresponds to one scv constructed around the same facet
201 166 const auto localFacetIndex = scvf.insideScvIdx();
202 return {
203 166 referenceElement(geo).type(localFacetIndex, 1),
204 166 GeometryHelper(geo).getBoundaryScvfCorners(localFacetIndex)
205 166 };
206 }
207 else
208 {
209 return {
210 12 SubControlVolumeFace::Traits::interiorGeometryType(geo.type()),
211 12 GeometryHelper(geo).getScvfCorners(scvf.index())
212 12 };
213 }
214 }
215
216 private:
217 std::optional<Element> element_;
218 GridIndexType eIdx_;
219 const GGCache* ggCache_;
220 };
221
222 } // end namespace Dumux
223
224 #endif
225