GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/fluidsystems/h2on2.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 130 132 98.5%
Functions: 88 88 100.0%
Branches: 110 193 57.0%

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 FluidSystems
10 * \copybrief Dumux::FluidSystems::H2ON2
11 */
12 #ifndef DUMUX_H2O_N2_FLUID_SYSTEM_HH
13 #define DUMUX_H2O_N2_FLUID_SYSTEM_HH
14
15 #include <cassert>
16 #include <iomanip>
17
18 #include <dumux/common/exceptions.hh>
19
20 #include <dumux/material/idealgas.hh>
21
22 #include <dumux/material/components/n2.hh>
23 #include <dumux/material/components/h2o.hh>
24 #include <dumux/material/components/tabulatedcomponent.hh>
25 #include <dumux/material/binarycoefficients/h2o_n2.hh>
26
27 #include <dumux/io/name.hh>
28
29 #include "base.hh"
30
31 namespace Dumux {
32 namespace FluidSystems {
33
34 /*!
35 * \ingroup FluidSystems
36 * \brief Policy for the H2O-N2 fluid system
37 */
38 template<bool fastButSimplifiedRelations = false>
39 struct H2ON2DefaultPolicy
40 {
41 static constexpr bool useH2ODensityAsLiquidMixtureDensity() { return fastButSimplifiedRelations; }
42 static constexpr bool useIdealGasDensity() { return fastButSimplifiedRelations; }
43 static constexpr bool useN2ViscosityAsGasMixtureViscosity() { return fastButSimplifiedRelations; }
44 static constexpr bool useN2HeatConductivityAsGasMixtureHeatConductivity() { return fastButSimplifiedRelations; }
45 static constexpr bool useIdealGasHeatCapacities() { return fastButSimplifiedRelations; }
46 };
47
48 /*!
49 * \ingroup FluidSystems
50 *
51 * \brief A two-phase fluid system with two components water \f$(\mathrm{H_2O})\f$
52 * Nitrogen \f$(\mathrm{N_2})\f$ for non-equilibrium models.
53 */
54 template <class Scalar, class Policy = H2ON2DefaultPolicy<>>
55 class H2ON2
56 : public Base<Scalar, H2ON2<Scalar, Policy> >
57 {
58 using ThisType = H2ON2<Scalar, Policy>;
59
60 // convenience using declarations
61 using IdealGas = Dumux::IdealGas<Scalar>;
62 using TabulatedH2O = Components::TabulatedComponent<Dumux::Components::H2O<Scalar> >;
63 using SimpleN2 = Dumux::Components::N2<Scalar>;
64
65 public:
66 using H2O = TabulatedH2O; //!< The components for pure water
67 using N2 = SimpleN2; //!< The components for pure nitrogen
68
69 static constexpr int numPhases = 2; //!< Number of phases in the fluid system
70 static constexpr int numComponents = 2; //!< Number of components in the fluid system
71
72 static constexpr int liquidPhaseIdx = 0; //!< index of the liquid phase
73 static constexpr int gasPhaseIdx = 1; //!< index of the gas phase
74 static constexpr int phase0Idx = liquidPhaseIdx; //!< index of the first phase
75 static constexpr int phase1Idx = gasPhaseIdx; //!< index of the second phase
76
77 static constexpr int H2OIdx = 0;
78 static constexpr int N2Idx = 1;
79 static constexpr int comp0Idx = H2OIdx; //!< index of the first component
80 static constexpr int comp1Idx = N2Idx; //!< index of the second component
81 static constexpr int liquidCompIdx = H2OIdx; //!< index of the liquid component
82 static constexpr int gasCompIdx = N2Idx; //!< index of the gas component
83
84 /****************************************
85 * Fluid phase related static parameters
86 ****************************************/
87 /*!
88 * \brief Return the human readable name of a fluid phase
89 *
90 * \param phaseIdx The index of the fluid phase to consider
91 */
92 1150 static std::string phaseName(int phaseIdx)
93 {
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1142 times.
1150 assert(0 <= phaseIdx && phaseIdx < numPhases);
95
2/3
✓ Branch 0 taken 930 times.
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
1150 switch (phaseIdx)
96 {
97 934 case liquidPhaseIdx: return IOName::liquidPhase();
98 216 case gasPhaseIdx: return IOName::gaseousPhase();
99 }
100 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
101 }
102
103 /*!
104 * \brief Returns whether the fluids are miscible
105 */
106 static constexpr bool isMiscible()
107 { return true; }
108
109 /*!
110 * \brief Return whether a phase is gaseous
111 *
112 * \param phaseIdx The index of the fluid phase to consider
113 */
114 static constexpr bool isGas(int phaseIdx)
115 {
116
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 99332 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
99336 assert(0 <= phaseIdx && phaseIdx < numPhases);
117 return phaseIdx == gasPhaseIdx;
118 }
119
120 /*!
121 * \brief Returns true if and only if a fluid phase is assumed to
122 * be an ideal mixture.
123 *
124 * We define an ideal mixture as a fluid phase where the fugacity
125 * coefficients of all components times the pressure of the phase
126 * are independent on the fluid composition. This assumption is true
127 * if Henry's law and Raoult's law apply. If you are unsure what
128 * this function should return, it is safe to return false. The
129 * only damage done will be (slightly) increased computation times
130 * in some cases.
131 *
132 * \param phaseIdx The index of the fluid phase to consider
133 */
134 static bool isIdealMixture(int phaseIdx)
135 {
136
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 14982027 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12594427 times.
27576454 assert(0 <= phaseIdx && phaseIdx < numPhases);
137 // we assume Henry's and Raoult's laws for the water phase and
138 // and no interaction between gas molecules of different
139 // components, so all phases are ideal mixtures!
140 return true;
141 }
142
143 /*!
144 * \brief Returns true if and only if a fluid phase is assumed to
145 * be compressible.
146 *
147 * Compressible means that the partial derivative of the density
148 * to the fluid pressure is always larger than zero.
149 *
150 * \param phaseIdx The index of the fluid phase to consider
151 */
152 static constexpr bool isCompressible(int phaseIdx)
153 {
154 assert(0 <= phaseIdx && phaseIdx < numPhases);
155 // gases are always compressible
156 if (phaseIdx == gasPhaseIdx)
157 return true;
158 // the water component decides for the liquid phase...
159 return H2O::liquidIsCompressible();
160 }
161
162 /*!
163 * \brief Returns true if and only if a fluid phase is assumed to
164 * be an ideal gas.
165 *
166 * \param phaseIdx The index of the fluid phase to consider
167 */
168 static bool isIdealGas(int phaseIdx)
169 {
170 assert(0 <= phaseIdx && phaseIdx < numPhases);
171
172 if (phaseIdx == gasPhaseIdx)
173 // let the components decide
174 return H2O::gasIsIdeal() && N2::gasIsIdeal();
175 return false; // not a gas
176 }
177
178 /****************************************
179 * Component related static parameters
180 ****************************************/
181 /*!
182 * \brief Return the human readable name of a component
183 *
184 * \param compIdx The index of the component to consider
185 */
186 376 static std::string componentName(int compIdx)
187 {
188
2/3
✓ Branch 0 taken 185 times.
✓ Branch 1 taken 183 times.
✗ Branch 2 not taken.
376 switch (compIdx)
189 {
190 189 case H2OIdx: return H2O::name();
191 187 case N2Idx: return N2::name();
192 }
193
194 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);
195 }
196
197 /*!
198 * \brief Return the molar mass of a component in \f$\mathrm{[kg/mol]}\f$.
199 *
200 * \param compIdx The index of the component to consider
201 */
202 static Scalar molarMass(int compIdx)
203 {
204 static const Scalar M[] = {
205 H2O::molarMass(),
206 N2::molarMass(),
207 };
208
209
5/14
✗ Branch 0 not taken.
✓ Branch 1 taken 507826322 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 63886040 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 7724848 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 7 times.
579437219 assert(0 <= compIdx && compIdx < numComponents);
210
7/11
✓ Branch 0 taken 21451240 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 42434796 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
561086216 return M[compIdx];
211 }
212
213 /*!
214 * \brief Critical temperature of a component \f$\mathrm{[K]}\f$.
215 *
216 * \param compIdx The index of the component to consider
217 */
218 static Scalar criticalTemperature(int compIdx)
219 {
220 static const Scalar Tcrit[] = {
221 H2O::criticalTemperature(),
222 N2::criticalTemperature()
223 };
224
225 assert(0 <= compIdx && compIdx < numComponents);
226 return Tcrit[compIdx];
227 }
228
229 /*!
230 * \brief Critical pressure of a component \f$\mathrm{[Pa]}\f$.
231 *
232 * \param compIdx The index of the component to consider
233 */
234 static Scalar criticalPressure(int compIdx)
235 {
236 static const Scalar pcrit[] = {
237 H2O::criticalPressure(),
238 N2::criticalPressure()
239 };
240
241 assert(0 <= compIdx && compIdx < numComponents);
242 return pcrit[compIdx];
243 }
244
245 /*!
246 * \brief Vapor pressure including the Kelvin equation in \f$\mathrm{[Pa]}\f$
247 *
248 * Calculate the decreased vapor pressure due to capillarity
249 *
250 * \param fluidState An arbitrary fluid state
251 * \param phaseIdx The index of the fluid phase to consider
252 * \param compIdx The index of the component to consider
253 */
254 template <class FluidState>
255 static Scalar kelvinVaporPressure(const FluidState &fluidState,
256 const int phaseIdx,
257 const int compIdx)
258 {
259 assert(compIdx == H2OIdx && phaseIdx == liquidPhaseIdx);
260
261 using std::exp;
262 return fugacityCoefficient(fluidState, phaseIdx, compIdx)
263 * fluidState.pressure(phaseIdx)
264 * exp(-(fluidState.pressure(gasPhaseIdx)-fluidState.pressure(liquidPhaseIdx))
265 / density(fluidState, phaseIdx)
266 / (Dumux::Constants<Scalar>::R / molarMass(compIdx))
267 / fluidState.temperature());
268 }
269
270 /*!
271 * \brief Molar volume of a component at the critical point \f$\mathrm{[m^3/mol]}\f$.
272 *
273 * \param compIdx The index of the component to consider
274 */
275 static Scalar criticalMolarVolume(int compIdx)
276 {
277 DUNE_THROW(Dune::NotImplemented,
278 "H2ON2FluidSystem::criticalMolarVolume()");
279 }
280
281 /*!
282 * \brief The acentric factor of a component \f$\mathrm{[-]}\f$.
283 *
284 * \param compIdx The index of the component to consider
285 */
286 static Scalar acentricFactor(int compIdx)
287 {
288 static const Scalar accFac[] = {
289 H2O::acentricFactor(),
290 N2::acentricFactor()
291 };
292
293 assert(0 <= compIdx && compIdx < numComponents);
294 return accFac[compIdx];
295 }
296
297 /****************************************
298 * thermodynamic relations
299 ****************************************/
300
301 /*!
302 * \brief Initialize the fluid system's static parameters generically
303 *
304 * If a tabulated H2O component is used, we do our best to create
305 * tables that always work.
306 */
307 static void init()
308 {
309
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
54 init(/*tempMin=*/273.15,
310 /*tempMax=*/623.15,
311 /*numTemp=*/100,
312 /*pMin=*/0.0,
313 /*pMax=*/20e6,
314 /*numP=*/200);
315 }
316
317 /*!
318 * \brief Initialize the fluid system's static parameters using
319 * problem specific temperature and pressure ranges
320 *
321 * \param tempMin The minimum temperature used for tabulation of water \f$\mathrm{[K]}\f$
322 * \param tempMax The maximum temperature used for tabulation of water \f$\mathrm{[K]}\f$
323 * \param nTemp The number of ticks on the temperature axis of the table of water
324 * \param pressMin The minimum pressure used for tabulation of water \f$\mathrm{[Pa]}\f$
325 * \param pressMax The maximum pressure used for tabulation of water \f$\mathrm{[Pa]}\f$
326 * \param nPress The number of ticks on the pressure axis of the table of water
327 */
328 80 static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
329 Scalar pressMin, Scalar pressMax, unsigned nPress)
330 {
331 80 std::cout << "The H2O-N2 fluid system was configured with the following policy:\n";
332 160 std::cout << " - use H2O density as liquid mixture density: " << std::boolalpha << Policy::useH2ODensityAsLiquidMixtureDensity() << "\n";
333 160 std::cout << " - use ideal gas density: " << std::boolalpha << Policy::useIdealGasDensity() << "\n";
334 160 std::cout << " - use N2 viscosity as gas mixture viscosity: " << std::boolalpha << Policy::useN2ViscosityAsGasMixtureViscosity() << "\n";
335 160 std::cout << " - use N2 heat conductivity as gas mixture heat conductivity: " << std::boolalpha << Policy::useN2HeatConductivityAsGasMixtureHeatConductivity() << "\n";
336 160 std::cout << " - use ideal gas heat capacities: " << std::boolalpha << Policy::useIdealGasHeatCapacities() << std::endl;
337
338 if constexpr (H2O::isTabulated)
339 80 H2O::init(tempMin, tempMax, nTemp, pressMin, pressMax, nPress);
340 80 }
341
342 using Base<Scalar, ThisType>::density;
343 /*!
344 * \brief Given a phase's composition, temperature, pressure, and
345 * the partial pressures of all components, return its
346 * density \f$\mathrm{[kg/m^3]}\f$.
347 *
348 * If Policy::useH2ODensityAsLiquidMixtureDensity() == false, we apply Eq. (7)
349 * in Class et al. (2002a) \cite A3:class:2002b <BR>
350 * for the liquid density.
351 *
352 * \param fluidState An arbitrary fluid state
353 * \param phaseIdx The index of the fluid phase to consider
354 */
355 template <class FluidState>
356 52892219 static Scalar density(const FluidState &fluidState,
357 int phaseIdx)
358 {
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52892185 times.
52892219 assert(0 <= phaseIdx && phaseIdx < numPhases);
360
361
2/2
✓ Branch 0 taken 18634829 times.
✓ Branch 1 taken 34257346 times.
52892219 Scalar T = fluidState.temperature(phaseIdx);
362
2/2
✓ Branch 0 taken 18634830 times.
✓ Branch 1 taken 34257347 times.
52892219 Scalar p = fluidState.pressure(phaseIdx);
363
364 // liquid phase
365
2/2
✓ Branch 0 taken 18634834 times.
✓ Branch 1 taken 34257351 times.
52892219 if (phaseIdx == liquidPhaseIdx) {
366 if (Policy::useH2ODensityAsLiquidMixtureDensity())
367 // assume pure water
368 22499597 return H2O::liquidDensity(T, p);
369 else
370 {
371 // See: Eq. (7) in Class et al. (2002a)
372 // This assumes each gas molecule displaces exactly one
373 // molecule in the liquid.
374 11522261 return H2O::liquidMolarDensity(T, p)
375 11522261 * (H2O::molarMass()*fluidState.moleFraction(liquidPhaseIdx, H2OIdx)
376 23044384 + N2::molarMass()*fluidState.moleFraction(liquidPhaseIdx, N2Idx));
377 }
378 }
379
380 // gas phase
381 using std::max;
382 if (Policy::useIdealGasDensity())
383 // for the gas phase assume an ideal gas
384 {
385 7323268 const Scalar averageMolarMass = fluidState.averageMolarMass(gasPhaseIdx);
386 14646536 return IdealGas::density(averageMolarMass, T, p);
387 }
388
389 // assume ideal mixture: steam and nitrogen don't "see" each other
390 23069216 Scalar rho_gH2O = H2O::gasDensity(T, fluidState.partialPressure(gasPhaseIdx, H2OIdx));
391 23069350 Scalar rho_gN2 = N2::gasDensity(T, fluidState.partialPressure(gasPhaseIdx, N2Idx));
392 11547093 return (rho_gH2O + rho_gN2);
393 }
394
395 using Base<Scalar, ThisType>::molarDensity;
396 //! \copydoc Dumux::FluidSystems::Base<Scalar,ThisType>::molarDensity(const FluidState&,int)
397 template <class FluidState>
398 48192023 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
399 {
400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48191997 times.
48192023 assert(0 <= phaseIdx && phaseIdx < numPhases);
401
402
2/2
✓ Branch 0 taken 31653494 times.
✓ Branch 1 taken 16538493 times.
48192031 Scalar T = fluidState.temperature(phaseIdx);
403
2/2
✓ Branch 0 taken 31653495 times.
✓ Branch 1 taken 16538494 times.
48192031 Scalar p = fluidState.pressure(phaseIdx);
404
405 // liquid phase
406
2/2
✓ Branch 0 taken 31653499 times.
✓ Branch 1 taken 16538498 times.
48192023 if (phaseIdx == liquidPhaseIdx)
407 {
408 // assume pure water or that each gas molecule displaces exactly one
409 // molecule in the liquid.
410 31653516 return H2O::liquidMolarDensity(T, p);
411 }
412
413 // gas phase
414 using std::max;
415 if (Policy::useIdealGasDensity())
416 // for the gas phase assume an ideal gas
417 {
418 9982844 return IdealGas::molarDensity(T, p);
419 }
420
421 // assume ideal mixture: steam and nitrogen don't "see" each other
422 23069216 Scalar rho_gH2O = H2O::gasMolarDensity(T, fluidState.partialPressure(gasPhaseIdx, H2OIdx));
423 23069350 Scalar rho_gN2 = N2::gasMolarDensity(T, fluidState.partialPressure(gasPhaseIdx, N2Idx));
424 11547093 return rho_gH2O + rho_gN2;
425 }
426
427 using Base<Scalar, ThisType>::viscosity;
428 /*!
429 * \brief Calculate the dynamic viscosity of a fluid phase \f$\mathrm{[Pa*s]}\f$
430 *
431 * Compositional effects in the gas phase are accounted by the Wilke method.
432 * See Reid et al. (1987) \cite reid1987 <BR>
433 * 4th edition, McGraw-Hill, 1987, 407-410
434 * 5th edition, McGraw-Hill, 20001, p. 9.21/22
435 *
436 * \param fluidState An arbitrary fluid state
437 * \param phaseIdx The index of the fluid phase to consider
438 * \note Compositional effects for a liquid mixture have to be implemented.
439 */
440 template <class FluidState>
441 49499279 static Scalar viscosity(const FluidState &fluidState,
442 int phaseIdx)
443 {
444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49499253 times.
49499279 assert(0 <= phaseIdx && phaseIdx < numPhases);
445
446
2/2
✓ Branch 0 taken 32962760 times.
✓ Branch 1 taken 16536483 times.
49499279 Scalar T = fluidState.temperature(phaseIdx);
447
2/2
✓ Branch 0 taken 32962761 times.
✓ Branch 1 taken 16536484 times.
49499279 Scalar p = fluidState.pressure(phaseIdx);
448
449 // liquid phase
450
2/2
✓ Branch 0 taken 32962765 times.
✓ Branch 1 taken 16536488 times.
49499279 if (phaseIdx == liquidPhaseIdx) {
451 // assume pure water for the liquid phase
452 32962778 return H2O::liquidViscosity(T, p);
453 }
454
455 // gas phase
456 if (Policy::useN2ViscosityAsGasMixtureViscosity())
457 {
458 // assume pure nitrogen for the gas phase
459 4989542 return N2::gasViscosity(T, p);
460 }
461 else
462 {
463 // Wilke method (Reid et al.):
464 11546959 Scalar muResult = 0;
465 23093918 const Scalar mu[numComponents] = {
466 11546959 h2oGasViscosityInMixture(T, p),
467 11546959 N2::gasViscosity(T, p)
468 };
469
470 11546959 Scalar sumx = 0.0;
471 using std::max;
472
2/2
✓ Branch 0 taken 23093914 times.
✓ Branch 1 taken 11546957 times.
34640877 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
473 46187828 sumx += fluidState.moleFraction(phaseIdx, compIdx);
474
1/2
✓ Branch 0 taken 11546957 times.
✗ Branch 1 not taken.
11546959 sumx = max(1e-10, sumx);
475
476
2/2
✓ Branch 0 taken 23093914 times.
✓ Branch 1 taken 11546957 times.
34640877 for (int i = 0; i < numComponents; ++i) {
477 Scalar divisor = 0;
478 // using std::sqrt;
479 // using std::pow;
480
2/2
✓ Branch 0 taken 46187828 times.
✓ Branch 1 taken 23093914 times.
69281754 for (int j = 0; j < numComponents; ++j) {
481 138563508 Scalar phiIJ = 1 + sqrt(mu[i]/mu[j]) * pow(molarMass(j)/molarMass(i), 1/4.0);
482 46187836 phiIJ *= phiIJ;
483 46187836 phiIJ /= sqrt(8*(1 + molarMass(i)/molarMass(j)));
484 92375656 divisor += fluidState.moleFraction(phaseIdx, j)/sumx * phiIJ;
485 }
486 46187828 muResult += fluidState.moleFraction(phaseIdx, i)/sumx * mu[i] / divisor;
487 }
488
489 return muResult;
490 }
491 }
492
493 using Base<Scalar, ThisType>::fugacityCoefficient;
494 //! \copydoc Dumux::FluidSystems::Base<Scalar,ThisType>::fugacityCoefficient(const FluidState&,int,int)
495 template <class FluidState>
496 69986020 static Scalar fugacityCoefficient(const FluidState &fluidState,
497 int phaseIdx,
498 int compIdx)
499 {
500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69986004 times.
69986020 assert(0 <= phaseIdx && phaseIdx < numPhases);
501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69986004 times.
69986020 assert(0 <= compIdx && compIdx < numComponents);
502
503
2/2
✓ Branch 0 taken 34992994 times.
✓ Branch 1 taken 34992994 times.
69986020 Scalar T = fluidState.temperature(phaseIdx);
504
2/2
✓ Branch 0 taken 34992994 times.
✓ Branch 1 taken 34992994 times.
69986020 Scalar p = fluidState.pressure(phaseIdx);
505
506 // liquid phase
507
2/2
✓ Branch 0 taken 34993002 times.
✓ Branch 1 taken 34993002 times.
69986020 if (phaseIdx == liquidPhaseIdx) {
508
2/2
✓ Branch 0 taken 17496501 times.
✓ Branch 1 taken 17496501 times.
34993010 if (compIdx == H2OIdx)
509 17496505 return H2O::vaporPressure(T)/p;
510 17496505 return BinaryCoeff::H2O_N2::henry(T)/p;
511 }
512
513 // for the gas phase, assume an ideal gas when it comes to
514 // fugacity (-> fugacity == partial pressure)
515 return 1.0;
516 }
517
518 using Base<Scalar, ThisType>::diffusionCoefficient;
519 //! \copydoc Dumux::FluidSystems::Base<Scalar,ThisType>::diffusionCoefficient(const FluidState&,int,int)
520 template <class FluidState>
521 32 static Scalar diffusionCoefficient(const FluidState &fluidState,
522 int phaseIdx,
523 int compIdx)
524 {
525
7/16
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 16 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 16 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 16 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 16 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 16 times.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
352 DUNE_THROW(Dune::NotImplemented, "Diffusion coefficients");
526 }
527
528 using Base<Scalar, ThisType>::binaryDiffusionCoefficient;
529 //! \copydoc Dumux::FluidSystems::Base<Scalar,ThisType>::binaryDiffusionCoefficient(const FluidState&,int,int,int)
530 template <class FluidState>
531 53539296 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
532 int phaseIdx,
533 int compIIdx,
534 int compJIdx)
535
536 {
537
2/2
✓ Branch 0 taken 18091728 times.
✓ Branch 1 taken 35447536 times.
53539296 if (compIIdx > compJIdx)
538 {
539 using std::swap;
540 18091736 swap(compIIdx, compJIdx);
541 }
542
543
2/2
✓ Branch 0 taken 34441612 times.
✓ Branch 1 taken 19097620 times.
53539296 const Scalar T = fluidState.temperature(phaseIdx);
544
2/2
✓ Branch 0 taken 34441612 times.
✓ Branch 1 taken 19097620 times.
53539296 const Scalar p = fluidState.pressure(phaseIdx);
545
546
6/6
✓ Branch 0 taken 34441628 times.
✓ Branch 1 taken 19097636 times.
✓ Branch 2 taken 34441624 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 34441620 times.
✓ Branch 5 taken 4 times.
53539296 if (phaseIdx == liquidPhaseIdx && compIIdx == H2OIdx && compJIdx == N2Idx)
547 68883256 return BinaryCoeff::H2O_N2::liquidDiffCoeff(T, p);
548
549
6/6
✓ Branch 0 taken 19097636 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 19097632 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 19097628 times.
✓ Branch 5 taken 4 times.
19097668 else if (phaseIdx == gasPhaseIdx && compIIdx == H2OIdx && compJIdx == N2Idx)
550 19097636 return BinaryCoeff::H2O_N2::gasDiffCoeff(T, p);
551
552 else
553
10/22
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 16 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 16 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 16 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 16 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 16 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 16 times.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 16 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
448 DUNE_THROW(Dune::InvalidStateException,
554 "Binary diffusion coefficient of components "
555 << compIIdx << " and " << compJIdx
556 << " in phase " << phaseIdx << " is unavailable!\n");
557 }
558
559 using Base<Scalar, ThisType>::enthalpy;
560 /*!
561 * \brief Given a phase's composition, temperature, pressure and
562 * density, calculate its specific enthalpy \f$\mathrm{[J/kg]}\f$.
563 *
564 * \note This fluid system neglects the contribution of
565 * gas-molecules in the liquid phase. This contribution is
566 * probably not big. Somebody would have to find out the
567 * enthalpy of solution for this system. ...
568 *
569 * \param fluidState An arbitrary fluid state
570 * \param phaseIdx The index of the fluid phase to consider
571 */
572 template <class FluidState>
573 42324812 static Scalar enthalpy(const FluidState &fluidState,
574 int phaseIdx)
575 {
576
2/2
✓ Branch 0 taken 26218796 times.
✓ Branch 1 taken 16106000 times.
42324812 const Scalar T = fluidState.temperature(phaseIdx);
577
2/2
✓ Branch 0 taken 26218796 times.
✓ Branch 1 taken 16106000 times.
42324812 const Scalar p = fluidState.pressure(phaseIdx);
578
579 // liquid phase
580
2/2
✓ Branch 0 taken 26218800 times.
✓ Branch 1 taken 16106004 times.
42324812 if (phaseIdx == liquidPhaseIdx) {
581 26218804 return H2O::liquidEnthalpy(T, p);
582 }
583 // gas phase
584 else {
585 // assume ideal mixture: which means
586 // that the total specific enthalpy is the sum of the
587 // "partial specific enthalpies" of the components.
588 16106008 Scalar hH2O =
589 fluidState.massFraction(gasPhaseIdx, H2OIdx)
590 28821931 * H2O::gasEnthalpy(T, p);
591 16106008 Scalar hN2 =
592 fluidState.massFraction(gasPhaseIdx, N2Idx)
593 28821931 * N2::gasEnthalpy(T, p);
594 16106008 return hH2O + hN2;
595 }
596 }
597
598 /*!
599 * \brief Returns the specific enthalpy \f$\mathrm{[J/kg]}\f$ of a component in the specified phase
600 * \param fluidState The fluid state
601 * \param phaseIdx The index of the phase
602 * \param componentIdx The index of the component
603 */
604 template <class FluidState>
605 static Scalar componentEnthalpy(const FluidState &fluidState,
606 int phaseIdx,
607 int componentIdx)
608 {
609 const Scalar T = fluidState.temperature(phaseIdx);
610 const Scalar p = fluidState.pressure(phaseIdx);
611
612 if (phaseIdx == liquidPhaseIdx)
613 {
614 if (componentIdx == H2OIdx)
615 return H2O::liquidEnthalpy(T, p);
616 else if (componentIdx == N2Idx)
617 DUNE_THROW(Dune::NotImplemented, "Component enthalpy of nitrogen in liquid phase");
618 else
619 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << componentIdx);
620 }
621 else if (phaseIdx == gasPhaseIdx)
622 {
623 if (componentIdx == H2OIdx)
624 return H2O::gasEnthalpy(T, p);
625 else if (componentIdx == N2Idx)
626 return N2::gasEnthalpy(T, p);
627 else
628 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << componentIdx);
629 }
630 else
631 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
632 }
633
634 using Base<Scalar, ThisType>::thermalConductivity;
635 /*!
636 * \brief Thermal conductivity of a fluid phase \f$\mathrm{[W/(m K)]}\f$.
637 *
638 * Use the conductivity of air and water as a first approximation.
639 *
640 * \param fluidState An arbitrary fluid state
641 * \param phaseIdx The index of the fluid phase to consider
642 */
643 template <class FluidState>
644 50149799 static Scalar thermalConductivity(const FluidState &fluidState,
645 const int phaseIdx)
646 {
647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50149791 times.
50149799 assert(0 <= phaseIdx && phaseIdx < numPhases);
648
649
2/2
✓ Branch 0 taken 32222218 times.
✓ Branch 1 taken 17927565 times.
50149799 const Scalar temperature = fluidState.temperature(phaseIdx) ;
650
2/2
✓ Branch 0 taken 32222218 times.
✓ Branch 1 taken 17927565 times.
50149799 const Scalar pressure = fluidState.pressure(phaseIdx);
651
2/2
✓ Branch 0 taken 32222222 times.
✓ Branch 1 taken 17927569 times.
50149799 if (phaseIdx == liquidPhaseIdx)
652 {
653 32222226 return H2O::liquidThermalConductivity(temperature, pressure);
654 }
655 else
656 {
657 17927573 Scalar lambdaPureN2 = N2::gasThermalConductivity(temperature, pressure);
658 if (!Policy::useN2HeatConductivityAsGasMixtureHeatConductivity())
659 {
660 11546959 Scalar xN2 = fluidState.moleFraction(phaseIdx, N2Idx);
661 11546959 Scalar xH2O = fluidState.moleFraction(phaseIdx, H2OIdx);
662 11546959 Scalar lambdaN2 = xN2 * lambdaPureN2;
663 11546959 Scalar partialPressure = pressure * xH2O;
664 11546959 Scalar lambdaH2O = xH2O * H2O::gasThermalConductivity(temperature, partialPressure);
665 11546959 return lambdaN2 + lambdaH2O;
666 }
667 else
668 6380614 return lambdaPureN2;
669 }
670 }
671
672 using Base<Scalar, ThisType>::heatCapacity;
673 //! \copydoc Dumux::FluidSystems::Base<Scalar,ThisType>::heatCapacity(const FluidState&,int)
674 template <class FluidState>
675 1612808 static Scalar heatCapacity(const FluidState &fluidState,
676 int phaseIdx)
677 {
678
2/2
✓ Branch 0 taken 806400 times.
✓ Branch 1 taken 806400 times.
1612808 if (phaseIdx == liquidPhaseIdx) {
679 6594673 return H2O::liquidHeatCapacity(fluidState.temperature(phaseIdx),
680 806404 fluidState.pressure(phaseIdx));
681 }
682
683 // for the gas phase, assume ideal mixture
684 Scalar c_pN2;
685 Scalar c_pH2O;
686 // let the water and nitrogen components do things their own way
687 if (!Policy::useIdealGasHeatCapacities()) {
688 2 c_pN2 = N2::gasHeatCapacity(fluidState.temperature(phaseIdx),
689 fluidState.pressure(phaseIdx)
690 2 * fluidState.moleFraction(phaseIdx, N2Idx));
691
692 2 c_pH2O = H2O::gasHeatCapacity(fluidState.temperature(phaseIdx),
693 fluidState.pressure(phaseIdx)
694 2 * fluidState.moleFraction(phaseIdx, H2OIdx));
695 }
696 else {
697 // assume an ideal gas for both components. See:
698 // http://en.wikipedia.org/wiki/Heat_capacity
699 806402 Scalar c_vN2molar = Constants<Scalar>::R*2.39;
700 806402 Scalar c_pN2molar = Constants<Scalar>::R + c_vN2molar;
701
702 806402 Scalar c_vH2Omolar = Constants<Scalar>::R*3.37; // <- correct??
703 806402 Scalar c_pH2Omolar = Constants<Scalar>::R + c_vH2Omolar;
704
705 806402 c_pN2 = c_pN2molar/molarMass(N2Idx);
706 806402 c_pH2O = c_pH2Omolar/molarMass(H2OIdx);
707 }
708
709 // mangle both components together
710 806404 return c_pH2O*fluidState.massFraction(gasPhaseIdx, H2OIdx)
711 806404 + c_pN2*fluidState.massFraction(gasPhaseIdx, N2Idx);
712 }
713 };
714
715 } // end namespace FluidSystems
716
717 } // end namespace Dumux
718
719 #endif
720