GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porousmediumflow/2p/volumevariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 59 62 95.2%
Functions: 54 66 81.8%
Branches: 92 149 61.7%

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 TwoPModel
10 * \brief Contains the quantities which are constant within a
11 * finite volume in the two-phase model.
12 */
13
14 #ifndef DUMUX_2P_VOLUME_VARIABLES_HH
15 #define DUMUX_2P_VOLUME_VARIABLES_HH
16
17 #include <dumux/porousmediumflow/volumevariables.hh>
18 #include <dumux/porousmediumflow/nonisothermal/volumevariables.hh>
19 #include <dumux/material/solidstates/updatesolidvolumefractions.hh>
20 #include <dumux/porousmediumflow/2p/formulation.hh>
21
22 namespace Dumux {
23
24 /*!
25 * \ingroup TwoPModel
26 * \brief Contains the quantities which are are constant within a
27 * finite volume in the two-phase model.
28 */
29 template <class Traits>
30
22/40
✗ Branch 0 not taken.
✓ Branch 1 taken 526104 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 64312 times.
✓ Branch 4 taken 461792 times.
✓ Branch 5 taken 64312 times.
✓ Branch 7 taken 461792 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 81408 times.
✓ Branch 10 taken 33895 times.
✓ Branch 11 taken 81408 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 115303 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 33895 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 127125 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 127125 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 127125 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3984 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 3984 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 3984 times.
✓ Branch 36 taken 77648 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 77648 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 77648 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 608634 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 608634 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 608634 times.
✗ Branch 50 not taken.
214530390 class TwoPVolumeVariables
31 : public PorousMediumFlowVolumeVariables<Traits>
32 , public EnergyVolumeVariables<Traits, TwoPVolumeVariables<Traits> >
33 {
34 using ParentType = PorousMediumFlowVolumeVariables<Traits>;
35 using EnergyVolVars = EnergyVolumeVariables<Traits, TwoPVolumeVariables<Traits> >;
36 using PermeabilityType = typename Traits::PermeabilityType;
37 using ModelTraits = typename Traits::ModelTraits;
38 using Idx = typename ModelTraits::Indices;
39 using Scalar = typename Traits::PrimaryVariables::value_type;
40 using FS = typename Traits::FluidSystem;
41 static constexpr int numFluidComps = ParentType::numFluidComponents();
42 enum
43 {
44 pressureIdx = Idx::pressureIdx,
45 saturationIdx = Idx::saturationIdx,
46
47 phase0Idx = FS::phase0Idx,
48 phase1Idx = FS::phase1Idx
49 };
50
51 static constexpr auto formulation = ModelTraits::priVarFormulation();
52
53 public:
54 //! Export type of fluid system
55 using FluidSystem = typename Traits::FluidSystem;
56 //! Export type of fluid state
57 using FluidState = typename Traits::FluidState;
58 //! Export the indices
59 using Indices = typename ModelTraits::Indices;
60 //! Export type of solid state
61 using SolidState = typename Traits::SolidState;
62 //! Export type of solid system
63 using SolidSystem = typename Traits::SolidSystem;
64
65 /*!
66 * \brief Updates all quantities for a given control volume.
67 *
68 * \param elemSol A vector containing all primary variables connected to the element
69 * \param problem The object specifying the problem which ought to
70 * be simulated
71 * \param element An element which contains part of the control volume
72 * \param scv The sub control volume
73 */
74 template<class ElemSol, class Problem, class Element, class Scv>
75 75029330 void update(const ElemSol &elemSol,
76 const Problem &problem,
77 const Element &element,
78 const Scv& scv)
79 {
80 75029330 ParentType::update(elemSol, problem, element, scv);
81
82 75029330 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
83
84
2/2
✓ Branch 0 taken 2706244 times.
✓ Branch 1 taken 32313244 times.
75029330 const auto& spatialParams = problem.spatialParams();
85
2/2
✓ Branch 0 taken 2706244 times.
✓ Branch 1 taken 32313244 times.
75029330 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
86
87 75029330 const int wPhaseIdx = fluidState_.wettingPhase();
88 75029330 const int nPhaseIdx = 1 - wPhaseIdx;
89
90 75029330 mobility_[wPhaseIdx] =
91 fluidMatrixInteraction.krw(fluidState_.saturation(wPhaseIdx))
92
3/6
✓ Branch 1 taken 941464 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 941464 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 941464 times.
✗ Branch 8 not taken.
151548398 / fluidState_.viscosity(wPhaseIdx);
93
94 75029330 mobility_[nPhaseIdx] =
95 fluidMatrixInteraction.krn(fluidState_.saturation(wPhaseIdx))
96
4/5
✓ Branch 1 taken 941464 times.
✓ Branch 2 taken 32158596 times.
✓ Branch 3 taken 2860892 times.
✓ Branch 4 taken 941464 times.
✗ Branch 5 not taken.
150058660 / fluidState_.viscosity(nPhaseIdx);
97
98 // porosity calculation over inert volumefraction
99
2/3
✓ Branch 0 taken 32158596 times.
✓ Branch 1 taken 3802356 times.
✗ Branch 2 not taken.
95278832 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
100
1/2
✓ Branch 1 taken 941464 times.
✗ Branch 2 not taken.
75029330 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
101
2/2
✓ Branch 0 taken 32158596 times.
✓ Branch 1 taken 2860892 times.
95278832 permeability_ = spatialParams.permeability(element, scv, elemSol);
102 75029330 EnergyVolVars::updateEffectiveThermalConductivity();
103 75029330 }
104
105 /*!
106 * \brief Sets complete fluid state.
107 *
108 * \param elemSol A vector containing all primary variables connected to the element
109 * \param problem The object specifying the problem which ought to be simulated
110 * \param element An element which contains part of the control volume
111 * \param scv The sub-control volume
112 * \param fluidState A container with the current (physical) state of the fluid
113 * \param solidState A container with the current (physical) state of the solid
114 *
115 * Set temperature, saturations, capillary pressures, viscosities, densities and enthalpies.
116 */
117 template<class ElemSol, class Problem, class Element, class Scv>
118 75029330 void completeFluidState(const ElemSol& elemSol,
119 const Problem& problem,
120 const Element& element,
121 const Scv& scv,
122 FluidState& fluidState,
123 SolidState& solidState)
124 {
125 75029330 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
126
127
2/2
✓ Branch 0 taken 2706244 times.
✓ Branch 1 taken 32313244 times.
75029330 const auto& spatialParams = problem.spatialParams();
128
2/2
✓ Branch 0 taken 2706244 times.
✓ Branch 1 taken 32313244 times.
76519068 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
129
130
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
72731068 const auto& priVars = elemSol[scv.localDofIndex()];
131
132
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
75029330 const auto wPhaseIdx = spatialParams.template wettingPhase<FluidSystem>(element, scv, elemSol);
133
2/3
✓ Branch 0 taken 90794 times.
✓ Branch 1 taken 14961987 times.
✗ Branch 2 not taken.
75029330 fluidState.setWettingPhase(wPhaseIdx);
134 if (formulation == TwoPFormulation::p0s1)
135 {
136
5/6
✓ Branch 0 taken 90794 times.
✓ Branch 1 taken 14961987 times.
✓ Branch 2 taken 90794 times.
✓ Branch 3 taken 13472249 times.
✓ Branch 4 taken 1489738 times.
✗ Branch 5 not taken.
149433940 fluidState.setPressure(phase0Idx, priVars[pressureIdx]);
137
2/2
✓ Branch 0 taken 90794 times.
✓ Branch 1 taken 13472249 times.
74716970 if (fluidState.wettingPhase() == phase1Idx)
138 {
139 181588 fluidState.setSaturation(phase1Idx, priVars[saturationIdx]);
140 181588 fluidState.setSaturation(phase0Idx, 1 - priVars[saturationIdx]);
141 181588 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
142 181588 fluidState.setPressure(phase1Idx, priVars[pressureIdx] - pc_);
143 }
144 else
145 {
146 112374280 const auto Sn = Traits::SaturationReconstruction::reconstructSn(spatialParams, element,
147
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
112374280 scv, elemSol, priVars[saturationIdx]);
148
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
74626176 fluidState.setSaturation(phase1Idx, Sn);
149
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
74626176 fluidState.setSaturation(phase0Idx, 1 - Sn);
150
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
88098425 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
151 149252352 fluidState.setPressure(phase1Idx, priVars[pressureIdx] + pc_);
152 }
153 }
154 else if (formulation == TwoPFormulation::p1s0)
155 {
156 624720 fluidState.setPressure(phase1Idx, priVars[pressureIdx]);
157 if (wPhaseIdx == phase1Idx)
158 {
159 const auto Sn = Traits::SaturationReconstruction::reconstructSn(spatialParams, element,
160 scv, elemSol, priVars[saturationIdx]);
161 fluidState.setSaturation(phase0Idx, Sn);
162 fluidState.setSaturation(phase1Idx, 1 - Sn);
163 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
164 fluidState.setPressure(phase0Idx, priVars[pressureIdx] + pc_);
165 }
166 else
167 {
168 624720 fluidState.setSaturation(phase0Idx, priVars[saturationIdx]);
169 624720 fluidState.setSaturation(phase1Idx, 1 - priVars[saturationIdx]);
170 312360 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
171 624720 fluidState.setPressure(phase0Idx, priVars[pressureIdx] - pc_);
172 }
173 }
174
175 typename FluidSystem::ParameterCache paramCache;
176 61466287 paramCache.updateAll(fluidState);
177
178
2/2
✓ Branch 0 taken 150058660 times.
✓ Branch 1 taken 75029330 times.
225087990 for (int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx) {
179 // compute and set the viscosity
180
2/2
✓ Branch 0 taken 65467582 times.
✓ Branch 1 taken 65467582 times.
150058660 Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
181
2/2
✓ Branch 0 taken 65467582 times.
✓ Branch 1 taken 65467582 times.
150058660 fluidState.setViscosity(phaseIdx, mu);
182
183 // compute and set the density
184
2/2
✓ Branch 0 taken 65467582 times.
✓ Branch 1 taken 65467582 times.
150058660 Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
185
1/2
✓ Branch 1 taken 1882928 times.
✗ Branch 2 not taken.
150058660 fluidState.setDensity(phaseIdx, rho);
186
187 // compute and set the enthalpy
188
1/2
✓ Branch 1 taken 1882928 times.
✗ Branch 2 not taken.
150058660 Scalar h = EnergyVolVars::enthalpy(fluidState, paramCache, phaseIdx);
189 300117320 fluidState.setEnthalpy(phaseIdx, h);
190 }
191 75029330 }
192
193 /*!
194 * \brief Returns the phase state for the control volume.
195 */
196 const FluidState &fluidState() const
197
3/6
✓ Branch 0 taken 506352 times.
✓ Branch 1 taken 506352 times.
✓ Branch 2 taken 1012704 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
24652224 { return fluidState_; }
198
199 /*!
200 * \brief Returns the phase state for the control volume.
201 */
202 const SolidState &solidState() const
203 2172696 { return solidState_; }
204
205 /*!
206 * \brief Returns the saturation of a given phase within
207 * the control volume in \f$[-]\f$.
208 *
209 * \param phaseIdx The phase index
210 */
211 Scalar saturation(int phaseIdx) const
212
4/16
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 243 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 243 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 243 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 243 times.
948255736 { return fluidState_.saturation(phaseIdx); }
213
214 /*!
215 * \brief Returns the mass density of a given phase within the
216 * control volume in \f$[kg/m^3]\f$.
217 *
218 * \param phaseIdx The phase index
219 */
220 Scalar density(int phaseIdx) const
221
10/10
✓ Branch 0 taken 84912096 times.
✓ Branch 1 taken 2424540 times.
✓ Branch 2 taken 84912096 times.
✓ Branch 3 taken 2408100 times.
✓ Branch 4 taken 16440 times.
✓ Branch 5 taken 12060 times.
✓ Branch 6 taken 6602124 times.
✓ Branch 7 taken 51564 times.
✓ Branch 8 taken 6602124 times.
✓ Branch 9 taken 39504 times.
4343922844 { return fluidState_.density(phaseIdx); }
222
223 /*!
224 * \brief Returns the effective pressure of a given phase within
225 * the control volume in \f$[kg/(m*s^2)=N/m^2=Pa]\f$.
226 *
227 * \param phaseIdx The phase index
228 */
229 Scalar pressure(int phaseIdx) const
230
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 1645221 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1645221 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1606195 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1606195 times.
2168093550 { return fluidState_.pressure(phaseIdx); }
231
232 /*!
233 * \brief Returns the capillary pressure within the control volume
234 * in \f$[kg/(m*s^2)=N/m^2=Pa]\f$.
235 */
236 Scalar capillaryPressure() const
237 { return pc_; }
238
239 /*!
240 * \brief Returns temperature inside the sub-control volume
241 * in \f$[K]\f$.
242 *
243 * Note that we assume thermodynamic equilibrium, i.e. the
244 * temperature of the rock matrix and of all fluid phases are
245 * identical.
246 */
247 Scalar temperature() const
248
2/4
✓ Branch 0 taken 935168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 935168 times.
✗ Branch 3 not taken.
16128896 { return fluidState_.temperature(/*phaseIdx=*/0); }
249
250 /*!
251 * \brief Returns the dynamic viscosity of the fluid within the
252 * control volume in \f$\mathrm{[Pa s]}\f$.
253 *
254 * \param phaseIdx The phase index
255 */
256 Scalar viscosity(int phaseIdx) const
257 12 { return fluidState_.viscosity(phaseIdx); }
258
259 /*!
260 * \brief Returns the effective mobility of a given phase within
261 * the control volume in \f$[s*m/kg]\f$.
262 *
263 * \param phaseIdx The phase index
264 */
265 Scalar mobility(int phaseIdx) const
266 1185511044 { return mobility_[phaseIdx]; }
267
268 /*!
269 * \brief Returns the average porosity within the control volume in \f$[-]\f$.
270 */
271 Scalar porosity() const
272
2/4
✓ Branch 1 taken 16440 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16440 times.
✗ Branch 5 not taken.
953977478 { return solidState_.porosity(); }
273
274 /*!
275 * \brief Returns the permeability within the control volume in \f$[m^2]\f$.
276 */
277 const PermeabilityType& permeability() const
278 { return permeability_; }
279
280 /*!
281 * \brief Returns the wetting phase index
282 */
283 int wettingPhase() const
284 { return fluidState_.wettingPhase(); }
285
286 protected:
287 FluidState fluidState_;
288 SolidState solidState_;
289
290 private:
291 Scalar pc_;
292 Scalar porosity_;
293 PermeabilityType permeability_;
294 Scalar mobility_[ModelTraits::numFluidPhases()];
295 };
296
297 } // end namespace Dumux
298
299 #endif
300