GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/fluidstates/isothermalimmiscible.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 13 22 59.1%
Functions: 2 7 28.6%
Branches: 15 42 35.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 Represents all relevant thermodynamic quantities of a isothermal immiscible
11 * multi-phase fluid system
12 */
13 #ifndef DUMUX_ISOIMMISCIBLE_FLUID_STATE_HH
14 #define DUMUX_ISOIMMISCIBLE_FLUID_STATE_HH
15
16 #include <limits>
17 #include <type_traits>
18 #include <dune/common/exceptions.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup FluidStates
24 * \brief Represents all relevant thermodynamic quantities of a
25 * multi-phase fluid system assuming immiscibility and
26 * thermodynamic equilibrium.
27 */
28 template <class ScalarType, class FluidSystem>
29 class IsothermalImmiscibleFluidState
30 {
31 public:
32 static constexpr int numPhases = FluidSystem::numPhases;
33 static constexpr int numComponents = FluidSystem::numComponents;
34
35 //! export the scalar type
36 using Scalar = ScalarType;
37
38 //! default constructor
39 IsothermalImmiscibleFluidState() = default;
40
41 //! copy constructor from arbitrary fluid state
42 template <class FluidState, typename std::enable_if_t<!std::is_same<FluidState, IsothermalImmiscibleFluidState>::value, int> = 0>
43 IsothermalImmiscibleFluidState(const FluidState &fs)
44 { assign(fs); }
45
46 // copy and move constructor / assignment operator
47 IsothermalImmiscibleFluidState(const IsothermalImmiscibleFluidState &fs) = default;
48 IsothermalImmiscibleFluidState(IsothermalImmiscibleFluidState &&fs) = default;
49 IsothermalImmiscibleFluidState& operator=(const IsothermalImmiscibleFluidState &fs) = default;
50 IsothermalImmiscibleFluidState& operator=(IsothermalImmiscibleFluidState &&fs) = default;
51
52 /*****************************************************
53 * Generic access to fluid properties
54 *****************************************************/
55
56 /*!
57 * \brief Returns the index of the most wetting phase in the
58 * fluid-solid configuration (for porous medium systems).
59 */
60 int wettingPhase() const { return wPhaseIdx_; }
61
62 /*!
63 * \brief Returns the saturation \f$S_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[-]}\f$.
64 *
65 * The saturation is defined as the pore space occupied by the fluid divided by the total pore space:
66 * \f[S_\alpha := \frac{\phi \mathcal{V}_\alpha}{\phi \mathcal{V}}\f]
67 *
68 * \param phaseIdx the index of the phase
69 */
70 Scalar saturation(int phaseIdx) const
71 1 { return saturation_[phaseIdx]; }
72
73 /*!
74 * \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$.
75 *
76 * The molar fraction \f$x^\kappa_\alpha\f$ is defined as the ratio of the number of molecules
77 * of component \f$\kappa\f$ and the total number of molecules of the phase \f$\alpha\f$.
78 * They are set either 1 or 0 in a phase since this is an immiscible fluidstate.
79 * \param phaseIdx the index of the phase
80 * \param compIdx the index of the component
81 */
82 Scalar moleFraction(int phaseIdx, int compIdx) const
83 { return (phaseIdx == compIdx) ? 1.0 : 0.0; }
84
85 /*!
86 * \brief Returns the mass fraction \f$X^\kappa_\alpha\f$ of component \f$\kappa\f$ in fluid phase \f$\alpha\f$ in \f$\mathrm{[-]}\f$.
87 *
88 * They are set either 1 or 0 in a phase since this is an immiscible fluidstate.
89 *
90 * \param phaseIdx the index of the phase
91 * \param compIdx the index of the component
92 */
93 Scalar massFraction(int phaseIdx, int compIdx) const
94 { return (phaseIdx == compIdx) ? 1.0 : 0.0; }
95
96 /*!
97 * \brief The average molar mass \f$\overline M_\alpha\f$ of phase \f$\alpha\f$ in \f$\mathrm{[kg/mol]}\f$
98 *
99 * The average molar mass is the mean mass of a mole of the
100 * fluid at current composition. It is defined as the sum of the
101 * component's molar masses weighted by the current mole fraction:
102 * \f[\mathrm{ \overline M_\alpha = \sum_\kappa M^\kappa x_\alpha^\kappa}\f]
103 *
104 * Since this is an immiscible fluidstate we simply consider the molarMass of the
105 * pure component/phase.
106 */
107 Scalar averageMolarMass(int phaseIdx) const
108
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 { return FluidSystem::molarMass(/*compIdx=*/phaseIdx); }
109
110 /*!
111 * \brief The molar concentration \f$c^\kappa_\alpha\f$ of component \f$\kappa\f$ in fluid phase \f$\alpha\f$ in \f$\mathrm{[mol/m^3]}\f$
112 *
113 * This quantity is usually called "molar concentration" or just
114 * "concentration", but there are many other (though less common)
115 * measures for concentration.
116 *
117 * http://en.wikipedia.org/wiki/Concentration
118 */
119 Scalar molarity(int phaseIdx, int compIdx) const
120 2 { return molarDensity(phaseIdx)*moleFraction(phaseIdx, compIdx); }
121
122 /*!
123 * \brief The fugacity \f$f^\kappa_\alpha\f$ of component \f$\kappa\f$
124 * in fluid phase \f$\alpha\f$ in \f$\mathrm{[Pa]}\f$
125 * @copydoc ImmiscibleFluidState::fugacity()
126 * To avoid numerical issues with code that assumes miscibility,
127 * we return a fugacity of 0 for components which do not mix with
128 * the specified phase. (Actually it is undefined, but for finite
129 * fugacity coefficients, the only way to get components
130 * completely out of a phase is 0 to feed it zero fugacity.)
131 */
132 Scalar fugacity(int phaseIdx, int compIdx) const
133 1 { return phaseIdx == compIdx ? pressure(phaseIdx) : 0.0; }
134
135 /*!
136 * \brief The fugacity coefficient \f$\Phi^\kappa_\alpha\f$ of component \f$\kappa\f$ in fluid phase \f$\alpha\f$ in \f$\mathrm{[-]}\f$
137 *
138 * Since we assume immiscibility, the fugacity coefficients for
139 * the components which are not miscible with the phase is
140 * infinite. Beware that this will very likely break your code if
141 * you don't keep that in mind.
142 */
143 Scalar fugacityCoefficient(int phaseIdx, int compIdx) const
144 { return phaseIdx == compIdx ? 1.0 : std::numeric_limits<Scalar>::infinity(); }
145
146 /*!
147 * \brief The molar volume \f$v_{mol,\alpha}\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[m^3/mol]}\f$
148 *
149 * This quantity is the inverse of the molar density.
150 */
151 Scalar molarVolume(int phaseIdx) const
152 1 { return 1.0/molarDensity(phaseIdx); }
153
154 /*!
155 * \brief The mass density \f$\rho_\alpha\f$ of the fluid phase
156 * \f$\alpha\f$ in \f$\mathrm{[kg/m^3]}\f$
157 */
158 Scalar density(int phaseIdx) const
159 1 { return density_[phaseIdx]; }
160
161 /*!
162 * \brief The molar density \f$\rho_{mol,\alpha}\f$
163 * of a fluid phase \f$\alpha\f$ in \f$\mathrm{[mol/m^3]}\f$
164 *
165 * The molar density is defined by the mass density \f$\rho_\alpha\f$ and the mean molar mass \f$\overline M_\alpha\f$:
166 *
167 * \f[\rho_{mol,\alpha} = \frac{\rho_\alpha}{\overline M_\alpha} \;.\f]
168 */
169 Scalar molarDensity(int phaseIdx) const
170 1 { return molarDensity_[phaseIdx]; }
171
172 /*!
173 * \brief The temperature of a fluid phase \f$\mathrm{[K]}\f$
174 */
175 Scalar temperature(int phaseIdx) const
176 { return temperature_; }
177
178 /*!
179 * \brief The temperature within the domain \f$\mathrm{[K]}\f$
180 */
181 Scalar temperature() const
182 { return temperature_; }
183
184 /*!
185 * \brief The pressure \f$p_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[Pa]}\f$
186 */
187 Scalar pressure(int phaseIdx) const
188 1 { return pressure_[phaseIdx]; }
189
190 /*!
191 * \brief The specific enthalpy \f$h_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[J/kg]}\f$
192 * This is not defined for an isothermal fluidstate.
193 */
194 1 Scalar enthalpy(int phaseIdx) const
195
7/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
11 { DUNE_THROW(Dune::NotImplemented,"No enthalpy() function defined for isothermal systems!"); }
196
197 /*!
198 * \brief The specific internal energy \f$u_\alpha\f$ of a fluid phase \f$\alpha\f$ in \f$\mathrm{[J/kg]}\f$
199 *
200 * The specific internal energy is defined by the relation:
201 * \f[u_\alpha = h_\alpha - \frac{p_\alpha}{\rho_\alpha}\f]
202 * This is not defined for an isothermal fluidstate.
203 */
204 1 Scalar internalEnergy(int phaseIdx) const
205
7/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
11 { DUNE_THROW(Dune::NotImplemented,"No internalEnergy() function defined for isothermal systems!"); }
206
207 /*!
208 * \brief The dynamic viscosity \f$\mu_\alpha\f$ of fluid phase \f$\alpha\f$ in \f$\mathrm{[Pa s]}\f$
209 */
210 Scalar viscosity(int phaseIdx) const
211
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { return viscosity_[phaseIdx]; }
212
213 /*****************************************************
214 * Setter methods. Note that these are not part of the
215 * generic FluidState interface but specific for each
216 * implementation...
217 *****************************************************/
218
219 /*!
220 * \brief Retrieve all parameters from an arbitrary fluid
221 * state.
222 * \param fs Fluidstate
223 */
224 template <class FluidState>
225 void assign(const FluidState &fs)
226 {
227 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
228 {
229 pressure_[phaseIdx] = fs.pressure(phaseIdx);
230 saturation_[phaseIdx] = fs.saturation(phaseIdx);
231 density_[phaseIdx] = fs.density(phaseIdx);
232 molarDensity_[phaseIdx] = fs.molarDensity(phaseIdx);
233 viscosity_[phaseIdx] = fs.viscosity(phaseIdx);
234 }
235 temperature_ = fs.temperature(0);
236 }
237
238 /*!
239 * \brief Set the temperature \f$\mathrm{[K]]}\f$ of a fluid phase
240 */
241 void setTemperature(Scalar value)
242 { temperature_ = value; }
243
244 /*!
245 * \brief Set the fluid pressure of a phase \f$\mathrm{[Pa]}\f$
246 */
247 void setPressure(int phaseIdx, Scalar value)
248 { pressure_[phaseIdx] = value; }
249
250 /*!
251 * \brief Set the saturation of a phase \f$\mathrm{[-]}\f$
252 */
253 void setSaturation(int phaseIdx, Scalar value)
254 { saturation_[phaseIdx] = value; }
255
256 /*!
257 * \brief Set the density of a phase \f$\mathrm{[kg/m^3]}\f$
258 */
259 void setDensity(int phaseIdx, Scalar value)
260 { density_[phaseIdx] = value; }
261
262 /*!
263 * \brief Set the molar density of a phase \f$\mathrm{[kg/m^3]}\f$
264 */
265 void setMolarDensity(int phaseIdx, Scalar value)
266 { molarDensity_[phaseIdx] = value; }
267
268 /*!
269 * \brief Set the dynamic viscosity of a phase \f$\mathrm{[Pa s]}\f$
270 */
271 void setViscosity(int phaseIdx, Scalar value)
272 { viscosity_[phaseIdx] = value; }
273
274 /*!
275 * \brief Set the index of the most wetting phase
276 */
277 void setWettingPhase(int phaseIdx)
278 { wPhaseIdx_ = phaseIdx; }
279 protected:
280 Scalar pressure_[numPhases] = {};
281 Scalar saturation_[numPhases] = {};
282 Scalar density_[numPhases] = {};
283 Scalar molarDensity_[numPhases] = {};
284 Scalar viscosity_[numPhases] = {};
285 Scalar temperature_ = 0.0;
286
287 int wPhaseIdx_{0};
288 };
289
290 } // end namespace Dumux
291
292 #endif
293