GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/cvfe/elementfluxvariablescache.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 24 31 77.4%
Functions: 115 316 36.4%
Branches: 168 312 53.8%

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 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 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 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
54 const FVElementGeometry& fvGeometry,
55 const ElementVolumeVariables& elemVolVars) &
56 11362778 { 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 CVFEElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
65 const FVElementGeometry& fvGeometry,
66 const ElementVolumeVariables& elemVolVars) &&
67 {
68 607040 this->bind(element, fvGeometry, elemVolVars);
69 303520 return std::move(*this);
70 }
71
72 template<class FVElementGeometry, class ElementVolumeVariables>
73 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
74 const FVElementGeometry& fvGeometry,
75 const ElementVolumeVariables& elemVolVars) &
76
17/31
✗ Branch 3 not taken.
✓ Branch 4 taken 76278 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 55304 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 432836 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 10487 times.
✓ Branch 13 taken 138216 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 10487 times.
✓ Branch 16 taken 138216 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2207177 times.
✓ Branch 19 taken 194247 times.
✗ Branch 20 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 8844 times.
✓ Branch 30 taken 1058780 times.
✓ Branch 31 taken 575908 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 15683 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 534088 times.
✓ Branch 38 taken 4412 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 4412 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 4412 times.
✗ Branch 45 not taken.
17044167 { 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 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
123
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 138374284 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138374284 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 740772 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 740772 times.
660672172 { return gridFluxVarsCache().cache(eIdx_, scvf.index()); }
124
125 //! The global object we are a restriction of
126 const GridFluxVariablesCache& gridFluxVarsCache() const
127 { 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
62/118
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 42900 times.
✓ Branch 6 taken 20294 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 7622012 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 156019 times.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 98239 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 890 times.
✓ Branch 20 taken 4603 times.
✓ Branch 21 taken 890 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 5208 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 788772 times.
✓ Branch 26 taken 260096 times.
✓ Branch 27 taken 137 times.
✓ Branch 28 taken 316791 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 605 times.
✓ Branch 31 taken 788612 times.
✓ Branch 32 taken 12 times.
✓ Branch 33 taken 3 times.
✓ Branch 34 taken 16 times.
✓ Branch 35 taken 316431 times.
✓ Branch 36 taken 400 times.
✓ Branch 37 taken 28 times.
✓ Branch 38 taken 38840 times.
✓ Branch 39 taken 154252 times.
✓ Branch 40 taken 352 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 161552 times.
✓ Branch 43 taken 7708 times.
✓ Branch 44 taken 153840 times.
✓ Branch 45 taken 4 times.
✓ Branch 46 taken 203840 times.
✓ Branch 47 taken 4 times.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✓ Branch 53 taken 203840 times.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 56 taken 1117840 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 153840 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 153840 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 1233344 times.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✓ Branch 65 taken 6552 times.
✓ Branch 66 taken 101 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 6553 times.
✓ Branch 69 taken 1 times.
✓ Branch 70 taken 6552 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 6553 times.
✓ Branch 73 taken 1 times.
✓ Branch 74 taken 1 times.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✓ Branch 79 taken 3021 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 3021 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 3021 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 3021 times.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✓ Branch 92 taken 326574 times.
✓ Branch 93 taken 12168 times.
✓ Branch 94 taken 326574 times.
✓ Branch 95 taken 12168 times.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✓ Branch 98 taken 175910 times.
✓ Branch 99 taken 6920 times.
✓ Branch 100 taken 175910 times.
✓ Branch 101 taken 6920 times.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✓ Branch 104 taken 43859 times.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✓ Branch 108 taken 2 times.
✗ Branch 109 not taken.
✓ Branch 110 taken 2 times.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✓ Branch 114 taken 2 times.
✗ Branch 115 not taken.
✓ Branch 116 taken 2 times.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
27023041 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 CVFEElementFluxVariablesCache(const GridFluxVariablesCache& global)
149
26/58
✓ Branch 1 taken 246 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 246 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 190332 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 190332 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 7637045 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 7637045 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 57796 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 57796 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 197146 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 197146 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 420488 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 420488 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 3037 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 3037 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 339094 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 339094 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 190938 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 190938 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 51571 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 51571 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 50002 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 50002 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 964002 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 964002 times.
✗ Branch 71 not taken.
✓ Branch 75 taken 1 times.
✗ Branch 76 not taken.
✓ Branch 78 taken 1 times.
✗ Branch 79 not taken.
22721030 : 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 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 68123 times.
✓ Branch 2 taken 57082 times.
✓ Branch 3 taken 19752 times.
✓ Branch 4 taken 64 times.
✓ Branch 5 taken 22 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.
10485350 bindElement(element, fvGeometry, elemVolVars);
159 }
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 CVFEElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
168 const FVElementGeometry& fvGeometry,
169 const ElementVolumeVariables& elemVolVars) &&
170 {
171
1/16
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 4 taken 161672 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.
161672 this->bind(element, fvGeometry, elemVolVars);
172 323344 return std::move(*this);
173 }
174
175 template<class FVElementGeometry, class ElementVolumeVariables>
176 16465894 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 32931788 fluxVarsCache_.resize(fvGeometry.numScvf());
182
4/4
✓ Branch 0 taken 38297047 times.
✓ Branch 1 taken 12281072 times.
✓ Branch 2 taken 35357525 times.
✓ Branch 3 taken 9341550 times.
110576020 for (auto&& scvf : scvfs(fvGeometry))
183 60526147 (*this)[scvf].update(gridFluxVarsCache().problem(), element, fvGeometry, elemVolVars, scvf);
184 16465894 }
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 CVFEElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
193 const FVElementGeometry& fvGeometry,
194 const ElementVolumeVariables& elemVolVars) &&
195 {
196
2/4
✓ Branch 1 taken 161146 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 156861 times.
✗ Branch 5 not taken.
318007 this->bindElement(element, fvGeometry, elemVolVars);
197
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.
636014 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 4664146 void update(const typename FVElementGeometry::Element& element,
231 const FVElementGeometry& fvGeometry,
232 const ElementVolumeVariables& elemVolVars)
233 {
234 if constexpr (FluxVariablesCache::isSolDependent)
235 {
236 9328292 fluxVarsCache_.resize(fvGeometry.numScvf());
237
2/2
✓ Branch 0 taken 2479618 times.
✓ Branch 1 taken 2479618 times.
13992438 for (const auto& scvf : scvfs(fvGeometry))
238 9328292 (*this)[scvf].update(gridFluxVarsCache().problem(), element, fvGeometry, elemVolVars, scvf);
239 }
240 4664146 }
241
242 // access operator
243 template<class SubControlVolumeFace>
244 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
245
26/28
✓ Branch 0 taken 40694 times.
✓ Branch 1 taken 501950800 times.
✓ Branch 2 taken 40694 times.
✓ Branch 3 taken 501974934 times.
✓ Branch 4 taken 4429 times.
✓ Branch 5 taken 3276288 times.
✓ Branch 6 taken 4444 times.
✓ Branch 7 taken 3426319 times.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 2705461 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 2564055 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 1186078 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1153319 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 32058562 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 32058562 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 31948673 times.
✓ Branch 22 taken 1 times.
✓ Branch 23 taken 31948673 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 31948673 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 31948673 times.
2100597618 { return fluxVarsCache_[scvf.index()]; }
246
247 // access operator
248 template<class SubControlVolumeFace>
249 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
250
11/22
✗ Branch 0 not taken.
✓ Branch 1 taken 10053508 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10089624 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24176988 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 24140872 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 61536 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 61536 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 61624 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 70360 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 8736 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 8056 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 8056 times.
150294226 { return fluxVarsCache_[scvf.index()]; }
251
252 //! The global object we are a restriction of
253 const GridFluxVariablesCache& gridFluxVarsCache() const
254 { return *gridFluxVarsCachePtr_; }
255
256 private:
257 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
258 std::vector<FluxVariablesCache> fluxVarsCache_;
259 };
260
261 } // end namespace Dumux
262
263 #endif
264