GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/staggered/gridvariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 40 56 71.4%
Functions: 186 638 29.2%
Branches: 43 90 47.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 StaggeredDiscretization
10 * \copydoc Dumux::StaggeredGridVariables
11 */
12 #ifndef DUMUX_STAGGERED_GRID_VARIABLES_HH
13 #define DUMUX_STAGGERED_GRID_VARIABLES_HH
14
15 #include <dumux/discretization/fvgridvariables.hh>
16
17 namespace Dumux {
18
19 /*!
20 * \ingroup StaggeredDiscretization
21 * \brief Base class for cell center of face specific auxiliary GridVariables classes.
22 * Provides a common interface and a pointer to the actual grid variables.
23 */
24 template<class ActualGridVariables>
25 class StaggeredGridVariablesView
26 {
27 public:
28 using GridVolumeVariables = typename ActualGridVariables::GridVolumeVariables;
29 using GridFaceVariables = typename ActualGridVariables::GridFaceVariables;
30 using GridFluxVariablesCache = typename ActualGridVariables::GridFluxVariablesCache;
31
32 //! export type of the volume variables
33 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
34
35 //! export primary variable type
36 using PrimaryVariables = typename VolumeVariables::PrimaryVariables;
37 using GridGeometry = typename ActualGridVariables::GridGeometry;
38
39 102 explicit StaggeredGridVariablesView(ActualGridVariables* gridVariables)
40 102 : gridVariables_(gridVariables) {}
41
42 //! return the flux variables cache
43 const GridFluxVariablesCache& gridFluxVarsCache() const
44
4/8
✓ Branch 1 taken 1360444 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1360444 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1360444 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1360444 times.
✗ Branch 11 not taken.
5441776 { return gridVariables_->gridFluxVarsCache(); }
45
46 //! return the flux variables cache
47 GridFluxVariablesCache& gridFluxVarsCache()
48 11134 { return gridVariables_->gridFluxVarsCache(); }
49
50 //! return the current volume variables
51 const GridVolumeVariables& curGridVolVars() const
52
4/8
✓ Branch 1 taken 1360444 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1360444 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1360444 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1360444 times.
✗ Branch 11 not taken.
5441776 { return gridVariables_->curGridVolVars(); }
53
54 //! return the current volume variables
55 GridVolumeVariables& curGridVolVars()
56 44453116 { return gridVariables_->curGridVolVars(); }
57
58 //! return the volume variables of the previous time step (for instationary problems)
59 const GridVolumeVariables& prevGridVolVars() const
60
4/8
✓ Branch 1 taken 1360444 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1360444 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1360444 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1360444 times.
✗ Branch 11 not taken.
5441776 { return gridVariables_->prevGridVolVars(); }
61
62 //! return the volume variables of the previous time step (for instationary problems)
63 GridVolumeVariables& prevGridVolVars()
64 30 { return gridVariables_->prevGridVolVars(); }
65
66 //! return the current face variables
67 const GridFaceVariables& curGridFaceVars() const
68 5441776 { return gridVariables_->curGridFaceVars(); }
69
70 //! return the previous face variables
71 const GridFaceVariables& prevGridFaceVars() const
72 5441776 { return gridVariables_->prevGridFaceVars(); }
73
74 //! return the current face variables
75 GridFaceVariables& curGridFaceVars()
76 96523728 { return gridVariables_->curGridFaceVars(); }
77
78 //! return the previous face variables
79 GridFaceVariables& prevGridFaceVars()
80 { return gridVariables_->prevGridFaceVars(); }
81
82 //! return the fv grid geometry
83 const GridGeometry& gridGeometry() const
84 22238 { return (*gridVariables_->gridGeometry_); }
85
86 // return the actual grid variables
87 const ActualGridVariables& gridVariables() const
88 { return *gridVariables_; }
89
90 // return the actual grid variables
91 ActualGridVariables& gridVariables()
92 { return *gridVariables_; }
93
94 protected:
95 ActualGridVariables* gridVariables_;
96 };
97
98 /*!
99 * \ingroup StaggeredDiscretization
100 * \brief Cell center specific auxiliary GridVariables classes.
101 * Required for the Dumux multi-domain framework.
102 */
103 template<class ActualGridVariables>
104 class CellCenterGridVariablesView : public StaggeredGridVariablesView<ActualGridVariables>
105 {
106 using ParentType = StaggeredGridVariablesView<ActualGridVariables>;
107 public:
108
1/2
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
51 using ParentType::ParentType;
109
110 //! initialize all variables (stationary case)
111 template<class SolVector>
112 void init(const SolVector& curSol)
113 {
114 this->curGridVolVars().update(this->gridGeometry(), curSol);
115 this->gridFluxVarsCache().update(this->gridGeometry(), this->curGridVolVars(), curSol, true);
116 this->prevGridVolVars().update(this->gridGeometry(), curSol);
117 }
118
119 //! update the volume variables and the flux variables cache
120 template<class SolVector>
121 5552 void update(const SolVector& curSol)
122 {
123 16656 this->curGridVolVars().update(this->gridGeometry(), curSol);
124 22208 this->gridFluxVarsCache().update(this->gridGeometry(), this->curGridVolVars(), curSol);
125 5552 }
126
127 //! resets state to the one before time integration
128 template<class SolVector>
129 15 void resetTimeStep(const SolVector& sol)
130 {
131 45 this->curGridVolVars() = this->prevGridVolVars();
132 60 this->gridFluxVarsCache().update(this->gridGeometry(), this->curGridVolVars(), sol);
133 15 }
134 };
135
136 /*!
137 * \ingroup StaggeredDiscretization
138 * \brief Face specific auxiliary GridVariables classes.
139 * Required for the Dumux multi-domain framework.
140 */
141 template<class ActualGridVariables>
142 class FaceGridVariablesView : public StaggeredGridVariablesView<ActualGridVariables>
143 {
144 using ParentType = StaggeredGridVariablesView<ActualGridVariables>;
145 public:
146
1/2
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
51 using ParentType::ParentType;
147
148 //! initialize all variables (stationary case)
149 template<class SolVector>
150 void init(const SolVector& curSol)
151 {
152 this->curGridFaceVars().update(this->gridGeometry(), curSol);
153 this->prevGridFaceVars().update(this->gridGeometry(), curSol);
154 }
155
156 //! update the face variables
157 template<class SolVector>
158 void update(const SolVector& curSol)
159 {
160 this->curGridFaceVars().update(this->gridGeometry(), curSol);
161 }
162
163 //! resets state to the one before time integration
164 template<class SolVector>
165 void resetTimeStep(const SolVector& sol)
166 {
167 this->curGridFaceVars() = this->prevGridFaceVars();
168 }
169 };
170
171
172
173 /*!
174 * \ingroup StaggeredDiscretization
175 * \brief Class storing data associated to scvs and scvfs
176 * \tparam GG the type of the grid geometry
177 * \tparam GVV the type of the grid volume variables
178 * \tparam GFVC the type of the grid flux variables cache
179 * \tparam GFV the type of the grid face variables
180 */
181 template<class GG, class GVV, class GFVC, class GFV>
182 class StaggeredGridVariables : public FVGridVariables<GG, GVV, GFVC>
183 {
184 using ParentType = FVGridVariables<GG, GVV, GFVC>;
185 using ThisType = StaggeredGridVariables<GG, GVV, GFVC, GFV>;
186 friend class StaggeredGridVariablesView<ThisType>;
187
188 static constexpr auto cellCenterIdx = GG::cellCenterIdx();
189 static constexpr auto faceIdx = GG::faceIdx();
190
191 public:
192 using CellCenterGridVariablesType = CellCenterGridVariablesView<ThisType>;
193 using FaceGridVariablesType = FaceGridVariablesView<ThisType>;
194
195 //! export the type of the grid volume variables
196 using GridVolumeVariables = GVV;
197 //! export the type of the grid flux variables cache
198 using GridFluxVariablesCache = GFVC;
199 //! export the type of the grid face variables
200 using GridFaceVariables = GFV;
201 //! export the type of the grid geometry
202 using GridGeometry = GG;
203
204 //! Constructor
205 template<class Problem>
206 99 StaggeredGridVariables(std::shared_ptr<Problem> problem,
207 std::shared_ptr<GridGeometry> gridGeometry)
208 : ParentType(problem, gridGeometry)
209 198 , curGridFaceVariables_(*problem)
210
3/10
✓ Branch 3 taken 75 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 75 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 75 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
594 , prevGridFaceVariables_(*problem)
211 99 {}
212
213 //! update all variables
214 template<class SolutionVector>
215 void update(const SolutionVector& curSol)
216 {
217 ParentType::update(curSol[cellCenterIdx]);
218 curGridFaceVariables_.update(*this->gridGeometry_, curSol[faceIdx]);
219 }
220
221 //! initialize all variables (stationary case)
222 template<class SolutionVector>
223 99 void init(const SolutionVector& curSol)
224 {
225 198 ParentType::init(curSol[cellCenterIdx]);
226 297 curGridFaceVariables_.update(*this->gridGeometry_, curSol[faceIdx]);
227 297 prevGridFaceVariables_.update(*this->gridGeometry_, curSol[faceIdx]);
228 99 }
229
230 //! Sets the current state as the previous for next time step
231 //! this has to be called at the end of each time step
232 1268 void advanceTimeStep()
233 {
234 1268 ParentType::advanceTimeStep();
235 1268 prevGridFaceVariables_ = curGridFaceVariables_;
236 1268 }
237
238 //! resets state to the one before time integration
239 template<class SolutionVector>
240 void resetTimeStep(const SolutionVector& solution)
241 {
242 ParentType::resetTimeStep(solution);
243 curGridFaceVariables_ = prevGridFaceVariables_;
244 }
245
246 //! return the current face variables
247 const GridFaceVariables& curGridFaceVars() const
248
24/48
✓ Branch 1 taken 144 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 81 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
471783 { return curGridFaceVariables_; }
249
250 //! return the previous face variables
251 const GridFaceVariables& prevGridFaceVars() const
252 { return prevGridFaceVariables_; }
253
254 //! return the current face variables
255 GridFaceVariables& curGridFaceVars()
256 50982752 { return curGridFaceVariables_; }
257
258 //! return the previous face variables
259 GridFaceVariables& prevGridFaceVars()
260 2720888 { return prevGridFaceVariables_; }
261
262 //! Returns a pointer the cell center specific auxiliary class. Required for the multi-domain FVAssembler's ctor.
263 std::unique_ptr<CellCenterGridVariablesView<ThisType>> cellCenterGridVariablesPtr()
264 {
265
1/2
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
51 return std::make_unique<CellCenterGridVariablesView<ThisType>>(this);
266 }
267
268 //! Returns a pointer the face specific auxiliary class. Required for the multi-domain FVAssembler's ctor.
269 std::unique_ptr<FaceGridVariablesView<ThisType>> faceGridVariablesPtr()
270 {
271
1/2
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
51 return std::make_unique<FaceGridVariablesView<ThisType>>(this);
272 }
273
274 //! Return a copy of the cell center specific auxiliary class.
275 CellCenterGridVariablesView<ThisType> cellCenterGridVariables() const
276 {
277 return CellCenterGridVariablesView<ThisType>(this);
278 }
279
280 //! Return a copy of the face specific auxiliary class.
281 FaceGridVariablesView<ThisType> faceGridVariables() const
282 {
283 return FaceGridVariablesView<ThisType>(this);
284 }
285
286
287 private:
288 GridFaceVariables curGridFaceVariables_;
289 GridFaceVariables prevGridFaceVariables_;
290 };
291
292 } // end namespace Dumux
293
294 #endif
295