GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/fluidsystems/h2on2o2.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 154 160 96.2%
Functions: 37 37 100.0%
Branches: 121 277 43.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 /*!
9 * \file
10 * \ingroup FluidSystems
11 * \copybrief Dumux::FluidSystems::H2ON2O2
12 */
13 #ifndef DUMUX_H2O_N2_O2_FLUID_SYSTEM_HH
14 #define DUMUX_H2O_N2_O2_FLUID_SYSTEM_HH
15
16 #include <cassert>
17 #include <iomanip>
18
19 #include <dumux/common/exceptions.hh>
20
21 #include <dumux/material/fluidsystems/base.hh>
22 #include <dumux/material/idealgas.hh>
23 #include <dumux/material/constants.hh>
24
25 #include <dumux/material/components/n2.hh>
26 #include <dumux/material/components/h2o.hh>
27 #include <dumux/material/components/o2.hh>
28
29 #include <dumux/material/components/tabulatedcomponent.hh>
30 #include <dumux/material/binarycoefficients/h2o_n2.hh>
31 #include <dumux/material/binarycoefficients/h2o_o2.hh>
32 #include <dumux/material/binarycoefficients/n2_o2.hh>
33
34 #include <dumux/io/name.hh>
35
36 namespace Dumux {
37 namespace FluidSystems {
38 /*!
39 * \ingroup FluidSystems
40 * \brief Policy for the H2O-N2-O2 fluid system
41 */
42 template<bool fastButSimplifiedRelations = false>
43 struct H2ON2O2DefaultPolicy
44 {
45 static constexpr bool useH2ODensityAsLiquidMixtureDensity() { return fastButSimplifiedRelations; }
46 static constexpr bool useIdealGasDensity() { return fastButSimplifiedRelations; }
47 static constexpr bool useN2ViscosityAsGasMixtureViscosity() { return fastButSimplifiedRelations; }
48 static constexpr bool useN2HeatConductivityAsGasMixtureHeatConductivity() { return fastButSimplifiedRelations; }
49 static constexpr bool useIdealGasHeatCapacities() { return fastButSimplifiedRelations; }
50 };
51
52 /*!
53 * \ingroup FluidSystems
54 * \brief A two-phase (water and air) fluid system
55 * with water, nitrogen and oxygen as components.
56 *
57 * This fluidsystem uses tabulated version of water of the IAPWS-formulation.
58 *
59 * Also remember to initialize tabulated components (FluidSystem::init()), while this
60 * is not necessary for non-tabularized ones.
61 */
62 template <class Scalar, class Policy = H2ON2O2DefaultPolicy<>>
63 class H2ON2O2
64 : public Base<Scalar, H2ON2O2<Scalar, Policy> >
65 {
66 using ThisType = H2ON2O2<Scalar, Policy>;
67
68 using IdealGas = Dumux::IdealGas<Scalar>;
69 using Constants = Dumux::Constants<Scalar>;
70 using TabulatedH2O = Components::TabulatedComponent<Dumux::Components::H2O<Scalar> >;
71 using SimpleN2 = Dumux::Components::N2<Scalar>;
72 using O2 = Dumux::Components::O2<Scalar>;
73
74 //! The components for pure water
75 using H2O = TabulatedH2O;
76
77 //! The components for pure nitrogen
78 using N2 = SimpleN2;
79
80 public:
81 static constexpr int numPhases = 2; //!< Number of phases in the fluid system
82 static constexpr int numComponents = 3; //!< Number of components in the fluid system
83 static constexpr int numSPhases = 0; // TODO: Remove
84
85 static constexpr int liquidPhaseIdx = 0; //!< index of the liquid phase
86 static constexpr int gasPhaseIdx = 1; //!< index of the gas phase
87 static constexpr int phase0Idx = liquidPhaseIdx; //!< index of the first phase
88 static constexpr int phase1Idx = gasPhaseIdx; //!< index of the second phase
89
90 static constexpr int H2OIdx = 0;
91 static constexpr int N2Idx = 1;
92 static constexpr int O2Idx = 2;
93
94 static constexpr int comp0Idx = H2OIdx; // first major component
95 static constexpr int comp1Idx = N2Idx; // second major component
96 static constexpr int comp2Idx = O2Idx; // secondary component
97
98 // main component at 20°C and 1 bar
99 static constexpr int liquidPhaseMainCompIdx = H2OIdx;
100 static constexpr int gasPhaseMainCompIdx = N2Idx;
101
102 /****************************************
103 * Fluid phase related static parameters
104 ****************************************/
105 /*!
106 * \brief Return the human readable name of a fluid phase
107 *
108 * \param phaseIdx The index of the fluid phase to consider
109 */
110 58 static std::string phaseName(int phaseIdx)
111 {
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
58 assert(0 <= phaseIdx && phaseIdx < numPhases);
113
2/3
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
58 switch (phaseIdx)
114 {
115 28 case liquidPhaseIdx: return IOName::liquidPhase();
116 30 case gasPhaseIdx: return IOName::gaseousPhase();
117 }
118 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
119 }
120
121 /*!
122 * \brief Return whether a phase is gaseous
123 *
124 * \param phaseIdx The index of the fluid phase to consider
125 */
126 static constexpr bool isGas(int phaseIdx)
127 {
128
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
12 assert(0 <= phaseIdx && phaseIdx < numPhases);
129 return phaseIdx == gasPhaseIdx;
130 }
131
132 /*!
133 * \brief Returns true if and only if a fluid phase is assumed to
134 * be an ideal mixture.
135 *
136 * We define an ideal mixture as a fluid phase where the fugacity
137 * coefficients of all components times the pressure of the phase
138 * are independent on the fluid composition. This assumption is true
139 * if Henry's law and Raoult's law apply. If you are unsure what
140 * this function should return, it is safe to return false. The
141 * only damage done will be (slightly) increased computation times
142 * in some cases.
143 *
144 * \param phaseIdx The index of the fluid phase to consider
145 */
146 static bool isIdealMixture(int phaseIdx)
147 {
148 assert(0 <= phaseIdx && phaseIdx < numPhases);
149 // we assume Henry's and Raoult's laws for the water phase and
150 // and no interaction between gas molecules of different
151 // components, so all phases are ideal mixtures!
152 return true;
153 }
154
155 /*!
156 * \brief Returns true if and only if a fluid phase is assumed to
157 * be compressible.
158 *
159 * Compressible means that the partial derivative of the density
160 * to the fluid pressure is always larger than zero.
161 *
162 * \param phaseIdx The index of the fluid phase to consider
163 */
164 static constexpr bool isCompressible(int phaseIdx)
165 {
166 assert(0 <= phaseIdx && phaseIdx < numPhases);
167 // gases are always compressible
168 if (phaseIdx == gasPhaseIdx)
169 return true;
170 // the water component decides for the liquid phase...
171 return H2O::liquidIsCompressible();
172 }
173
174 /*!
175 * \brief Returns true if and only if a fluid phase is assumed to
176 * be an ideal gas.
177 *
178 * \param phaseIdx The index of the fluid phase to consider
179 */
180 static bool isIdealGas(int phaseIdx)
181 {
182 assert(0 <= phaseIdx && phaseIdx < numPhases);
183 if (phaseIdx == gasPhaseIdx)
184 // let the components decide
185 return H2O::gasIsIdeal() && N2::gasIsIdeal() && O2::gasIsIdeal();
186 return false; // not a gas
187 }
188
189 /*!
190 * \brief Returns whether the fluids are miscible
191 */
192 static constexpr bool isMiscible()
193 { return true; }
194
195 /****************************************
196 * Component related static parameters
197 ****************************************/
198 /*!
199 * \brief Return the human readable name of a component
200 *
201 * \param compIdx The index of the component to consider
202 */
203 36 static std::string componentName(int compIdx)
204 {
205
3/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
36 switch (compIdx)
206 {
207 12 case H2OIdx: return H2O::name();
208 12 case N2Idx: return N2::name();
209 12 case O2Idx: return O2::name();
210 }
211
212 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);
213 }
214
215 /*!
216 * \brief Return the molar mass of a component in \f$\mathrm{[kg/mol]}\f$.
217 *
218 * \param compIdx The index of the component to consider
219 */
220 static Scalar molarMass(int compIdx)
221 {
222 static const Scalar M[] = {
223 H2O::molarMass(),
224 N2::molarMass(),
225 O2::molarMass()
226 };
227
228
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 8687334 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 36 times.
8687376 assert(0 <= compIdx && compIdx < numComponents);
229
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
9936375 return M[compIdx];
230 }
231
232 /*!
233 * \brief Critical temperature of a component \f$\mathrm{[K]}\f$.
234 *
235 * \param compIdx The index of the component to consider
236 */
237 static Scalar criticalTemperature(int compIdx)
238 {
239 static const Scalar Tcrit[] = {
240 H2O::criticalTemperature(),
241 N2::criticalTemperature(),
242 O2::criticalTemperature()
243 };
244
245 assert(0 <= compIdx && compIdx < numComponents);
246 return Tcrit[compIdx];
247 }
248
249 /*!
250 * \brief Critical pressure of a component \f$\mathrm{[Pa]}\f$.
251 *
252 * \param compIdx The index of the component to consider
253 */
254 static Scalar criticalPressure(int compIdx)
255 {
256 static const Scalar pcrit[] = {
257 H2O::criticalPressure(),
258 N2::criticalPressure(),
259 O2::criticalPressure()
260 };
261
262 assert(0 <= compIdx && compIdx < numComponents);
263 return pcrit[compIdx];
264 }
265
266 /*!
267 * \brief Molar volume of a component at the critical point \f$\mathrm{[m^3/mol]}\f$.
268 *
269 * \param compIdx The index of the component to consider
270 */
271 static Scalar criticalMolarVolume(int compIdx)
272 {
273 DUNE_THROW(Dune::NotImplemented,
274 "H2ON2O2FluidSystem::criticalMolarVolume()");
275 }
276
277 /*!
278 * \brief The acentric factor of a component \f$\mathrm{[-]}\f$.
279 *
280 * \param compIdx The index of the component to consider
281 */
282 static Scalar acentricFactor(int compIdx)
283 {
284 static const Scalar accFac[] = {
285 H2O::acentricFactor(),
286 N2::acentricFactor(),
287 O2::acentricFactor()
288 };
289
290 assert(0 <= compIdx && compIdx < numComponents);
291 return accFac[compIdx];
292 }
293
294 /*!
295 * \brief Kelvin equation in \f$\mathrm{[Pa]}\f$
296 *
297 * Calculate the increase vapor pressure over the
298 * curved surface of a drop with radius r
299 *
300 * \param fluidState An arbitrary fluid state
301 * \param phaseIdx The index of the fluid phase to consider
302 * \param compIdx The index of the component to consider
303 * \param radius The radius of the drop
304 */
305 template <class FluidState>
306 static Scalar kelvinVaporPressure(const FluidState &fluidState,
307 const int phaseIdx,
308 const int compIdx,
309 const Scalar radius)
310 {
311 assert(0 <= phaseIdx && phaseIdx == liquidPhaseIdx);
312 assert(0 <= compIdx && compIdx == liquidPhaseMainCompIdx);
313
314 Scalar T = fluidState.temperature(phaseIdx);
315
316 Scalar vaporPressure = H2O::vaporPressure(T);
317 Scalar exponent = molarMass(compIdx)/(density(fluidState, phaseIdx) * Constants::R * T);
318 exponent *= (2 * surfaceTension(fluidState) / radius);
319 using std::exp;
320 Scalar kelvinVaporPressure = vaporPressure * exp(exponent);
321
322 return kelvinVaporPressure;
323 }
324
325 /*!
326 * \brief Vapor pressure including the Kelvin equation in \f$\mathrm{[Pa]}\f$
327 *
328 * Calculate the decreased vapor pressure due to capillarity
329 *
330 * \param fluidState An arbitrary fluid state
331 * \param phaseIdx The index of the fluid phase to consider
332 * \param compIdx The index of the component to consider
333 */
334 template <class FluidState>
335 static Scalar kelvinVaporPressure(const FluidState &fluidState,
336 const int phaseIdx,
337 const int compIdx)
338 {
339 assert(compIdx == liquidPhaseMainCompIdx && phaseIdx == liquidPhaseIdx);
340
341 using std::exp;
342 return fugacityCoefficient(fluidState, phaseIdx, compIdx)
343 * fluidState.pressure(phaseIdx)
344 * exp(-(fluidState.pressure(gasPhaseIdx)-fluidState.pressure(liquidPhaseIdx))
345 / density(fluidState, phaseIdx)
346 / (Dumux::Constants<Scalar>::R / molarMass(compIdx))
347 / fluidState.temperature());
348 }
349
350 /*!
351 * \brief Calculate the surface tension between water and air in \f$\mathrm{[\frac{N}{m}]}\f$,
352 * according to IAPWS Release on Surface Tension from September 1994.
353 * The equation is valid between the triple Point (0.01C) and the critical temperature.
354 *
355 * \param fluidState An arbitrary fluid state
356 */
357 template <class FluidState>
358 static Scalar surfaceTension(const FluidState &fluidState)
359 {
360 const Scalar T = fluidState.temperature(); //K
361 const Scalar B = 0.2358 ; // [N/m]
362 const Scalar T_c = H2O::criticalTemperature(); //K
363 const Scalar mu = 1.256;
364 const Scalar b = -0.625;
365 //Equation to calculate surface Tension of Water According to IAPWS Release on Surface Tension from September 1994
366 using std::pow;
367 const Scalar surfaceTension = B*pow((1.-(T/T_c)),mu)*(1.+b*(1.-(T/T_c)));
368 return surfaceTension; //surface Tension [N/m]
369 }
370 /****************************************
371 * thermodynamic relations
372 ****************************************/
373
374 /*!
375 * \brief Initialize the fluid system's static parameters generically
376 *
377 * If a tabulated H2O component is used, we do our best to create
378 * tables that always work.
379 */
380 static void init()
381 {
382 3 init(/*tempMin=*/273.15,
383 /*tempMax=*/623.15,
384 /*numTemp=*/100,
385 /*pMin=*/0.0,
386 /*pMax=*/20e6,
387 /*numP=*/200);
388 }
389
390 /*!
391 * \brief Initialize the fluid system's static parameters using
392 * problem specific temperature and pressure ranges
393 *
394 * \param tempMin The minimum temperature used for tabulation of water \f$\mathrm{[K]}\f$
395 * \param tempMax The maximum temperature used for tabulation of water \f$\mathrm{[K]}\f$
396 * \param nTemp The number of ticks on the temperature axis of the table of water
397 * \param pressMin The minimum pressure used for tabulation of water \f$\mathrm{[Pa]}\f$
398 * \param pressMax The maximum pressure used for tabulation of water \f$\mathrm{[Pa]}\f$
399 * \param nPress The number of ticks on the pressure axis of the table of water
400 */
401 9 static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
402 Scalar pressMin, Scalar pressMax, unsigned nPress)
403 {
404 9 std::cout << "The H2O-N2-O2 fluid system was configured with the following policy:\n";
405 18 std::cout << " - use H2O density as liquid mixture density: " << std::boolalpha << Policy::useH2ODensityAsLiquidMixtureDensity() << "\n";
406 18 std::cout << " - use ideal gas density: " << std::boolalpha << Policy::useIdealGasDensity() << "\n";
407 18 std::cout << " - use N2 viscosity as gas mixture viscosity: " << std::boolalpha << Policy::useN2ViscosityAsGasMixtureViscosity() << "\n";
408 18 std::cout << " - use N2 heat conductivity as gas mixture heat conductivity: " << std::boolalpha << Policy::useN2HeatConductivityAsGasMixtureHeatConductivity() << "\n";
409 18 std::cout << " - use ideal gas heat capacities: " << std::boolalpha << Policy::useIdealGasHeatCapacities() << std::endl;
410
411 if (H2O::isTabulated)
412 {
413 9 TabulatedH2O::init(tempMin, tempMax, nTemp,
414 pressMin, pressMax, nPress);
415 }
416 9 }
417
418 using Base<Scalar, ThisType>::density;
419 /*!
420 * \brief Given a phase's composition, temperature, pressure, and
421 * the partial pressures of all components, return its
422 * density \f$\mathrm{[kg/m^3]}\f$.
423 *
424 * If Policy::useH2ODensityAsLiquidMixtureDensity() == false, we apply Eq. (7)
425 * in Class et al. (2002a) \cite A3:class:2002b <BR>
426 * for the liquid density.
427 *
428 * \param fluidState An arbitrary fluid state
429 * \param phaseIdx The index of the fluid phase to consider
430 */
431 template <class FluidState>
432 603436 static Scalar density(const FluidState &fluidState,
433 int phaseIdx)
434 {
435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 603431 times.
603436 assert(0 <= phaseIdx && phaseIdx < numPhases);
436
437
2/2
✓ Branch 0 taken 301713 times.
✓ Branch 1 taken 301713 times.
603436 Scalar T = fluidState.temperature(phaseIdx);
438
2/2
✓ Branch 0 taken 301713 times.
✓ Branch 1 taken 301713 times.
603436 Scalar p = fluidState.pressure(phaseIdx);
439
440 // liquid phase
441
2/2
✓ Branch 0 taken 301715 times.
✓ Branch 1 taken 301716 times.
603436 if (phaseIdx == liquidPhaseIdx)
442 {
443 // assume pure water
444 if (Policy::useH2ODensityAsLiquidMixtureDensity())
445 2 return H2O::liquidDensity(T, p);
446
447 // See: Eq. (7) in Class et al. (2002a)
448 // This assumes each gas molecule displaces exactly one
449 // molecule in the liquid.
450 else
451 301715 return H2O::liquidMolarDensity(T, p)
452 301715 * (fluidState.moleFraction(liquidPhaseIdx, H2OIdx)*H2O::molarMass()
453 301715 + fluidState.moleFraction(liquidPhaseIdx, N2Idx)*N2::molarMass()
454 603428 + fluidState.moleFraction(liquidPhaseIdx, O2Idx)*O2::molarMass());
455 }
456
457 // gas phase
458 else if (phaseIdx == gasPhaseIdx)
459 {
460
461 // for the gas phase assume an ideal gas
462 using std::max;
463 if (Policy::useIdealGasDensity())
464 4 return IdealGas::molarDensity(T, p) * fluidState.averageMolarMass(gasPhaseIdx);
465
466 // assume ideal mixture: steam, nitrogen and oxygen don't "see" each other
467 else
468 603430 return H2O::gasDensity(T, fluidState.partialPressure(gasPhaseIdx, H2OIdx))
469 603430 + N2::gasDensity(T, fluidState.partialPressure(gasPhaseIdx, N2Idx))
470 905143 + O2::gasDensity(T, fluidState.partialPressure(gasPhaseIdx, O2Idx));
471 }
472
473 DUNE_THROW(Dune::InvalidStateException, "Unknown phase index " << phaseIdx);
474 }
475
476 using Base<Scalar, ThisType>::molarDensity;
477 //! \copydoc Base<Scalar,ThisType>::molarDensity(const FluidState&,int)
478 template <class FluidState>
479 603436 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
480 {
481
2/2
✓ Branch 0 taken 301713 times.
✓ Branch 1 taken 301713 times.
603436 const Scalar T = fluidState.temperature(phaseIdx);
482
2/2
✓ Branch 0 taken 301713 times.
✓ Branch 1 taken 301713 times.
603436 const Scalar p = fluidState.pressure(phaseIdx);
483
484
2/2
✓ Branch 0 taken 301715 times.
✓ Branch 1 taken 301716 times.
603436 if (phaseIdx == liquidPhaseIdx)
485 {
486 // assume pure water or that each gas molecule displaces exactly one
487 // molecule in the liquid.
488 301717 return H2O::liquidMolarDensity(T, p);
489 }
490 else
491 {
492 if (Policy::useIdealGasDensity())
493 { //assume ideal gas
494 4 return IdealGas::molarDensity(T,p);
495 }
496
497 603430 return H2O::gasMolarDensity(T, fluidState.partialPressure(gasPhaseIdx, H2OIdx))
498 603430 + N2::gasMolarDensity(T, fluidState.partialPressure(gasPhaseIdx, N2Idx))
499 905143 + O2::gasMolarDensity(T, fluidState.partialPressure(gasPhaseIdx, O2Idx));
500 }
501 }
502
503 using Base<Scalar, ThisType>::viscosity;
504 /*!
505 * \brief Calculate the dynamic viscosity of a fluid phase \f$\mathrm{[Pa*s]}\f$
506 *
507 * Compositional effects in the gas phase are accounted by the Wilke method.
508 * See Reid et al. (1987) \cite reid1987 <BR>
509 * 4th edition, McGraw-Hill, 1987, 407-410
510 * 5th edition, McGraw-Hill, 20001, p. 9.21/22
511 * \note Compositional effects for a liquid mixture have to be implemented.
512 *
513 * \param fluidState An arbitrary fluid state
514 * \param phaseIdx The index of the fluid phase to consider
515 */
516 template <class FluidState>
517 603436 static Scalar viscosity(const FluidState &fluidState,
518 int phaseIdx)
519 {
520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 603431 times.
603436 assert(0 <= phaseIdx && phaseIdx < numPhases);
521
522
2/2
✓ Branch 0 taken 301713 times.
✓ Branch 1 taken 301713 times.
603436 Scalar T = fluidState.temperature(phaseIdx);
523
2/2
✓ Branch 0 taken 301713 times.
✓ Branch 1 taken 301713 times.
603436 Scalar p = fluidState.pressure(phaseIdx);
524
525 // liquid phase
526
2/2
✓ Branch 0 taken 301715 times.
✓ Branch 1 taken 301716 times.
603436 if (phaseIdx == liquidPhaseIdx) {
527 // assume pure water for the liquid phase
528 301717 return H2O::liquidViscosity(T, p);
529 }
530
531 // gas phase
532 if (Policy::useN2ViscosityAsGasMixtureViscosity())
533 {
534 // assume pure nitrogen for the gas phase
535 2 return N2::gasViscosity(T, p);
536 }
537 else
538 {
539 // Wilke method (Reid et al.):
540 301717 Scalar muResult = 0;
541 905151 const Scalar mu[numComponents] = {
542 301717 h2oGasViscosityInMixture(T, p),
543 301717 N2::gasViscosity(T, p),
544 301717 O2::gasViscosity(T, p)
545 };
546
547 301717 Scalar sumx = 0.0;
548 using std::max;
549
2/2
✓ Branch 0 taken 905145 times.
✓ Branch 1 taken 301715 times.
1206868 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
550 1810290 sumx += fluidState.moleFraction(phaseIdx, compIdx);
551
1/2
✓ Branch 0 taken 301715 times.
✗ Branch 1 not taken.
301717 sumx = max(1e-10, sumx);
552
553
2/2
✓ Branch 0 taken 905145 times.
✓ Branch 1 taken 301715 times.
1206868 for (int i = 0; i < numComponents; ++i) {
554 Scalar divisor = 0;
555 using std::pow;
556 using std::sqrt;
557
2/2
✓ Branch 0 taken 2715435 times.
✓ Branch 1 taken 905145 times.
3620604 for (int j = 0; j < numComponents; ++j) {
558 8146359 Scalar phiIJ = 1 + sqrt(mu[i]/mu[j]) * pow(molarMass(j)/molarMass(i), 1/4.0);
559 2715453 phiIJ *= phiIJ;
560 2715453 phiIJ /= sqrt(8*(1 + molarMass(i)/molarMass(j)));
561 5430870 divisor += fluidState.moleFraction(phaseIdx, j)/sumx * phiIJ;
562 }
563 1810290 muResult += fluidState.moleFraction(phaseIdx, i)/sumx * mu[i] / divisor;
564 }
565 return muResult;
566 }
567 }
568
569 using Base<Scalar, ThisType>::fugacityCoefficient;
570 /*!
571 * \brief Returns the fugacity coefficient \f$\mathrm{[-]}\f$ of a component in a
572 * phase.
573 *
574 * The fugacity coefficient \f$\phi^\kappa_\alpha\f$ of
575 * component \f$\kappa\f$ in phase \f$\alpha\f$ is connected to
576 * the fugacity \f$f^\kappa_\alpha\f$ and the component's mole
577 * fraction \f$x^\kappa_\alpha\f$ by means of the relation
578 *
579 * \f[
580 f^\kappa_\alpha = \phi^\kappa_\alpha\;x^\kappa_\alpha\;p_\alpha
581 \f]
582 * where \f$p_\alpha\f$ is the pressure of the fluid phase.
583 *
584 * For liquids with very low miscibility this boils down to the
585 * Henry constant for the solutes and the saturated vapor pressure
586 * both divided by phase pressure.
587 * \param fluidState An arbitrary fluid state
588 * \param phaseIdx The index of the fluid phase to consider
589 * \param compIdx The index of the component to consider
590 */
591 template <class FluidState>
592 1810308 static Scalar fugacityCoefficient(const FluidState &fluidState,
593 int phaseIdx,
594 int compIdx)
595 {
596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1810293 times.
1810308 assert(0 <= phaseIdx && phaseIdx < numPhases);
597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1810293 times.
1810308 assert(0 <= compIdx && compIdx < numComponents);
598
599
2/2
✓ Branch 0 taken 905139 times.
✓ Branch 1 taken 905139 times.
1810308 Scalar T = fluidState.temperature(phaseIdx);
600
2/2
✓ Branch 0 taken 905139 times.
✓ Branch 1 taken 905139 times.
1810308 Scalar p = fluidState.pressure(phaseIdx);
601
602 // liquid phase
603
2/2
✓ Branch 0 taken 905145 times.
✓ Branch 1 taken 905148 times.
1810308 if (phaseIdx == liquidPhaseIdx)
604 {
605
3/4
✓ Branch 0 taken 301715 times.
✓ Branch 1 taken 301715 times.
✓ Branch 2 taken 301715 times.
✗ Branch 3 not taken.
905151 switch(compIdx){
606 301717 case H2OIdx: return H2O::vaporPressure(T)/p;
607 301717 case N2Idx: return BinaryCoeff::H2O_N2::henry(T)/p;
608 301717 case O2Idx: return BinaryCoeff::H2O_O2::henry(T)/p;
609 };
610 }
611
612 // for the gas phase, assume an ideal gas when it comes to
613 // fugacity (-> fugacity == partial pressure)
614 return 1.0;
615 }
616
617 using Base<Scalar, ThisType>::diffusionCoefficient;
618 //! \copydoc Base<Scalar,ThisType>::diffusionCoefficient(const FluidState&,int,int)
619 template <class FluidState>
620 30 static Scalar diffusionCoefficient(const FluidState &fluidState,
621 int phaseIdx,
622 int compIdx)
623 {
624
7/16
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 15 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 15 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 15 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 15 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 15 times.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 15 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
330 DUNE_THROW(Dune::NotImplemented, "Diffusion coefficients");
625 }
626
627 using Base<Scalar, ThisType>::binaryDiffusionCoefficient;
628 //! \copydoc Base<Scalar,ThisType>::binaryDiffusionCoefficient(const FluidState&,int,int,int)
629 template <class FluidState>
630 1206942 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
631 int phaseIdx,
632 int compIIdx,
633 int compJIdx)
634
635 {
636
2/2
✓ Branch 0 taken 301728 times.
✓ Branch 1 taken 905169 times.
1206942 if (compIIdx > compJIdx)
637 {
638 using std::swap;
639 301743 swap(compIIdx, compJIdx);
640 }
641
642 #ifndef NDEBUG
643
3/4
✓ Branch 0 taken 1206882 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 1206882 times.
✗ Branch 3 not taken.
1206942 if (compIIdx == compJIdx ||
644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1206882 times.
1206912 phaseIdx > numPhases - 1 ||
645 compJIdx > numComponents - 1)
646 {
647
10/22
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 15 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 15 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 15 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 15 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 15 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 15 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 15 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 15 times.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 15 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
420 DUNE_THROW(Dune::InvalidStateException,
648 "Binary diffusion coefficient of components "
649 << compIIdx << " and " << compJIdx
650 << " in phase " << phaseIdx << " is undefined!\n");
651 }
652 #endif
653
654
2/2
✓ Branch 0 taken 603426 times.
✓ Branch 1 taken 603426 times.
1206912 Scalar T = fluidState.temperature(phaseIdx);
655
2/2
✓ Branch 0 taken 603426 times.
✓ Branch 1 taken 603426 times.
1206912 Scalar p = fluidState.pressure(phaseIdx);
656
657 // liquid phase
658
2/2
✓ Branch 0 taken 603438 times.
✓ Branch 1 taken 603444 times.
1206912 if (phaseIdx == liquidPhaseIdx) {
659
4/4
✓ Branch 0 taken 603434 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 301717 times.
✓ Branch 3 taken 301717 times.
603450 if (compIIdx == H2OIdx && compJIdx == N2Idx)
660 603442 return BinaryCoeff::H2O_N2::liquidDiffCoeff(T, p);
661
3/4
✓ Branch 0 taken 301717 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 301717 times.
✗ Branch 3 not taken.
301729 if (compIIdx == H2OIdx && compJIdx == O2Idx)
662 603442 return BinaryCoeff::H2O_O2::liquidDiffCoeff(T, p);
663
10/22
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 4 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 4 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 4 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 4 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 4 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 4 times.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 4 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
112 DUNE_THROW(Dune::InvalidStateException,
664 "Binary diffusion coefficient of components "
665 << compIIdx << " and " << compJIdx
666 << " in phase " << phaseIdx << " is undefined!\n");
667 }
668 // gas phase
669
1/2
✓ Branch 0 taken 603444 times.
✗ Branch 1 not taken.
603462 if (phaseIdx == gasPhaseIdx) {
670
4/4
✓ Branch 0 taken 301725 times.
✓ Branch 1 taken 301719 times.
✓ Branch 2 taken 301719 times.
✓ Branch 3 taken 6 times.
603462 if (compIIdx == H2OIdx && compJIdx == N2Idx)
671 301725 return BinaryCoeff::H2O_N2::gasDiffCoeff(T, p);
672
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 301719 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
301737 if (compIIdx == H2OIdx && compJIdx == O2Idx)
673 12 return BinaryCoeff::H2O_O2::gasDiffCoeff(T, p);
674
2/4
✓ Branch 0 taken 301719 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 301719 times.
✗ Branch 3 not taken.
301725 if(compIIdx == N2Idx && compJIdx == O2Idx)
675 301725 return BinaryCoeff::N2_O2::gasDiffCoeff(T, p);
676 DUNE_THROW(Dune::InvalidStateException,
677 "Binary diffusion coefficient of components "
678 << compIIdx << " and " << compJIdx
679 << " in phase " << phaseIdx << " is undefined!\n");
680 }
681
682 DUNE_THROW(Dune::InvalidStateException,
683 "Binary diffusion coefficient of components "
684 << compIIdx << " and " << compJIdx
685 << " in phase " << phaseIdx << " is undefined!\n");
686 }
687
688 using Base<Scalar, ThisType>::enthalpy;
689 /*!
690 * \brief Given a phase's composition, temperature, pressure and
691 * density, calculate its specific enthalpy \f$\mathrm{[J/kg]}\f$.
692 *
693 * \note This fluid system neglects the contribution of
694 * gas-molecules in the liquid phase. This contribution is
695 * probably not big. Somebody would have to find out the
696 * enthalpy of solution for this system. ...
697 *
698 * \param fluidState An arbitrary fluid state
699 * \param phaseIdx The index of the fluid phase to consider
700 */
701 template <class FluidState>
702 278818 static Scalar enthalpy(const FluidState &fluidState,
703 int phaseIdx)
704 {
705
2/2
✓ Branch 0 taken 139404 times.
✓ Branch 1 taken 139404 times.
278818 Scalar T = fluidState.temperature(phaseIdx);
706
2/2
✓ Branch 0 taken 139404 times.
✓ Branch 1 taken 139404 times.
278818 Scalar p = fluidState.pressure(phaseIdx);
707
708 // liquid phase
709
2/2
✓ Branch 0 taken 139406 times.
✓ Branch 1 taken 139407 times.
278818 if (phaseIdx == liquidPhaseIdx) {
710 139408 return H2O::liquidEnthalpy(T, p);
711 }
712 // gas phase
713
1/2
✓ Branch 0 taken 139407 times.
✗ Branch 1 not taken.
139410 else if (phaseIdx == gasPhaseIdx)
714 {
715 // assume ideal mixture: which means
716 // that the total specific enthalpy is the sum of the
717 // "partial specific enthalpies" of the components.
718 139410 Scalar hH2O =
719 fluidState.massFraction(gasPhaseIdx, H2OIdx)
720 278814 * H2O::gasEnthalpy(T, p);
721 139410 Scalar hN2 =
722 fluidState.massFraction(gasPhaseIdx, N2Idx)
723 278814 * N2::gasEnthalpy(T,p);
724 139410 Scalar hO2 =
725 fluidState.massFraction(gasPhaseIdx, O2Idx)
726 278814 * O2::gasEnthalpy(T,p);
727 139410 return hH2O + hN2 + hO2;
728 }
729 else
730 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
731 }
732
733 /*!
734 * \brief Returns the specific enthalpy \f$\mathrm{[J/kg]}\f$ of a component in a specific phase
735 * \param fluidState An arbitrary fluid state
736 * \param phaseIdx The index of the fluid phase to consider
737 * \param componentIdx The index of the component to consider
738 */
739 template <class FluidState>
740 static Scalar componentEnthalpy(const FluidState &fluidState,
741 int phaseIdx,
742 int componentIdx)
743 {
744 const Scalar T = fluidState.temperature(phaseIdx);
745 const Scalar p = fluidState.pressure(phaseIdx);
746
747 if (phaseIdx == phase0Idx)
748 {
749 if (componentIdx == H2OIdx)
750 return H2O::liquidEnthalpy(T, p);
751 else if (componentIdx == N2Idx)
752 DUNE_THROW(Dune::NotImplemented, "Component enthalpy of nitrogen in liquid phase");
753 else if (componentIdx == O2Idx)
754 DUNE_THROW(Dune::NotImplemented, "Component enthalpy of oxygen in liquid phase");
755 else
756 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << componentIdx);
757 }
758 else if (phaseIdx == phase1Idx)
759 {
760 if (componentIdx == H2OIdx)
761 return H2O::gasEnthalpy(T, p);
762 else if (componentIdx == N2Idx)
763 return N2::gasEnthalpy(T, p);
764 else if (componentIdx == O2Idx)
765 return O2::gasEnthalpy(T, p);
766 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << componentIdx);
767 }
768 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
769 }
770
771 using Base<Scalar, ThisType>::thermalConductivity;
772 /*!
773 * \brief Thermal conductivity of a fluid phase \f$\mathrm{[W/(m K)]}\f$.
774 *
775 * Use the conductivity of air and water as a first approximation.
776 *
777 * http://en.wikipedia.org/wiki/List_of_thermal_conductivities
778 * \param fluidState An arbitrary fluid state
779 * \param phaseIdx The index of the fluid phase to consider
780 */
781 template <class FluidState>
782 278818 static Scalar thermalConductivity(const FluidState &fluidState,
783 const int phaseIdx)
784 {
785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 278813 times.
278818 assert(0 <= phaseIdx && phaseIdx < numPhases);
786
2/2
✓ Branch 0 taken 139404 times.
✓ Branch 1 taken 139404 times.
278818 Scalar temperature = fluidState.temperature(phaseIdx) ;
787
2/2
✓ Branch 0 taken 139404 times.
✓ Branch 1 taken 139404 times.
278818 Scalar pressure = fluidState.pressure(phaseIdx);
788
789
2/2
✓ Branch 0 taken 139406 times.
✓ Branch 1 taken 139407 times.
278818 if (phaseIdx == liquidPhaseIdx)
790 {
791 139408 return H2O::liquidThermalConductivity(temperature, pressure);
792 }
793 else
794 {
795 139410 Scalar lambdaPureN2 = N2::gasThermalConductivity(temperature, pressure);
796 139410 Scalar lambdaPureO2 = O2::gasThermalConductivity(temperature, pressure);
797 if (!Policy::useN2HeatConductivityAsGasMixtureHeatConductivity())
798 {
799 139408 Scalar xN2 = fluidState.moleFraction(phaseIdx, N2Idx);
800 139408 Scalar xO2 = fluidState.moleFraction(phaseIdx, O2Idx);
801 139408 Scalar xH2O = fluidState.moleFraction(phaseIdx, H2OIdx);
802 139408 Scalar lambdaN2 = xN2 * lambdaPureN2;
803 139408 Scalar lambdaO2 = xO2 * lambdaPureO2;
804 139408 Scalar partialPressure = pressure * xH2O;
805 139408 Scalar lambdaH2O = xH2O * H2O::gasThermalConductivity(temperature, partialPressure);
806 139408 return lambdaN2 + lambdaH2O + lambdaO2;
807 }
808 else
809 2 return lambdaPureN2;
810 }
811 }
812
813 using Base<Scalar, ThisType>::heatCapacity;
814 //! \copydoc Base<Scalar,ThisType>::heatCapacity(const FluidState&,int)
815 template <class FluidState>
816 5 static Scalar heatCapacity(const FluidState &fluidState,
817 int phaseIdx)
818 {
819 5 if (phaseIdx == liquidPhaseIdx) {
820 2 return H2O::liquidHeatCapacity(fluidState.temperature(phaseIdx),
821 2 fluidState.pressure(phaseIdx));
822 }
823
824 Scalar c_pN2;
825 Scalar c_pO2;
826 Scalar c_pH2O;
827 // let the water and nitrogen components do things their own way
828 if (!Policy::useIdealGasHeatCapacities()) {
829 2 c_pN2 = N2::gasHeatCapacity(fluidState.temperature(phaseIdx),
830 fluidState.pressure(phaseIdx)
831 2 * fluidState.moleFraction(phaseIdx, N2Idx));
832
833 2 c_pH2O = H2O::gasHeatCapacity(fluidState.temperature(phaseIdx),
834 fluidState.pressure(phaseIdx)
835 2 * fluidState.moleFraction(phaseIdx, H2OIdx));
836 2 c_pO2 = O2::gasHeatCapacity(fluidState.temperature(phaseIdx),
837 fluidState.pressure(phaseIdx)
838 2 * fluidState.moleFraction(phaseIdx, O2Idx));
839 }
840 else {
841 // assume an ideal gas for both components. See:
842 //
843 //http://en.wikipedia.org/wiki/Heat_capacity
844 1 Scalar c_vN2molar = Constants::R*2.39;
845 1 Scalar c_pN2molar = Constants::R + c_vN2molar;
846
847 1 Scalar c_vO2molar = Constants::R*2.43;
848 1 Scalar c_pO2molar = Constants::R + c_vO2molar;
849
850 1 Scalar c_vH2Omolar = Constants::R*3.37; // <- correct??
851 1 Scalar c_pH2Omolar = Constants::R + c_vH2Omolar;
852
853 1 c_pN2 = c_pN2molar/molarMass(N2Idx);
854 1 c_pO2 = c_pO2molar/molarMass(O2Idx);
855 1 c_pH2O = c_pH2Omolar/molarMass(H2OIdx);
856 }
857
858 // mangle all components together
859 return
860 3 c_pH2O*fluidState.massFraction(gasPhaseIdx, H2OIdx)
861 3 + c_pN2*fluidState.massFraction(gasPhaseIdx, N2Idx)
862 3 + c_pO2*fluidState.massFraction(gasPhaseIdx, O2Idx);
863 }
864
865 };
866
867 } // end namespace FluidSystems
868 } // end namespace Dumux
869
870 #endif
871