GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/cvfe/elementfluxvariablescache.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 122 123 99.2%
Branches: 126 214 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 CVFEDiscretization
10 * \brief Global flux variable cache
11 */
12 #ifndef DUMUX_DISCRETIZATION_CVFE_ELEMENT_FLUXVARSCACHE_HH
13 #define DUMUX_DISCRETIZATION_CVFE_ELEMENT_FLUXVARSCACHE_HH
14
15 #include <cstddef>
16 #include <vector>
17 #include <utility>
18
19 namespace Dumux {
20
21 /*!
22 * \ingroup CVFEDiscretization
23 * \brief The flux variables caches for an element
24 * \note The class is specialized for a version with and without caching
25 * If grid caching is enabled the flux caches are stored for the whole gridview in the corresponding
26 * GridFluxVariablesCache which is memory intensive but faster. For caching disabled the
27 * flux caches are locally computed for each element whenever needed.
28 */
29 template<class GFVC, bool cachingEnabled>
30 class CVFEElementFluxVariablesCache
31 {};
32
33 /*!
34 * \ingroup CVFEDiscretization
35 * \brief The flux variables caches for an element with caching enabled
36 */
37 template<class GFVC>
38 class CVFEElementFluxVariablesCache<GFVC, true>
39 {
40 public:
41 //! export the type of the grid flux variables cache
42 using GridFluxVariablesCache = GFVC;
43
44 //! export the type of the flux variables cache
45 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
46
47
5/8
✓ Branch 1 taken 55306 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 138216 times.
✓ Branch 5 taken 20 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 6 not taken.
✓ Branch 3 taken 926094 times.
3244270 CVFEElementFluxVariablesCache(const GridFluxVariablesCache& global)
48 : gridFluxVarsCachePtr_(&global) {}
49
50 // Function is called by the BoxLocalJacobian prior to flux calculations on the element.
51 // We assume the FVGeometries to be bound at this point
52 template<class FVElementGeometry, class ElementVolumeVariables>
53 6234446 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
54 const FVElementGeometry& fvGeometry,
55 const ElementVolumeVariables& elemVolVars) &
56 6234446 { bindElement(element, fvGeometry, elemVolVars); }
57
58 /*!
59 * \brief bind the local view (r-value overload)
60 * This overload is called when an instance of this class is a temporary in the usage context
61 * This allows a usage like this: `const auto view = localView(...).bind(element);`
62 */
63 template<class FVElementGeometry, class ElementVolumeVariables>
64 303520 CVFEElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
65 const FVElementGeometry& fvGeometry,
66 const ElementVolumeVariables& elemVolVars) &&
67 {
68 303520 this->bind(element, fvGeometry, elemVolVars);
69 return std::move(*this);
70 }
71
72 template<class FVElementGeometry, class ElementVolumeVariables>
73
4/7
✓ Branch 1 taken 55304 times.
✓ Branch 2 taken 10487 times.
✓ Branch 4 taken 138216 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 4412 times.
✗ Branch 10 not taken.
✗ Branch 3 not taken.
6234446 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
74 const FVElementGeometry& fvGeometry,
75 const ElementVolumeVariables& elemVolVars) &
76
10/13
✓ Branch 1 taken 55304 times.
✓ Branch 2 taken 401335 times.
✓ Branch 4 taken 204734 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1604912 times.
✓ Branch 8 taken 584732 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 542912 times.
✓ Branch 13 taken 4412 times.
✗ Branch 14 not taken.
✓ Branch 3 taken 2200786 times.
✓ Branch 6 taken 20 times.
✓ Branch 9 taken 6859 times.
6234446 { eIdx_ = fvGeometry.gridGeometry().elementMapper().index(element); }
77
78 /*!
79 * \brief bind the local view (r-value overload)
80 * This overload is called when an instance of this class is a temporary in the usage context
81 * This allows a usage like this: `const auto view = localView(...).bind(element);`
82 */
83 template<class FVElementGeometry, class ElementVolumeVariables>
84 CVFEElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
85 const FVElementGeometry& fvGeometry,
86 const ElementVolumeVariables& elemVolVars) &&
87 {
88 this->bindElement(element, fvGeometry, elemVolVars);
89 return std::move(*this);
90 }
91
92 template<class FVElementGeometry, class ElementVolumeVariables>
93 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
94 const FVElementGeometry& fvGeometry,
95 const ElementVolumeVariables& elemVolVars,
96 const typename FVElementGeometry::SubControlVolumeFace& scvf) &
97 { bindElement(element, fvGeometry, elemVolVars); }
98
99 /*!
100 * \brief bind the local view (r-value overload)
101 * This overload is called when an instance of this class is a temporary in the usage context
102 * This allows a usage like this: `const auto view = localView(...).bind(element);`
103 */
104 template<class FVElementGeometry, class ElementVolumeVariables>
105 CVFEElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
106 const FVElementGeometry& fvGeometry,
107 const ElementVolumeVariables& elemVolVars,
108 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
109 {
110 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
111 return std::move(*this);
112 }
113
114 //! Specialization for the global caching being enabled - do nothing here
115 template<class FVElementGeometry, class ElementVolumeVariables>
116 void update(const typename FVElementGeometry::Element& element,
117 const FVElementGeometry& fvGeometry,
118 const ElementVolumeVariables& elemVolVars) {}
119
120 // access operator
121 template<class SubControlVolumeFace>
122 343582726 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
123 340452374 { return gridFluxVarsCache().cache(eIdx_, scvf.index()); }
124
125 //! The global object we are a restriction of
126 343569808 const GridFluxVariablesCache& gridFluxVarsCache() const
127
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 138800268 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 740772 times.
343569808 { return *gridFluxVarsCachePtr_; }
128
129 private:
130 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
131 std::size_t eIdx_; //!< currently bound element
132 };
133
134 /*!
135 * \ingroup CVFEDiscretization
136 * \brief The flux variables caches for an element with caching disabled
137 */
138 template<class GFVC>
139
52/83
✗ Branch 0 not taken.
✓ Branch 1 taken 245 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 42900 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20364 times.
✓ Branch 7 taken 7361615 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 57360 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 99080 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 976 times.
✓ Branch 16 taken 3234 times.
✓ Branch 17 taken 839 times.
✓ Branch 18 taken 1421 times.
✓ Branch 19 taken 3234 times.
✓ Branch 20 taken 82 times.
✓ Branch 21 taken 1232 times.
✓ Branch 22 taken 196103 times.
✓ Branch 23 taken 2 times.
✓ Branch 25 taken 788614 times.
✓ Branch 26 taken 752 times.
✓ Branch 28 taken 316416 times.
✓ Branch 29 taken 4 times.
✓ Branch 30 taken 153856 times.
✓ Branch 31 taken 400 times.
✓ Branch 32 taken 38840 times.
✓ Branch 33 taken 16 times.
✓ Branch 34 taken 7712 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 1233696 times.
✓ Branch 37 taken 153840 times.
✓ Branch 39 taken 7708 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 6552 times.
✓ Branch 42 taken 50000 times.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 1 times.
✓ Branch 47 taken 50000 times.
✓ Branch 48 taken 3021 times.
✗ Branch 49 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 326574 times.
✓ Branch 56 taken 12168 times.
✓ Branch 57 taken 326574 times.
✓ Branch 58 taken 12168 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 175910 times.
✓ Branch 62 taken 7020 times.
✓ Branch 63 taken 175910 times.
✓ Branch 64 taken 6920 times.
✓ Branch 65 taken 1 times.
✗ Branch 66 not taken.
✓ Branch 67 taken 43860 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✓ Branch 71 taken 3 times.
✗ Branch 72 not taken.
✓ Branch 73 taken 3 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✓ Branch 77 taken 2 times.
✗ Branch 78 not taken.
✓ Branch 79 taken 2 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 38 not taken.
✗ Branch 43 not taken.
✓ Branch 50 taken 964001 times.
✓ Branch 24 taken 64065 times.
✓ Branch 27 taken 4 times.
24768998 class CVFEElementFluxVariablesCache<GFVC, false>
140 {
141 public:
142 //! export the type of the grid flux variables cache
143 using GridFluxVariablesCache = GFVC;
144
145 //! export the type of the flux variables cache
146 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
147
148 11118244 CVFEElementFluxVariablesCache(const GridFluxVariablesCache& global)
149
13/29
✓ Branch 1 taken 245 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 207802 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7377489 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 57376 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 197146 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 420488 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3037 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 339094 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 190938 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 51571 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 50002 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 964002 times.
✗ Branch 35 not taken.
✓ Branch 38 taken 1 times.
✗ Branch 39 not taken.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
11118244 : gridFluxVarsCachePtr_(&global) {}
150
151 // Function is called by the BoxLocalJacobian prior to flux calculations on the element.
152 // We assume the FVGeometries to be bound at this point
153 template<class FVElementGeometry, class ElementVolumeVariables>
154 10404332 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
155 const FVElementGeometry& fvGeometry,
156 const ElementVolumeVariables& elemVolVars) &
157 {
158
9/13
✓ Branch 1 taken 68544 times.
✓ Branch 2 taken 57082 times.
✓ Branch 6 taken 117398 times.
✗ Branch 7 not taken.
✓ Branch 11 taken 200 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 100 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1928 times.
✗ Branch 18 not taken.
✓ Branch 3 taken 19752 times.
✓ Branch 4 taken 64 times.
✓ Branch 5 taken 92 times.
10225190 bindElement(element, fvGeometry, elemVolVars);
159 290248 }
160
161 /*!
162 * \brief bind the local view (r-value overload)
163 * This overload is called when an instance of this class is a temporary in the usage context
164 * This allows a usage like this: `const auto view = localView(...).bind(element);`
165 */
166 template<class FVElementGeometry, class ElementVolumeVariables>
167
1/16
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 4 taken 179142 times.
✗ 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.
179142 CVFEElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
168 const FVElementGeometry& fvGeometry,
169 const ElementVolumeVariables& elemVolVars) &&
170 {
171 179142 this->bind(element, fvGeometry, elemVolVars);
172 179142 return std::move(*this);
173 }
174
175 template<class FVElementGeometry, class ElementVolumeVariables>
176 16223204 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
177 const FVElementGeometry& fvGeometry,
178 const ElementVolumeVariables& elemVolVars) &
179 {
180 // temporary resizing of the cache
181 16223204 fluxVarsCache_.resize(fvGeometry.numScvf());
182
2/2
✓ Branch 0 taken 37645014 times.
✓ Branch 1 taken 12038382 times.
61627964 for (auto&& scvf : scvfs(fvGeometry))
183 45404760 (*this)[scvf].update(gridFluxVarsCache().problem(), element, fvGeometry, elemVolVars, scvf);
184 16223204 }
185
186 /*!
187 * \brief bind the local view (r-value overload)
188 * This overload is called when an instance of this class is a temporary in the usage context
189 * This allows a usage like this: `const auto view = localView(...).bind(element);`
190 */
191 template<class FVElementGeometry, class ElementVolumeVariables>
192 318007 CVFEElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
193 const FVElementGeometry& fvGeometry,
194 const ElementVolumeVariables& elemVolVars) &&
195 {
196
4/8
✓ Branch 1 taken 161146 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 161146 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 156861 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 156861 times.
✗ Branch 11 not taken.
318007 this->bindElement(element, fvGeometry, elemVolVars);
197
2/4
✓ Branch 1 taken 161146 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 156861 times.
✗ Branch 5 not taken.
318007 return std::move(*this);
198 }
199
200 template<class FVElementGeometry, class ElementVolumeVariables>
201 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
202 const FVElementGeometry& fvGeometry,
203 const ElementVolumeVariables& elemVolVars,
204 const typename FVElementGeometry::SubControlVolumeFace& scvf) &
205 {
206 fluxVarsCache_.resize(fvGeometry.numScvf());
207 (*this)[scvf].update(gridFluxVarsCache().problem(), element, fvGeometry, elemVolVars, scvf);
208 }
209
210 /*!
211 * \brief bind the local view (r-value overload)
212 * This overload is called when an instance of this class is a temporary in the usage context
213 * This allows a usage like this: `const auto view = localView(...).bind(element);`
214 */
215 template<class FVElementGeometry, class ElementVolumeVariables>
216 CVFEElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
217 const FVElementGeometry& fvGeometry,
218 const ElementVolumeVariables& elemVolVars,
219 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
220 {
221 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
222 return std::move(*this);
223 }
224
225 /*!
226 * \brief Update the caches if the volume variables have changed and the cache is solution-dependent
227 * \note Results in undefined behaviour if called before bind() or with a different element
228 */
229 template<class FVElementGeometry, class ElementVolumeVariables>
230 4664882 void update(const typename FVElementGeometry::Element& element,
231 const FVElementGeometry& fvGeometry,
232 const ElementVolumeVariables& elemVolVars)
233 {
234 if constexpr (FluxVariablesCache::isSolDependent)
235 {
236 4664882 fluxVarsCache_.resize(fvGeometry.numScvf());
237
2/2
✓ Branch 0 taken 2480354 times.
✓ Branch 1 taken 2480354 times.
9329764 for (const auto& scvf : scvfs(fvGeometry))
238 4664882 (*this)[scvf].update(gridFluxVarsCache().problem(), element, fvGeometry, elemVolVars, scvf);
239 }
240 4664882 }
241
242 // access operator
243 template<class SubControlVolumeFace>
244 1066593126 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
245
13/14
✓ Branch 0 taken 413500 times.
✓ Branch 1 taken 484304272 times.
✓ Branch 2 taken 107609 times.
✓ Branch 3 taken 3536972 times.
✓ Branch 5 taken 2625105 times.
✓ Branch 6 taken 405494 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 32058562 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 31948673 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 31948673 times.
✓ Branch 4 taken 460861 times.
✓ Branch 7 taken 1153319 times.
1034644453 { return fluxVarsCache_[scvf.index()]; }
246
247 // access operator
248 template<class SubControlVolumeFace>
249 74518112 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
250
7/11
✗ Branch 0 not taken.
✓ Branch 1 taken 24032712 times.
✓ Branch 2 taken 36116 times.
✓ Branch 3 taken 10183684 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 61904 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 61536 times.
✓ Branch 8 taken 8736 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8056 times.
74518112 { return fluxVarsCache_[scvf.index()]; }
251
252 //! The global object we are a restriction of
253 40125368 const GridFluxVariablesCache& gridFluxVarsCache() const
254 40125368 { return *gridFluxVarsCachePtr_; }
255
256 private:
257 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
258 std::vector<FluxVariablesCache> fluxVarsCache_;
259 };
260
261 } // end namespace Dumux
262
263 #endif
264