GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/fluidstates/pseudo1p2c.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 18 38 47.4%
Functions: 0 13 0.0%
Branches: 19 64 29.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 FluidStates
10 * \brief Calculates phase state for a single phase but two-component state.
11 */
12 #ifndef DUMUX_PSEUDO1P2C_FLUID_STATE_HH
13 #define DUMUX_PSEUDO1P2C_FLUID_STATE_HH
14
15 #include <cassert>
16
17 namespace Dumux {
18
19 /*!
20 * \ingroup FluidStates
21 * \brief Container for compositional variables in a 1p2c situation
22 *
23 * This class holds variables for single-phase situations in a 2p2c context.
24 * It is used in case of a multiphysics approach. For the non-present phase,
25 * no information is stored but 0-values are returned to allow for general output
26 * methods.
27 * The "flash" calculation routines are in the sequential flash constrain solver, see
28 * CompositionalFlash .
29 */
30 template <class ScalarType, class FluidSystem>
31 class PseudoOnePTwoCFluidState
32 {
33
34 public:
35 static constexpr int numPhases = FluidSystem::numPhases;
36 static constexpr int numComponents = FluidSystem::numComponents;
37
38 //! export the scalar type
39 using Scalar = ScalarType;
40
41 enum {
42 phase0Idx = FluidSystem::phase0Idx,
43 phase1Idx = FluidSystem::phase1Idx,
44
45 comp0Idx = FluidSystem::comp0Idx,
46 comp1Idx = FluidSystem::comp1Idx
47 };
48
49 /*! \name Access functions */
50 //@{
51 /*!
52 * \brief Returns the saturation \f$S_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[-]}\f$.
53 *
54 * The saturation is defined as the pore space occupied by the fluid divided by the total pore space:
55 * \f[S_\alpha := \frac{\phi \mathcal{V}_\alpha}{\phi \mathcal{V}}\f]
56 * This is set either to 1 or 0 depending on the phase presence.
57 * \param phaseIdx the index of the phase
58 */
59 Scalar saturation(int phaseIdx) const
60
2/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 { return phaseIdx == presentPhaseIdx_ ? 1.0 : 0.0; }
61
62 //! \brief Returns the index of the phase that is present in that cell.
63 int presentPhaseIdx() const
64 { return presentPhaseIdx_; }
65
66 /*!
67 * \brief Return the partial pressure of a component in the gas phase.
68 * \todo is this needed?
69 *
70 * For an ideal gas, this means \f$ R*T*c \f$.
71 * Unit: \f$\mathrm{[Pa] = [N/m^2]}\f$
72 *
73 * \param compIdx the index of the component
74 */
75 Scalar partialPressure(int compIdx) const
76 { return partialPressure(phase1Idx, compIdx); }
77
78 /*!
79 * \brief The partial pressure of a component in a phase \f$\mathrm{[Pa]}\f$
80 * \todo is this needed?
81 */
82 Scalar partialPressure(int phaseIdx, int compIdx) const
83 {
84 assert(FluidSystem::isGas(phaseIdx));
85 return pressure(phaseIdx)*moleFraction(phaseIdx, compIdx);
86 }
87
88 /*!
89 * \brief The pressure \f$p_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[Pa]}\f$
90 */
91 Scalar pressure(int phaseIdx) const
92
7/10
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
16 { return pressure_[phaseIdx]; }
93
94 /*!
95 * \brief Set the density of a phase \f$\mathrm{[kg / m^3]}\f$
96 */
97 Scalar density(int phaseIdx) const
98 { return phaseIdx == presentPhaseIdx_ ? density_ : 0.0; }
99
100 /*!
101 * @copydoc CompositionalFluidState::molarDensity()
102 */
103 Scalar molarDensity(int phaseIdx) const
104 { return phaseIdx == presentPhaseIdx_ ? molarDensity_ : 0.0; }
105
106 /*!
107 * @copydoc CompositionalFluidState::massFraction()
108 */
109 Scalar massFraction(int phaseIdx, int compIdx) const
110 {
111 if (phaseIdx != presentPhaseIdx_)
112 return phaseIdx == compIdx ? 1.0 : 0.0;
113
114
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 return compIdx == phase0Idx ? massFractionWater_ : 1.0 - massFractionWater_;
115 }
116
117 /*!
118 * \brief Returns the molar fraction \f$x^\kappa_\alpha\f$ of the component \f$\kappa\f$ in fluid phase \f$\alpha\f$ in \f$\mathrm{[-]}\f$.
119 *
120 * This is either set to 1 or 0 depending on the phase presence for the
121 * nonwetting phase in general.
122 * It is set to the mole fraction of water or 1-moleFractionWater
123 * if the considered component is the main component of the wetting phase.
124 * \param phaseIdx the index of the phase
125 * \param compIdx the index of the component
126 */
127 Scalar moleFraction(int phaseIdx, int compIdx) const
128 {
129
4/10
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
8 if (phaseIdx != presentPhaseIdx_)
130
1/10
✗ 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 taken 1 times.
✗ Branch 9 not taken.
1 return phaseIdx == compIdx ? 1.0 : 0.0;
131
132
2/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 return compIdx == phase0Idx ? moleFractionWater_ : 1.0 - moleFractionWater_;
133 }
134
135 /*!
136 * \brief The dynamic viscosity \f$\mu_\alpha\f$ of fluid phase \f$\alpha\f$ in \f$\mathrm{[Pa s]}\f$
137 */
138 Scalar viscosity(int phaseIdx) const
139 {
140 assert(phaseIdx == presentPhaseIdx_);
141 return viscosity_;
142 }
143
144 /*!
145 * \brief The average molar mass \f$\overline M_\alpha\f$ of phase \f$\alpha\f$ in \f$\mathrm{[kg/mol]}\f$
146 *
147 * The average molar mass is the mean mass of a mole of the
148 * fluid at current composition. It is defined as the sum of the
149 * component's molar masses weighted by the current mole fraction:
150 * \f[\mathrm{ \overline M_\alpha = \sum_\kappa M^\kappa x_\alpha^\kappa}\f]
151 */
152 Scalar averageMolarMass(int phaseIdx) const
153 { return averageMolarMass_; }
154
155 /*!
156 * \brief The specific enthalpy \f$h_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[J/kg]}\f$
157 */
158 Scalar enthalpy(int phaseIdx) const
159 { return phaseIdx == presentPhaseIdx_ ? enthalpy_ : 0.0; }
160
161 /*!
162 * \brief The specific internal energy \f$u_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[J/kg]}\f$
163 *
164 * The specific internal energy is defined by the relation:
165 *
166 * \f[u_\alpha = h_\alpha - \frac{p_\alpha}{\rho_\alpha}\f]
167 */
168 Scalar internalEnergy(int phaseIdx) const
169 { return phaseIdx == presentPhaseIdx_ ? enthalpy_ - pressure(phaseIdx)/density(phaseIdx) : 0.0; }
170
171 /*!
172 * \brief Returns the temperature of the fluids \f$\mathrm{[K]}\f$.
173 *
174 * Note that we assume thermodynamic equilibrium, so all fluids
175 * and the rock matrix exhibit the same temperature.
176 */
177 Scalar temperature(int phaseIdx) const
178 { return temperature_; }
179 //@}
180
181 /*!
182 * \name Functions to set Data
183 */
184 //@{
185 /*!
186 * \brief Sets the viscosity of a phase \f$\mathrm{[Pa*s]}\f$.
187 *
188 * \param phaseIdx the index of the phase
189 * @param value Value to be stored
190 */
191 void setViscosity(int phaseIdx, Scalar value)
192 {
193
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
2 assert(phaseIdx == presentPhaseIdx_);
194 2 viscosity_ = value;
195 }
196
197 /*!
198 * \brief Sets the mass fraction of a component in a phase.
199 *
200 * \param phaseIdx the index of the phase
201 * \param compIdx the index of the component
202 * @param value Value to be stored
203 */
204 void setMassFraction(int phaseIdx, int compIdx, Scalar value)
205
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 { massFractionWater_ = compIdx == comp0Idx ? value : 1.0 - value; }
206
207 /*!
208 * \brief Sets the molar fraction of a component in a fluid phase.
209 *
210 * \param phaseIdx the index of the phase
211 * \param compIdx the index of the component
212 * @param value Value to be stored
213 */
214 void setMoleFraction(int phaseIdx, int compIdx, Scalar value)
215
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
4 { moleFractionWater_ = compIdx == comp0Idx ? value : 1.0 - value; }
216
217 /*!
218 * \brief Sets the density of a phase \f$\mathrm{[kg/m^3]}\f$.
219 *
220 * \param phaseIdx the index of the phase
221 * @param value Value to be stored
222 */
223 void setDensity(int phaseIdx, Scalar value)
224 {
225
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
2 assert(phaseIdx == presentPhaseIdx_);
226 2 density_ = value;
227 }
228
229 /*!
230 * \brief Set the molar density of a phase \f$\mathrm{[mol / m^3]}\f$
231 *
232 * \param phaseIdx the index of the phase
233 * @param value Value to be stored
234 */
235 void setMolarDensity(int phaseIdx, Scalar value)
236 {
237
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
2 assert(phaseIdx == presentPhaseIdx_);
238 2 molarDensity_ = value;
239 }
240
241 /*!
242 * \brief Sets the phase Index that is present in this fluidState.
243 * @param phaseIdx the index of the phase
244 */
245 void setPresentPhaseIdx(int phaseIdx)
246 2 { presentPhaseIdx_ = phaseIdx; }
247
248 /*!
249 * \brief Sets the temperature
250 *
251 * @param value Value to be stored
252 */
253 void setTemperature(Scalar value)
254 3 { temperature_ = value; }
255
256 /*!
257 * \brief Set the average molar mass of a fluid phase [kg/mol]
258 *
259 * The average molar mass is the mean mass of a mole of the
260 * fluid at current composition. It is defined as the sum of the
261 * component's molar masses weighted by the current mole fraction:
262 * \f[ \bar M_\alpha = \sum_\kappa M^\kappa x_\alpha^\kappa \f]
263 */
264 void setAverageMolarMass(int phaseIdx, Scalar value)
265 2 { averageMolarMass_ = value; }
266
267 /*!
268 * \brief Sets the phase pressure \f$\mathrm{[Pa]}\f$.
269 */
270 void setPressure(int phaseIdx, Scalar value)
271 6 { pressure_[phaseIdx] = value; }
272
273 /*!
274 * \brief Sets phase enthalpy
275 *
276 * \param phaseIdx the index of the phase
277 * @param value Value to be stored
278 */
279 void setEnthalpy(int phaseIdx, Scalar value)
280 {
281 assert(phaseIdx == presentPhaseIdx_);
282 enthalpy_ = value;
283 }
284 //@}
285
286 protected:
287 Scalar pressure_[numPhases] = {};
288 Scalar massConcentration_[numComponents] = {};
289 Scalar averageMolarMass_ = 0.0;
290 Scalar massFractionWater_ = 0.0;
291 Scalar moleFractionWater_ = 0.0;
292 Scalar density_ = 0.0;
293 Scalar molarDensity_ = 0.0;
294 Scalar viscosity_ = 0.0;
295 Scalar enthalpy_ = 0.0;
296 Scalar temperature_ = 0.0;
297 int presentPhaseIdx_ = 0;
298 };
299
300 } // end namespace Dumux
301
302 #endif
303