GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/staggered/freeflow/gridvolumevariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 44 57 77.2%
Functions: 118 211 55.9%
Branches: 98 285 34.4%

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::StaggeredGridVolumeVariables
11 */
12 #ifndef DUMUX_DISCRETIZATION_STAGGERED_GRID_VOLUMEVARIABLES_HH
13 #define DUMUX_DISCRETIZATION_STAGGERED_GRID_VOLUMEVARIABLES_HH
14
15 #include <dune/common/exceptions.hh>
16 #include <dune/common/rangeutilities.hh>
17
18 // make the local view function available whenever we use this class
19 #include <dumux/discretization/localview.hh>
20 #include <dumux/discretization/staggered/elementsolution.hh>
21 #include <dumux/discretization/staggered/freeflow/elementvolumevariables.hh>
22
23 namespace Dumux {
24
25 template<class P, class VV>
26 struct StaggeredGridDefaultGridVolumeVariablesTraits
27 {
28 using Problem = P;
29 using VolumeVariables = VV;
30 using PrimaryVariables = typename VV::PrimaryVariables;
31
32 template<class GridVolumeVariables, bool cachingEnabled>
33 using LocalView = StaggeredElementVolumeVariables<GridVolumeVariables, cachingEnabled>;
34
35 //! Returns the primary variables used for the boundary volVars and checks for admissible
36 //! combinations for boundary conditions.
37 template<class Problem, class SolutionVector, class Element, class SubControlVolumeFace>
38 705928 static PrimaryVariables getBoundaryPriVars(const Problem& problem,
39 const SolutionVector& sol,
40 const Element& element,
41 const SubControlVolumeFace& scvf)
42 {
43 using CellCenterPrimaryVariables = typename SolutionVector::value_type;
44 using Indices = typename VolumeVariables::Indices;
45 static constexpr auto dim = PrimaryVariables::dimension - CellCenterPrimaryVariables::dimension;
46 static constexpr auto offset = dim;
47
48 705928 const auto bcTypes = problem.boundaryTypes(element, scvf);
49 705928 PrimaryVariables boundaryPriVars(0.0);
50
51 // make sure to not use outflow BC for momentum balance
52
2/2
✓ Branch 0 taken 1410896 times.
✓ Branch 1 taken 705448 times.
2117784 for(int i = 0; i < dim; ++i)
53 {
54
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1410896 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1410896 times.
2823712 if(bcTypes.isOutflow(Indices::velocity(i)))
55 DUNE_THROW(Dune::InvalidStateException, "Outflow condition cannot be used for velocity. Set only a Dirichlet value for pressure instead.");
56 }
57
58
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 705448 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 705448 times.
1411856 if(bcTypes.isOutflow(Indices::pressureIdx))
59 DUNE_THROW(Dune::InvalidStateException, "Outflow condition cannot be used for pressure. Set only a Dirichlet value for velocity instead.");
60
61 // Determine the pressure value at a boundary with a Dirichlet condition for velocity.
62 // This just takes the value of the adjacent inner cell.
63
2/2
✓ Branch 0 taken 259560 times.
✓ Branch 1 taken 445888 times.
705928 if(bcTypes.isDirichlet(Indices::velocity(scvf.directionIndex())))
64 {
65
1/2
✓ Branch 0 taken 445888 times.
✗ Branch 1 not taken.
446008 if(bcTypes.isDirichlet(Indices::pressureIdx))
66 DUNE_THROW(Dune::InvalidStateException, "A Dirichlet condition for velocity must not be combined with a Dirichlet condition for pressure");
67 else
68 2177886 boundaryPriVars[Indices::pressureIdx] = sol[scvf.insideScvIdx()][Indices::pressureIdx - offset];
69 // TODO: pressure could be extrapolated to the boundary
70 }
71
72 // Determine the pressure value for a boundary with a Dirichlet condition for pressure.
73 // Takes a value specified in the problem.
74
2/2
✓ Branch 0 taken 508370 times.
✓ Branch 1 taken 197078 times.
705928 if(bcTypes.isDirichlet(Indices::pressureIdx))
75 {
76
1/2
✓ Branch 0 taken 197078 times.
✗ Branch 1 not taken.
197078 if(bcTypes.isDirichlet(Indices::velocity(scvf.directionIndex())))
77 DUNE_THROW(Dune::InvalidStateException, "A Dirichlet condition for velocity must not be combined with a Dirichlet condition for pressure");
78 else
79 239480 boundaryPriVars[Indices::pressureIdx] = problem.dirichlet(element, scvf)[Indices::pressureIdx];
80 }
81
82 // Return for isothermal single-phase systems ...
83 if(CellCenterPrimaryVariables::dimension == 1)
84 return boundaryPriVars;
85
86 // ... or handle values for components, temperature, etc.
87
2/2
✓ Branch 0 taken 2123736 times.
✓ Branch 1 taken 639156 times.
2764812 for(int eqIdx = offset; eqIdx < PrimaryVariables::dimension; ++eqIdx)
88 {
89
2/2
✓ Branch 0 taken 1484580 times.
✓ Branch 1 taken 639156 times.
2125216 if(eqIdx == Indices::pressureIdx)
90 continue;
91
92
2/2
✓ Branch 0 taken 676494 times.
✓ Branch 1 taken 808086 times.
1485620 if(bcTypes.isDirichlet(eqIdx))
93 809066 boundaryPriVars[eqIdx] = problem.dirichlet(element, scvf)[eqIdx];
94
10/10
✓ Branch 0 taken 210988 times.
✓ Branch 1 taken 465506 times.
✓ Branch 2 taken 210988 times.
✓ Branch 3 taken 465506 times.
✓ Branch 4 taken 109818 times.
✓ Branch 5 taken 101170 times.
✓ Branch 6 taken 109818 times.
✓ Branch 7 taken 101170 times.
✓ Branch 8 taken 900 times.
✓ Branch 9 taken 108918 times.
1354788 else if(bcTypes.isOutflow(eqIdx) || bcTypes.isSymmetry() || bcTypes.isNeumann(eqIdx))
95 3377970 boundaryPriVars[eqIdx] = sol[scvf.insideScvIdx()][eqIdx - offset];
96 }
97
98 // make sure that a potential outflow condition is set for all components
99 std::array<bool, VolumeVariables::numFluidComponents() - 1> isComponentOutflow;
100
2/2
✓ Branch 0 taken 291092 times.
✓ Branch 1 taken 281412 times.
930928 for(int compIdx = 1; compIdx < VolumeVariables::numFluidComponents(); ++compIdx)
101 {
102 291332 const auto eqIdx = VolumeVariables::Indices::conti0EqIdx + compIdx;
103 873996 isComponentOutflow[compIdx -1] = bcTypes.isOutflow(eqIdx);
104 }
105
106
3/4
✓ Branch 0 taken 83604 times.
✓ Branch 1 taken 197808 times.
✓ Branch 2 taken 83604 times.
✗ Branch 3 not taken.
723200 if(Dune::any_true(isComponentOutflow) && !Dune::all_true(isComponentOutflow))
107 DUNE_THROW(Dune::InvalidStateException, "Outflow condition must be set for all components!");
108
109 return boundaryPriVars;
110 }
111 };
112
113 /*!
114 * \ingroup StaggeredDiscretization
115 * \brief Grid volume variables class for staggered models
116 */
117 template<class Traits, bool cachingEnabled>
118 class StaggeredGridVolumeVariables;
119
120 /*!
121 * \ingroup StaggeredDiscretization
122 * \brief Grid volume variables class for staggered models.
123 Specialization in case of storing the volume variables
124 */
125 template<class Traits>
126
0/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1334 class StaggeredGridVolumeVariables<Traits, /*cachingEnabled*/true>
127 {
128 using ThisType = StaggeredGridVolumeVariables<Traits, true>;
129 using PrimaryVariables = typename Traits::VolumeVariables::PrimaryVariables;
130
131 public:
132 //! export the problem type
133 using Problem = typename Traits::Problem;
134
135 //! export the type of the indices
136 using Indices = typename Traits::VolumeVariables::Indices;
137
138 //! export the type of the VolumeVariables
139 using VolumeVariables = typename Traits::VolumeVariables;
140
141 //! make it possible to query if caching is enabled
142 static constexpr bool cachingEnabled = true;
143
144 //! export the type of the local view
145 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
146
147
4/8
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 51 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 51 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 51 times.
✗ Branch 11 not taken.
204 StaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
148
149 //! Update all volume variables
150 template<class GridGeometry, class SolutionVector>
151 5603 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
152 {
153
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5603 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5603 times.
11206 if (sol.size() != gridGeometry.numScv())
154 DUNE_THROW(Dune::InvalidStateException, "The solution vector passed to the GridVolumeVariables has the wrong size.\n"
155 << "Make sure to initialize the gridVariables correctly: \n\n"
156 << "auto ffSol = partial(sol, ffFaceIdx, ffCellCenterIdx); \n"
157 << "ffGridVariables->init(ffSol);\n\n");
158
159 11206 volumeVariables_.resize(gridGeometry.numScv());
160 5603 auto fvGeometry = localView(gridGeometry);
161
1/2
✓ Branch 2 taken 1693175 times.
✗ Branch 3 not taken.
3386350 for (const auto& element : elements(gridGeometry.gridView()))
162 {
163 1687572 fvGeometry.bindElement(element);
164
4/4
✓ Branch 2 taken 1687572 times.
✓ Branch 3 taken 1687572 times.
✓ Branch 4 taken 1687572 times.
✓ Branch 5 taken 1687572 times.
6750288 for (auto&& scv : scvs(fvGeometry))
165 {
166 // construct a privars object from the cell center solution vector
167 3375144 const auto& cellCenterPriVars = sol[scv.dofIndex()];
168 1687572 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
169
170
1/4
✓ Branch 1 taken 1279672 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
4654816 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
171
4/8
✓ Branch 1 taken 1687572 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1687572 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1687572 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 407900 times.
✗ Branch 10 not taken.
5062716 volumeVariables_[scv.dofIndex()].update(elemSol, problem(), element, scv);
172 }
173 }
174 5603 }
175
176 const VolumeVariables& volVars(const std::size_t scvIdx) const
177 12303509434 { return volumeVariables_[scvIdx]; }
178
179 VolumeVariables& volVars(const std::size_t scvIdx)
180 { return volumeVariables_[scvIdx]; }
181
182 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
183 const VolumeVariables& volVars(const SubControlVolume& scv) const
184 { return volumeVariables_[scv.dofIndex()]; }
185
186 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
187 VolumeVariables& volVars(const SubControlVolume& scv)
188 66679674 { return volumeVariables_[scv.dofIndex()]; }
189
190 const Problem& problem() const
191 { return *problemPtr_; }
192
193 //! Returns the primary variables used for the boundary volVars and checks for admissible
194 //! combinations for boundary conditions.
195 template<class... Args>
196 PrimaryVariables getBoundaryPriVars(Args&&... args) const
197 {
198 704968 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
199 }
200
201 private:
202 const Problem* problemPtr_;
203 std::vector<VolumeVariables> volumeVariables_;
204 };
205
206
207 /*!
208 * \ingroup StaggeredDiscretization
209 * \brief Grid volume variables class for staggered models.
210 Specialization in case of not storing the volume variables
211 */
212 template<class Traits>
213 class StaggeredGridVolumeVariables<Traits, /*cachingEnabled*/false>
214 {
215 using ThisType = StaggeredGridVolumeVariables<Traits, false>;
216 using PrimaryVariables = typename Traits::VolumeVariables::PrimaryVariables;
217
218 public:
219 //! export the problem type
220 using Problem = typename Traits::Problem;
221
222 //! export the type of the VolumeVariables
223 using VolumeVariables = typename Traits::VolumeVariables;
224
225 //! make it possible to query if caching is enabled
226 static constexpr bool cachingEnabled = false;
227
228 //! export the type of the local view
229 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
230
231
48/96
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 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.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 1 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 1 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 1 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 1 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 1 times.
✗ Branch 107 not taken.
✓ Branch 109 taken 1 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 1 times.
✗ Branch 113 not taken.
✓ Branch 115 taken 1 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 1 times.
✗ Branch 119 not taken.
✓ Branch 121 taken 1 times.
✗ Branch 122 not taken.
✓ Branch 124 taken 1 times.
✗ Branch 125 not taken.
✓ Branch 127 taken 1 times.
✗ Branch 128 not taken.
✓ Branch 130 taken 1 times.
✗ Branch 131 not taken.
✓ Branch 133 taken 1 times.
✗ Branch 134 not taken.
✓ Branch 136 taken 1 times.
✗ Branch 137 not taken.
✓ Branch 139 taken 1 times.
✗ Branch 140 not taken.
✓ Branch 142 taken 1 times.
✗ Branch 143 not taken.
48 StaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
232
233 template<class GridGeometry, class SolutionVector>
234 48 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
235 {
236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
48 if (sol.size() != gridGeometry.numScv())
237 DUNE_THROW(Dune::InvalidStateException, "The solution vector passed to the GridVolumeVariables has the wrong size.\n"
238 << "Make sure to initialize the gridVariables correctly: \n\n"
239 << "auto ffSol = partial(sol, ffFaceIdx, ffCellCenterIdx); \n"
240 << "ffGridVariables->init(ffSol);\n\n");
241 48 }
242
243 const Problem& problem() const
244 { return *problemPtr_;}
245
246 //! Returns the primary variables used for the boundary volVars and checks for admissible
247 //! combinations for boundary conditions.
248 template<class... Args>
249 PrimaryVariables getBoundaryPriVars(Args&&... args) const
250 {
251 480 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
252 }
253
254 private:
255
256 const Problem* problemPtr_;
257 };
258
259 } // end namespace Dumux
260
261 #endif
262