version 3.10.0
Loading...
Searching...
No Matches
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-FileCopyrightText: 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::FluidSystems {
28
46template <class Scalar, class WettingFluid, class NonwettingFluid, class Gas>
48: public Base<Scalar, ThreePImmiscible<Scalar, WettingFluid, NonwettingFluid, Gas> >
49{
50 static_assert((WettingFluid::numPhases == 1), "WettingFluid has more than one phase");
51 static_assert((NonwettingFluid::numPhases == 1), "NonwettingFluid has more than one phase");
52 static_assert((Gas::numPhases == 1), "Gas has more than one phase");
53 static_assert((WettingFluid::numComponents == 1), "WettingFluid has more than one component");
54 static_assert((NonwettingFluid::numComponents == 1), "NonwettingFluid has more than one component");
55 static_assert((Gas::numComponents == 1), "Gas has more than one component");
56
58
59public:
60 /****************************************
61 * Fluid phase related static parameters
62 ****************************************/
63
65 static constexpr int numPhases = 3;
66
68 static constexpr int wPhaseIdx = 0;
70 static constexpr int nPhaseIdx = 1;
72 static constexpr int gPhaseIdx = 2;
73
78 static std::string phaseName(int phaseIdx)
79 {
80 assert(0 <= phaseIdx && phaseIdx < numPhases);
81 switch (phaseIdx)
82 {
87 case gPhaseIdx: return IOName::gaseousPhase();
88 }
89 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
90 }
91
95 static constexpr bool isMiscible()
96 { return false; }
97
102 static constexpr bool isGas(int phaseIdx)
103 {
104 assert(0 <= phaseIdx && phaseIdx < numPhases);
105
106 switch (phaseIdx)
107 {
108 case wPhaseIdx: return WettingFluid::isGas(); break;
109 case nPhaseIdx: return NonwettingFluid::isGas(); break;
110 case gPhaseIdx: return Gas::isGas(); break;
111 default: return false; // TODO: constexpr-compatible throw
112 }
113 }
114
128 static constexpr bool isIdealMixture(int phaseIdx)
129 { return true; }
130
140 static constexpr bool isCompressible(int phaseIdx)
141 {
142 assert(0 <= phaseIdx && phaseIdx < numPhases);
143
144 // let the fluids decide
145 switch(phaseIdx)
146 {
147 case wPhaseIdx: return WettingFluid::isCompressible(); break;
148 case nPhaseIdx: return NonwettingFluid::isCompressible(); break;
149 case gPhaseIdx: return Gas::isCompressible(); break;
150 default: return false; // TODO: constexpr-compatible throw
151 }
152 }
153
160 static constexpr bool isIdealGas(int phaseIdx)
161 {
162 assert(0 <= phaseIdx && phaseIdx < numPhases);
163
164 // let the fluids decide
165 switch(phaseIdx)
166 {
167 case wPhaseIdx: return WettingFluid::isIdealGas(); break;
168 case nPhaseIdx: return NonwettingFluid::isIdealGas(); break;
169 case gPhaseIdx: return Gas::isIdealGas(); break;
170 default: return false; // TODO: constexpr-compatible throw
171 }
172 }
173
174 /****************************************
175 * Component related static parameters
176 ****************************************/
177
179 static constexpr int numComponents = 3;//WettingFluid::numComponents + NonwettingFluid::numComponents + Gas::numComponents; // TODO: 3??
180
182 static constexpr int wCompIdx = 0;
184 static constexpr int nCompIdx = 1;
186 static constexpr int gCompIdx = 2; // TODO: correct??
187
193 static std::string componentName(int compIdx)
194 {
195 assert(0 <= compIdx && compIdx < numComponents);
196
197 switch(compIdx)
198 {
199 case wCompIdx: return WettingFluid::name(); break;
200 case nCompIdx: return NonwettingFluid::name(); break;
201 case gCompIdx: return Gas::name(); break;
202 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
203 }
204 }
205
210 static Scalar molarMass(int compIdx)
211 {
212 assert(0 <= compIdx && compIdx < numComponents);
213
214 switch(compIdx)
215 {
216 case wCompIdx: return WettingFluid::molarMass(); break;
217 case nCompIdx: return NonwettingFluid::molarMass(); break;
218 case gCompIdx: return Gas::molarMass(); break;
219 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
220 }
221 }
222
227 static Scalar criticalTemperature(int compIdx)
228 {
229 assert(0 <= compIdx && compIdx < numComponents);
230
231 switch(compIdx)
232 {
233 case wCompIdx: return WettingFluid::criticalTemperature(); break;
234 case nCompIdx: return NonwettingFluid::criticalTemperature(); break;
235 case gCompIdx: return Gas::criticalTemperature(); break;
236 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
237 }
238 }
239
244 static Scalar criticalPressure(int compIdx)
245 {
246 assert(0 <= compIdx && compIdx < numComponents);
247
248 switch(compIdx)
249 {
250 case wCompIdx: return WettingFluid::criticalPressure(); break;
251 case nCompIdx: return NonwettingFluid::criticalPressure(); break;
252 case gCompIdx: return Gas::criticalPressure(); break;
253 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
254 }
255 }
256
261 static Scalar acentricFactor(int compIdx)
262 {
263 assert(0 <= compIdx && compIdx < numComponents);
264
265 switch(compIdx)
266 {
267 case wCompIdx: return WettingFluid::Component::acentricFactor(); break;
268 case nCompIdx: return NonwettingFluid::Component::acentricFactor(); break;
269 case gCompIdx: return Gas::Component::acentricFactor(); break;
270 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
271 }
272 }
273
274 /****************************************
275 * thermodynamic relations
276 ****************************************/
277
281 static constexpr void init()
282 {
283 // two gaseous phases at once do not make sense physically!
284 // (But two liquids are fine)
285 static_assert(!WettingFluid::isGas() && !NonwettingFluid::isGas() && Gas::isGas(), "There can only be one gaseous phase!");
286 }
287
299 static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
300 Scalar pressMin, Scalar pressMax, unsigned nPress)
301 {
302 // two gaseous phases at once do not make sense physically!
303 static_assert(!WettingFluid::isGas() && !NonwettingFluid::isGas() && Gas::isGas(), "There can only be one gaseous phase!");
304
305 if (WettingFluid::Component::isTabulated)
306 {
307 std::cout << "Initializing tables for the wetting fluid properties ("
308 << nTemp*nPress
309 << " entries).\n";
310
311 WettingFluid::Component::init(tempMin, tempMax, nTemp,
312 pressMin, pressMax, nPress);
313
314 }
315
316 if (NonwettingFluid::Component::isTabulated)
317 {
318 std::cout << "Initializing tables for the nonwetting fluid properties ("
319 << nTemp*nPress
320 << " entries).\n";
321
322 NonwettingFluid::Component::init(tempMin, tempMax, nTemp,
323 pressMin, pressMax, nPress);
324
325 }
326
327 if (Gas::Component::isTabulated)
328 {
329 std::cout << "Initializing tables for the gas fluid properties ("
330 << nTemp*nPress
331 << " entries).\n";
332
333 Gas::Component::init(tempMin, tempMax, nTemp,
334 pressMin, pressMax, nPress);
335
336 }
337 }
338
339 using Base<Scalar, ThisType>::density;
341 template <class FluidState>
342 static Scalar density(const FluidState &fluidState,
343 int phaseIdx)
344 {
345 assert(0 <= phaseIdx && phaseIdx < numPhases);
346
347 Scalar temperature = fluidState.temperature(phaseIdx);
348 Scalar pressure = fluidState.pressure(phaseIdx);
349
350 switch(phaseIdx)
351 {
352 case wPhaseIdx: return WettingFluid::density(temperature, pressure); break;
353 case nPhaseIdx: return NonwettingFluid::density(temperature, pressure); break;
354 case gPhaseIdx: return Gas::density(temperature, pressure); break;
355 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
356 }
357 }
358
359 using Base<Scalar, ThisType>::molarDensity;
369 template <class FluidState>
370 static Scalar molarDensity(const FluidState &fluidState,
371 int phaseIdx)
372 {
373 assert(0 <= phaseIdx && phaseIdx < numPhases);
374
375 Scalar temperature = fluidState.temperature(phaseIdx);
376 Scalar pressure = fluidState.pressure(phaseIdx);
377
378 switch(phaseIdx)
379 {
380 case wPhaseIdx: return WettingFluid::molarDensity(temperature, pressure);
381 case nPhaseIdx: return NonwettingFluid::molarDensity(temperature, pressure);
382 case gPhaseIdx: return Gas::molarDensity(temperature, pressure);
383 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
384 }
385 }
386
387 using Base<Scalar, ThisType>::viscosity;
393 template <class FluidState>
394 static Scalar viscosity(const FluidState &fluidState,
395 int phaseIdx)
396 {
397 assert(0 <= phaseIdx && phaseIdx < numPhases);
398
399 Scalar temperature = fluidState.temperature(phaseIdx);
400 Scalar pressure = fluidState.pressure(phaseIdx);
401
402 switch(phaseIdx)
403 {
404 case wPhaseIdx: return WettingFluid::viscosity(temperature, pressure); break;
405 case nPhaseIdx: return NonwettingFluid::viscosity(temperature, pressure); break;
406 case gPhaseIdx: return Gas::viscosity(temperature, pressure); break;
407 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
408 }
409 }
410
411 using Base<Scalar, ThisType>::fugacityCoefficient;
428 template <class FluidState>
429 static Scalar fugacityCoefficient(const FluidState &fluidState,
430 int phaseIdx,
431 int compIdx)
432 {
433 assert(0 <= phaseIdx && phaseIdx < numPhases);
434 assert(0 <= compIdx && compIdx < numComponents);
435
436 if (phaseIdx == compIdx)
437 // We could calculate the real fugacity coefficient of
438 // the component in the fluid. Probably that's not worth
439 // the effort, since the fugacity coefficient of the other
440 // component is infinite anyway...
441 return 1.0;
442 return std::numeric_limits<Scalar>::infinity();
443 }
444
445 using Base<Scalar, ThisType>::diffusionCoefficient;
468 template <class FluidState>
469 static Scalar diffusionCoefficient(const FluidState &fluidState,
470 int phaseIdx,
471 int compIdx)
472 {
473 DUNE_THROW(Dune::InvalidStateException,
474 "Diffusion coefficients of components are meaningless if"
475 " immiscibility is assumed");
476 }
477
488 template <class FluidState>
489 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
490 int phaseIdx,
491 int compIIdx,
492 int compJIdx)
493
494 {
495 DUNE_THROW(Dune::InvalidStateException,
496 "Binary diffusion coefficients of components are meaningless if"
497 " immiscibility is assumed");
498 }
499
500 using Base<Scalar, ThisType>::enthalpy;
506 template <class FluidState>
507 static Scalar enthalpy(const FluidState &fluidState,
508 int phaseIdx)
509 {
510 assert(0 <= phaseIdx && phaseIdx < numPhases);
511
512 Scalar temperature = fluidState.temperature(phaseIdx);
513 Scalar pressure = fluidState.pressure(phaseIdx);
514
515 switch(phaseIdx)
516 {
517 case wPhaseIdx: return WettingFluid::enthalpy(temperature, pressure); break;
518 case nPhaseIdx: return NonwettingFluid::enthalpy(temperature, pressure); break;
519 case gPhaseIdx: return Gas::enthalpy(temperature, pressure); break;
520 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
521 }
522 }
523
524 using Base<Scalar, ThisType>::thermalConductivity;
530 template <class FluidState>
531 static Scalar thermalConductivity(const FluidState &fluidState,
532 int phaseIdx)
533 {
534 assert(0 <= phaseIdx && phaseIdx < numPhases);
535
536 Scalar temperature = fluidState.temperature(phaseIdx);
537 Scalar pressure = fluidState.pressure(phaseIdx);
538
539 switch(phaseIdx)
540 {
541 case wPhaseIdx: return WettingFluid::thermalConductivity(temperature, pressure); break;
542 case nPhaseIdx: return NonwettingFluid::thermalConductivity(temperature, pressure); break;
543 case gPhaseIdx: return Gas::thermalConductivity(temperature, pressure); break;
544 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
545 }
546 }
547
548 using Base<Scalar, ThisType>::heatCapacity;
560 template <class FluidState>
561 static Scalar heatCapacity(const FluidState &fluidState,
562 int phaseIdx)
563 {
564 assert(0 <= phaseIdx && phaseIdx < numPhases);
565
566 Scalar temperature = fluidState.temperature(phaseIdx);
567 Scalar pressure = fluidState.pressure(phaseIdx);
568
569 switch(phaseIdx)
570 {
571 case wPhaseIdx: return WettingFluid::heatCapacity(temperature, pressure); break;
572 case nPhaseIdx: return NonwettingFluid::heatCapacity(temperature, pressure); break;
573 case gPhaseIdx: return Gas::heatCapacity(temperature, pressure); break;
574 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
575 }
576 }
577};
578
579} // end namespace Dumux::FluidSystems
580
581#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:32
A fluid system for three-phase models assuming immiscibility and thermodynamic equilibrium.
Definition 3pimmiscible.hh:49
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition 3pimmiscible.hh:193
static constexpr int numPhases
Number of phases in the fluid system.
Definition 3pimmiscible.hh:65
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition 3pimmiscible.hh:140
static constexpr int wPhaseIdx
Index of the wetting phase.
Definition 3pimmiscible.hh:68
static constexpr void init()
Initialize the fluid system's static parameters.
Definition 3pimmiscible.hh:281
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition 3pimmiscible.hh:78
static constexpr int gCompIdx
Index of the gas phase's component.
Definition 3pimmiscible.hh:186
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Return the viscosity of a phase .
Definition 3pimmiscible.hh:394
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:299
static constexpr int numComponents
Number of components in the fluid system.
Definition 3pimmiscible.hh:179
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition 3pimmiscible.hh:210
static constexpr int wCompIdx
Index of the wetting phase's component.
Definition 3pimmiscible.hh:182
static Scalar criticalPressure(int compIdx)
Critical pressure of a component .
Definition 3pimmiscible.hh:244
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:429
static constexpr int nPhaseIdx
Index of the nonwetting phase.
Definition 3pimmiscible.hh:70
static Scalar criticalTemperature(int compIdx)
Critical temperature of a component .
Definition 3pimmiscible.hh:227
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition 3pimmiscible.hh:102
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition 3pimmiscible.hh:342
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:469
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition 3pimmiscible.hh:95
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition 3pimmiscible.hh:561
static constexpr int gPhaseIdx
Index of the gas phase.
Definition 3pimmiscible.hh:72
static Scalar acentricFactor(int compIdx)
The acentric factor of a component .
Definition 3pimmiscible.hh:261
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:160
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
The molar density of a fluid phase in .
Definition 3pimmiscible.hh:370
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition 3pimmiscible.hh:531
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:128
static constexpr int nCompIdx
Index of the nonwetting phase's component.
Definition 3pimmiscible.hh:184
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Return the specific enthalpy of a fluid phase .
Definition 3pimmiscible.hh:507
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:489
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.
Definition h2o.hh:901
std::string gaseousPhase() noexcept
I/O name of gaseous phase.
Definition name.hh:111
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
IsAqueous struct.
Definition components/base.hh:34