GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/porousmediumflow/2p/volumevariables.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 70 70 100.0%
Functions: 54 54 100.0%
Branches: 62 93 66.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-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 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
9/17
✓ Branch 1 taken 547194 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 125455 times.
✓ Branch 5 taken 81408 times.
✓ Branch 7 taken 127125 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 3984 times.
✓ Branch 12 taken 2048 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 77648 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 608634 times.
✗ Branch 18 not taken.
✗ Branch 0 not taken.
✓ Branch 3 taken 6784 times.
✗ Branch 6 not taken.
66140528 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 70453090 void update(const ElemSol &elemSol,
76 const Problem &problem,
77 const Element &element,
78 const Scv& scv)
79 {
80 70453090 ParentType::update(elemSol, problem, element, scv);
81
82 70453090 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
83
84
2/2
✓ Branch 0 taken 2410244 times.
✓ Branch 1 taken 28033084 times.
70453090 const auto& spatialParams = problem.spatialParams();
85
2/2
✓ Branch 0 taken 538292 times.
✓ Branch 1 taken 692940 times.
70453090 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
86
87
1/2
✓ Branch 1 taken 941464 times.
✗ Branch 2 not taken.
70453090 const int wPhaseIdx = fluidState_.wettingPhase();
88 70453090 const int nPhaseIdx = 1 - wPhaseIdx;
89
90 70453090 mobility_[wPhaseIdx] =
91
1/2
✓ Branch 1 taken 941464 times.
✗ Branch 2 not taken.
70453090 fluidMatrixInteraction.krw(fluidState_.saturation(wPhaseIdx))
92
1/2
✓ Branch 1 taken 941464 times.
✗ Branch 2 not taken.
70453090 / fluidState_.viscosity(wPhaseIdx);
93
94 70453090 mobility_[nPhaseIdx] =
95
1/2
✓ Branch 1 taken 941464 times.
✗ Branch 2 not taken.
70453090 fluidMatrixInteraction.krn(fluidState_.saturation(wPhaseIdx))
96
2/2
✓ Branch 0 taken 27878436 times.
✓ Branch 1 taken 2564892 times.
70453090 / fluidState_.viscosity(nPhaseIdx);
97
98 // porosity calculation over inert volumefraction
99
2/3
✓ Branch 1 taken 3506356 times.
✗ Branch 2 not taken.
✓ Branch 0 taken 27878436 times.
70453090 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
100
2/3
✓ Branch 1 taken 2813416 times.
✗ Branch 2 not taken.
✓ Branch 0 taken 27340144 times.
31384792 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
101
2/2
✓ Branch 0 taken 538292 times.
✓ Branch 1 taken 692940 times.
70453090 permeability_ = spatialParams.permeability(element, scv, elemSol);
102 2720970 EnergyVolVars::updateEffectiveThermalConductivity();
103 70453090 }
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 70453090 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 70453090 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
126
127
2/2
✓ Branch 0 taken 2410244 times.
✓ Branch 1 taken 28033084 times.
70453090 const auto& spatialParams = problem.spatialParams();
128
2/2
✓ Branch 0 taken 538292 times.
✓ Branch 1 taken 692940 times.
71203426 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
129
130
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
68154828 const auto& priVars = elemSol[scv.localDofIndex()];
131
132
2/3
✓ Branch 1 taken 14961907 times.
✗ Branch 2 not taken.
✓ Branch 0 taken 90794 times.
81717791 const auto wPhaseIdx = spatialParams.template wettingPhase<FluidSystem>(element, scv, elemSol);
133
2/3
✓ Branch 1 taken 14961907 times.
✗ Branch 2 not taken.
✓ Branch 0 taken 90794 times.
70453090 fluidState.setWettingPhase(wPhaseIdx);
134 if (formulation == TwoPFormulation::p0s1)
135 {
136
2/3
✓ Branch 1 taken 14961907 times.
✗ Branch 2 not taken.
✓ Branch 0 taken 90794 times.
70140730 fluidState.setPressure(phase0Idx, priVars[pressureIdx]);
137
2/2
✓ Branch 0 taken 90794 times.
✓ Branch 1 taken 13472169 times.
70140730 if (fluidState.wettingPhase() == phase1Idx)
138 {
139 90794 fluidState.setSaturation(phase1Idx, priVars[saturationIdx]);
140 90794 fluidState.setSaturation(phase0Idx, 1 - priVars[saturationIdx]);
141 90794 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
142 90794 fluidState.setPressure(phase1Idx, priVars[pressureIdx] - pc_);
143 }
144 else
145 {
146 70049936 const auto Sn = Traits::SaturationReconstruction::reconstructSn(spatialParams, element,
147
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
70049936 scv, elemSol, priVars[saturationIdx]);
148 70049936 fluidState.setSaturation(phase1Idx, Sn);
149 70049936 fluidState.setSaturation(phase0Idx, 1 - Sn);
150
1/2
✓ Branch 1 taken 1489738 times.
✗ Branch 2 not taken.
70049936 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
151 70049936 fluidState.setPressure(phase1Idx, priVars[pressureIdx] + pc_);
152 }
153 }
154 else if (formulation == TwoPFormulation::p1s0)
155 {
156 312360 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 312360 fluidState.setSaturation(phase0Idx, priVars[saturationIdx]);
169 312360 fluidState.setSaturation(phase1Idx, 1 - priVars[saturationIdx]);
170 312360 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
171 312360 fluidState.setPressure(phase0Idx, priVars[pressureIdx] - pc_);
172 }
173 }
174
175 typename FluidSystem::ParameterCache paramCache;
176 paramCache.updateAll(fluidState);
177
178
2/2
✓ Branch 0 taken 140906180 times.
✓ Branch 1 taken 70453090 times.
211359270 for (int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx) {
179 // compute and set the viscosity
180
2/2
✓ Branch 0 taken 60891342 times.
✓ Branch 1 taken 60891342 times.
140906180 Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
181
2/2
✓ Branch 0 taken 60891342 times.
✓ Branch 1 taken 60891342 times.
140906180 fluidState.setViscosity(phaseIdx, mu);
182
183 // compute and set the density
184
1/2
✓ Branch 1 taken 1882928 times.
✗ Branch 2 not taken.
140906180 Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
185
1/2
✓ Branch 1 taken 1882928 times.
✗ Branch 2 not taken.
140906180 fluidState.setDensity(phaseIdx, rho);
186
187 // compute and set the enthalpy
188 140906180 Scalar h = EnergyVolVars::enthalpy(fluidState, paramCache, phaseIdx);
189 140906180 fluidState.setEnthalpy(phaseIdx, h);
190 }
191 70453090 }
192
193 /*!
194 * \brief Returns the phase state for the control volume.
195 */
196 1231232 const FluidState &fluidState() const
197
4/4
✓ Branch 0 taken 506352 times.
✓ Branch 1 taken 506352 times.
✓ Branch 2 taken 506352 times.
✓ Branch 3 taken 506352 times.
8452312 { 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 449684112 Scalar saturation(int phaseIdx) const
212
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 243 times.
437140692 { 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 1484979013 Scalar density(int phaseIdx) const
221
4/5
✓ Branch 0 taken 84912096 times.
✓ Branch 1 taken 2424540 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6614184 times.
✓ Branch 4 taken 39504 times.
1472434969 { 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 988298176 Scalar pressure(int phaseIdx) const
230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1645221 times.
985239940 { 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 2590183 Scalar capillaryPressure() const
237
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 251594 times.
✓ Branch 3 taken 687678 times.
2527711 { 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 11873676 Scalar temperature() const
248
1/2
✓ Branch 0 taken 935168 times.
✗ Branch 1 not taken.
7051744 { 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 6 Scalar viscosity(int phaseIdx) const
257 6 { 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 582854063 Scalar mobility(int phaseIdx) const
266 579795827 { return mobility_[phaseIdx]; }
267
268 /*!
269 * \brief Returns the average porosity within the control volume in \f$[-]\f$.
270 */
271 451782251 Scalar porosity() const
272
1/2
✓ Branch 1 taken 16440 times.
✗ Branch 2 not taken.
434535619 { 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