GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/facecentered/diamond/fvelementgeometry.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 57 57 100.0%
Functions: 22 22 100.0%
Branches: 79 138 57.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-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 17784774 const SubControlVolume& scv(LocalIndexType scvIdx) const
65
3/3
✓ Branch 1 taken 36608 times.
✓ Branch 2 taken 74416 times.
✓ Branch 0 taken 5600 times.
17784774 { 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 35389454 scvs(const FaceCenteredDiamondFVElementGeometry& fvGeometry)
78 {
79 using Iter = typename std::vector<SubControlVolume>::const_iterator;
80 35388511 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
81 35388511 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 4451472 scvfs(const FaceCenteredDiamondFVElementGeometry& fvGeometry)
91 {
92 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
93 4451472 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
94 4451472 return Dune::IteratorRange<Iter>(s.begin(), s.end());
95 }
96
97 //! Get a local finite element basis
98 9802424 const FeLocalBasis& feLocalBasis() const
99 {
100 9802424 return gridGeometry().feCache().get(element().type()).localBasis();
101 }
102
103 //! number of sub control volumes in this fv element geometry
104 7680785 std::size_t numScv() const
105 {
106
4/6
✓ Branch 3 taken 34914 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 30834 times.
✗ Branch 7 not taken.
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 186999 times.
7680785 return ggCache_->scvs(eIdx_).size();
107 }
108
109 //! number of sub control volumes in this fv element geometry
110 149856 std::size_t numScvf() const
111 {
112
1/2
✓ Branch 1 taken 10278 times.
✗ Branch 2 not taken.
149856 return ggCache_->scvfs(eIdx_).size();
113 }
114
115 //! Returns whether one of the geometry's scvfs lies on a boundary
116 28949 bool hasBoundaryScvf() const
117
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_); }
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 107256 FaceCenteredDiamondFVElementGeometry bind(const Element& element) &&
125 {
126
1/2
✓ Branch 1 taken 107256 times.
✗ Branch 2 not taken.
107256 this->bindElement(element);
127 107256 return std::move(*this);
128 }
129
130 838877 void bind(const Element& element) &
131 {
132
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);
133 116238 }
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 664905 FaceCenteredDiamondFVElementGeometry bindElement(const Element& element) &&
141 {
142
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);
143
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
664905 return std::move(*this);
144 }
145
146 //! Bind only element-local
147 4058043 void bindElement(const Element& element) &
148 {
149
2/2
✓ Branch 0 taken 2633713 times.
✓ Branch 1 taken 1321550 times.
4058043 element_ = element;
150 4058043 eIdx_ = gridGeometry().elementMapper().index(element);
151 4058043 }
152
153 //! Returns true if bind/bindElement has already been called
154 185 bool isBound() const
155
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
161 { return static_cast<bool>(element_); }
156
157 //! The bound element
158 9051737 const Element& element() const
159
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_; }
160
161 //! The grid geometry we are a restriction of
162 20176656 const GridGeometry& gridGeometry() const
163
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(); }
164
165 //! The bound element index
166 1495142 std::size_t elementIndex() const
167
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 712908 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
781291 { return eIdx_; }
168
169 //! Geometry of a sub control volume
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
171 {
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 assert(isBound());
173
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 const auto geo = element().geometry();
174 return {
175
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 SubControlVolume::Traits::geometryType(geo.type()),
176
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())
177 6 };
178 }
179
180 //! Geometry of a sub control volume face
181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
182 {
183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 assert(isBound());
184
2/2
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 12 times.
178 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 166 GeometryHelper(geo).getBoundaryScvfCorners(localFacetIndex)
192 166 };
193 }
194 else
195 {
196 return {
197 12 SubControlVolumeFace::Traits::interiorGeometryType(geo.type()),
198 12 GeometryHelper(geo).getScvfCorners(scvf.index())
199 12 };
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