version 3.8
3pimmiscible.hh
Go to the documentation of this file.
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//
12#ifndef DUMUX_3P_IMMISCIBLE_FLUID_SYSTEM_HH
13#define DUMUX_3P_IMMISCIBLE_FLUID_SYSTEM_HH
14
15#include <cassert>
16#include <limits>
17#include <iostream>
18
19#include <dune/common/exceptions.hh>
20
25#include <dumux/io/name.hh>
26
27namespace Dumux {
28namespace FluidSystems {
29
47template <class Scalar, class WettingFluid, class NonwettingFluid, class Gas>
49: public Base<Scalar, ThreePImmiscible<Scalar, WettingFluid, NonwettingFluid, Gas> >
50{
51 static_assert((WettingFluid::numPhases == 1), "WettingFluid has more than one phase");
52 static_assert((NonwettingFluid::numPhases == 1), "NonwettingFluid has more than one phase");
53 static_assert((Gas::numPhases == 1), "Gas has more than one phase");
54 static_assert((WettingFluid::numComponents == 1), "WettingFluid has more than one component");
55 static_assert((NonwettingFluid::numComponents == 1), "NonwettingFluid has more than one component");
56 static_assert((Gas::numComponents == 1), "Gas has more than one component");
57
59
60public:
61 /****************************************
62 * Fluid phase related static parameters
63 ****************************************/
64
66 static constexpr int numPhases = 3;
67
69 static constexpr int wPhaseIdx = 0;
71 static constexpr int nPhaseIdx = 1;
73 static constexpr int gPhaseIdx = 2;
74
79 static std::string phaseName(int phaseIdx)
80 {
81 assert(0 <= phaseIdx && phaseIdx < numPhases);
82 switch (phaseIdx)
83 {
88 case gPhaseIdx: return IOName::gaseousPhase();
89 }
90 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
91 }
92
96 static constexpr bool isMiscible()
97 { return false; }
98
103 static constexpr bool isGas(int phaseIdx)
104 {
105 assert(0 <= phaseIdx && phaseIdx < numPhases);
106
107 switch (phaseIdx)
108 {
109 case wPhaseIdx: return WettingFluid::isGas(); break;
110 case nPhaseIdx: return NonwettingFluid::isGas(); break;
111 case gPhaseIdx: return Gas::isGas(); break;
112 default: return false; // TODO: constexpr-compatible throw
113 }
114 }
115
129 static constexpr bool isIdealMixture(int phaseIdx)
130 { return true; }
131
141 static constexpr bool isCompressible(int phaseIdx)
142 {
143 assert(0 <= phaseIdx && phaseIdx < numPhases);
144
145 // let the fluids decide
146 switch(phaseIdx)
147 {
148 case wPhaseIdx: return WettingFluid::isCompressible(); break;
149 case nPhaseIdx: return NonwettingFluid::isCompressible(); break;
150 case gPhaseIdx: return Gas::isCompressible(); break;
151 default: return false; // TODO: constexpr-compatible throw
152 }
153 }
154
161 static constexpr bool isIdealGas(int phaseIdx)
162 {
163 assert(0 <= phaseIdx && phaseIdx < numPhases);
164
165 // let the fluids decide
166 switch(phaseIdx)
167 {
168 case wPhaseIdx: return WettingFluid::isIdealGas(); break;
169 case nPhaseIdx: return NonwettingFluid::isIdealGas(); break;
170 case gPhaseIdx: return Gas::isIdealGas(); break;
171 default: return false; // TODO: constexpr-compatible throw
172 }
173 }
174
175 /****************************************
176 * Component related static parameters
177 ****************************************/
178
180 static constexpr int numComponents = 3;//WettingFluid::numComponents + NonwettingFluid::numComponents + Gas::numComponents; // TODO: 3??
181
183 static constexpr int wCompIdx = 0;
185 static constexpr int nCompIdx = 1;
187 static constexpr int gCompIdx = 2; // TODO: correct??
188
194 static std::string componentName(int compIdx)
195 {
196 assert(0 <= compIdx && compIdx < numComponents);
197
198 switch(compIdx)
199 {
200 case wCompIdx: return WettingFluid::name(); break;
201 case nCompIdx: return NonwettingFluid::name(); break;
202 case gCompIdx: return Gas::name(); break;
203 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
204 }
205 }
206
211 static Scalar molarMass(int compIdx)
212 {
213 assert(0 <= compIdx && compIdx < numComponents);
214
215 switch(compIdx)
216 {
217 case wCompIdx: return WettingFluid::molarMass(); break;
218 case nCompIdx: return NonwettingFluid::molarMass(); break;
219 case gCompIdx: return Gas::molarMass(); break;
220 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
221 }
222 }
223
228 static Scalar criticalTemperature(int compIdx)
229 {
230 assert(0 <= compIdx && compIdx < numComponents);
231
232 switch(compIdx)
233 {
234 case wCompIdx: return WettingFluid::criticalTemperature(); break;
235 case nCompIdx: return NonwettingFluid::criticalTemperature(); break;
236 case gCompIdx: return Gas::criticalTemperature(); break;
237 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
238 }
239 }
240
245 static Scalar criticalPressure(int compIdx)
246 {
247 assert(0 <= compIdx && compIdx < numComponents);
248
249 switch(compIdx)
250 {
251 case wCompIdx: return WettingFluid::criticalPressure(); break;
252 case nCompIdx: return NonwettingFluid::criticalPressure(); break;
253 case gCompIdx: return Gas::criticalPressure(); break;
254 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
255 }
256 }
257
262 static Scalar acentricFactor(int compIdx)
263 {
264 assert(0 <= compIdx && compIdx < numComponents);
265
266 switch(compIdx)
267 {
268 case wCompIdx: return WettingFluid::Component::acentricFactor(); break;
269 case nCompIdx: return NonwettingFluid::Component::acentricFactor(); break;
270 case gCompIdx: return Gas::Component::acentricFactor(); break;
271 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
272 }
273 }
274
275 /****************************************
276 * thermodynamic relations
277 ****************************************/
278
282 static constexpr void init()
283 {
284 // two gaseous phases at once do not make sense physically!
285 // (But two liquids are fine)
286 static_assert(!WettingFluid::isGas() && !NonwettingFluid::isGas() && Gas::isGas(), "There can only be one gaseous phase!");
287 }
288
300 static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
301 Scalar pressMin, Scalar pressMax, unsigned nPress)
302 {
303 // two gaseous phases at once do not make sense physically!
304 static_assert(!WettingFluid::isGas() && !NonwettingFluid::isGas() && Gas::isGas(), "There can only be one gaseous phase!");
305
306 if (WettingFluid::Component::isTabulated)
307 {
308 std::cout << "Initializing tables for the wetting fluid properties ("
309 << nTemp*nPress
310 << " entries).\n";
311
312 WettingFluid::Component::init(tempMin, tempMax, nTemp,
313 pressMin, pressMax, nPress);
314
315 }
316
317 if (NonwettingFluid::Component::isTabulated)
318 {
319 std::cout << "Initializing tables for the nonwetting fluid properties ("
320 << nTemp*nPress
321 << " entries).\n";
322
323 NonwettingFluid::Component::init(tempMin, tempMax, nTemp,
324 pressMin, pressMax, nPress);
325
326 }
327
328 if (Gas::Component::isTabulated)
329 {
330 std::cout << "Initializing tables for the gas fluid properties ("
331 << nTemp*nPress
332 << " entries).\n";
333
334 Gas::Component::init(tempMin, tempMax, nTemp,
335 pressMin, pressMax, nPress);
336
337 }
338 }
339
342 template <class FluidState>
343 static Scalar density(const FluidState &fluidState,
344 int phaseIdx)
345 {
346 assert(0 <= phaseIdx && phaseIdx < numPhases);
347
348 Scalar temperature = fluidState.temperature(phaseIdx);
349 Scalar pressure = fluidState.pressure(phaseIdx);
350
351 switch(phaseIdx)
352 {
355 case gPhaseIdx: return Gas::density(temperature, pressure); break;
356 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
357 }
358 }
359
370 template <class FluidState>
371 static Scalar molarDensity(const FluidState &fluidState,
372 int phaseIdx)
373 {
374 assert(0 <= phaseIdx && phaseIdx < numPhases);
375
376 Scalar temperature = fluidState.temperature(phaseIdx);
377 Scalar pressure = fluidState.pressure(phaseIdx);
378
379 switch(phaseIdx)
380 {
384 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
385 }
386 }
387
394 template <class FluidState>
395 static Scalar viscosity(const FluidState &fluidState,
396 int phaseIdx)
397 {
398 assert(0 <= phaseIdx && phaseIdx < numPhases);
399
400 Scalar temperature = fluidState.temperature(phaseIdx);
401 Scalar pressure = fluidState.pressure(phaseIdx);
402
403 switch(phaseIdx)
404 {
407 case gPhaseIdx: return Gas::viscosity(temperature, pressure); break;
408 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
409 }
410 }
411
429 template <class FluidState>
430 static Scalar fugacityCoefficient(const FluidState &fluidState,
431 int phaseIdx,
432 int compIdx)
433 {
434 assert(0 <= phaseIdx && phaseIdx < numPhases);
435 assert(0 <= compIdx && compIdx < numComponents);
436
437 if (phaseIdx == compIdx)
438 // We could calculate the real fugacity coefficient of
439 // the component in the fluid. Probably that's not worth
440 // the effort, since the fugacity coefficient of the other
441 // component is infinite anyway...
442 return 1.0;
443 return std::numeric_limits<Scalar>::infinity();
444 }
445
469 template <class FluidState>
470 static Scalar diffusionCoefficient(const FluidState &fluidState,
471 int phaseIdx,
472 int compIdx)
473 {
474 DUNE_THROW(Dune::InvalidStateException,
475 "Diffusion coefficients of components are meaningless if"
476 " immiscibility is assumed");
477 }
478
489 template <class FluidState>
490 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
491 int phaseIdx,
492 int compIIdx,
493 int compJIdx)
494
495 {
496 DUNE_THROW(Dune::InvalidStateException,
497 "Binary diffusion coefficients of components are meaningless if"
498 " immiscibility is assumed");
499 }
500
507 template <class FluidState>
508 static Scalar enthalpy(const FluidState &fluidState,
509 int phaseIdx)
510 {
511 assert(0 <= phaseIdx && phaseIdx < numPhases);
512
513 Scalar temperature = fluidState.temperature(phaseIdx);
514 Scalar pressure = fluidState.pressure(phaseIdx);
515
516 switch(phaseIdx)
517 {
518 case wPhaseIdx: return WettingFluid::enthalpy(temperature, pressure); break;
519 case nPhaseIdx: return NonwettingFluid::enthalpy(temperature, pressure); break;
520 case gPhaseIdx: return Gas::enthalpy(temperature, pressure); break;
521 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
522 }
523 }
524
531 template <class FluidState>
532 static Scalar thermalConductivity(const FluidState &fluidState,
533 int phaseIdx)
534 {
535 assert(0 <= phaseIdx && phaseIdx < numPhases);
536
537 Scalar temperature = fluidState.temperature(phaseIdx);
538 Scalar pressure = fluidState.pressure(phaseIdx);
539
540 switch(phaseIdx)
541 {
542 case wPhaseIdx: return WettingFluid::thermalConductivity(temperature, pressure); break;
543 case nPhaseIdx: return NonwettingFluid::thermalConductivity(temperature, pressure); break;
544 case gPhaseIdx: return Gas::thermalConductivity(temperature, pressure); break;
545 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
546 }
547 }
548
561 template <class FluidState>
562 static Scalar heatCapacity(const FluidState &fluidState,
563 int phaseIdx)
564 {
565 assert(0 <= phaseIdx && phaseIdx < numPhases);
566
567 Scalar temperature = fluidState.temperature(phaseIdx);
568 Scalar pressure = fluidState.pressure(phaseIdx);
569
570 switch(phaseIdx)
571 {
572 case wPhaseIdx: return WettingFluid::heatCapacity(temperature, pressure); break;
573 case nPhaseIdx: return NonwettingFluid::heatCapacity(temperature, pressure); break;
574 case gPhaseIdx: return Gas::heatCapacity(temperature, pressure); break;
575 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
576 }
577 }
578};
579
580} // end namespace FluidSystems
581} // end namespace Dumux
582
583#endif
A gaseous phase consisting of a single component.
A liquid phase consisting of a single component.
Fluid system base class.
Definition: fluidsystems/base.hh:33
A fluid system for three-phase models assuming immiscibility and thermodynamic equilibrium.
Definition: 3pimmiscible.hh:50
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: 3pimmiscible.hh:194
static constexpr int numPhases
Number of phases in the fluid system.
Definition: 3pimmiscible.hh:66
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: 3pimmiscible.hh:141
static constexpr int wPhaseIdx
Index of the wetting phase.
Definition: 3pimmiscible.hh:69
static constexpr void init()
Initialize the fluid system's static parameters.
Definition: 3pimmiscible.hh:282
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition: 3pimmiscible.hh:79
static constexpr int gCompIdx
Index of the gas phase's component.
Definition: 3pimmiscible.hh:187
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Return the viscosity of a phase .
Definition: 3pimmiscible.hh:395
static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp, Scalar pressMin, Scalar pressMax, unsigned nPress)
Initialize the fluid system's static parameters using problem specific temperature and pressure range...
Definition: 3pimmiscible.hh:300
static constexpr int numComponents
Number of components in the fluid system.
Definition: 3pimmiscible.hh:180
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: 3pimmiscible.hh:211
static constexpr int wCompIdx
Index of the wetting phase's component.
Definition: 3pimmiscible.hh:183
static Scalar criticalPressure(int compIdx)
Critical pressure of a component .
Definition: 3pimmiscible.hh:245
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the fugacity coefficient of an individual component in a fluid phase.
Definition: 3pimmiscible.hh:430
static constexpr int nPhaseIdx
Index of the nonwetting phase.
Definition: 3pimmiscible.hh:71
static Scalar criticalTemperature(int compIdx)
Critical temperature of a component .
Definition: 3pimmiscible.hh:228
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition: 3pimmiscible.hh:103
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition: 3pimmiscible.hh:343
static Scalar diffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase .
Definition: 3pimmiscible.hh:470
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition: 3pimmiscible.hh:96
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: 3pimmiscible.hh:562
static constexpr int gPhaseIdx
Index of the gas phase.
Definition: 3pimmiscible.hh:73
static Scalar acentricFactor(int compIdx)
The acentric factor of a component .
Definition: 3pimmiscible.hh:262
static constexpr bool isIdealGas(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: 3pimmiscible.hh:161
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
The molar density of a fluid phase in .
Definition: 3pimmiscible.hh:371
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: 3pimmiscible.hh:532
static constexpr bool isIdealMixture(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: 3pimmiscible.hh:129
static constexpr int nCompIdx
Index of the nonwetting phase's component.
Definition: 3pimmiscible.hh:185
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Return the specific enthalpy of a fluid phase .
Definition: 3pimmiscible.hh:508
static Scalar binaryDiffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIIdx, int compJIdx)
Given a phase's composition, temperature and pressure, return the binary diffusion coefficient for c...
Definition: 3pimmiscible.hh:490
Base class for all components Components provide the thermodynamic relations for the liquid,...
Represents all relevant thermodynamic quantities of a multi-phase fluid system assuming immiscibility...
A collection of input/output field names for common physical quantities.
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:39
std::string gaseousPhase() noexcept
I/O name of gaseous phase.
Definition: name.hh:111
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:62
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:71
std::string naplPhase() noexcept
I/O name of napl phase.
Definition: name.hh:119
std::string aqueousPhase() noexcept
I/O name of aqueous phase.
Definition: name.hh:115
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:22
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53
Definition: adapt.hh:17
IsAqueous struct.
Definition: components/base.hh:35