3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_3P_IMMISCIBLE_FLUID_SYSTEM_HH
25#define DUMUX_3P_IMMISCIBLE_FLUID_SYSTEM_HH
26
27#include <cassert>
28#include <limits>
29#include <iostream>
30
31#include <dune/common/exceptions.hh>
32
37#include <dumux/io/name.hh>
38
39namespace Dumux {
40namespace FluidSystems {
41
59template <class Scalar, class WettingFluid, class NonwettingFluid, class Gas>
61: public Base<Scalar, ThreePImmiscible<Scalar, WettingFluid, NonwettingFluid, Gas> >
62{
63 static_assert((WettingFluid::numPhases == 1), "WettingFluid has more than one phase");
64 static_assert((NonwettingFluid::numPhases == 1), "NonwettingFluid has more than one phase");
65 static_assert((Gas::numPhases == 1), "Gas has more than one phase");
66 static_assert((WettingFluid::numComponents == 1), "WettingFluid has more than one component");
67 static_assert((NonwettingFluid::numComponents == 1), "NonwettingFluid has more than one component");
68 static_assert((Gas::numComponents == 1), "Gas has more than one component");
69
72public:
73 /****************************************
74 * Fluid phase related static parameters
75 ****************************************/
76
78 static constexpr int numPhases = 3;
79
81 static constexpr int wPhaseIdx = 0;
83 static constexpr int nPhaseIdx = 1;
85 static constexpr int gPhaseIdx = 2;
86
91 static std::string phaseName(int phaseIdx)
92 {
93 assert(0 <= phaseIdx && phaseIdx < numPhases);
94 switch (phaseIdx)
95 {
100 case gPhaseIdx: return IOName::gaseousPhase();
101 }
102 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
103 }
104
108 static constexpr bool isMiscible()
109 { return false; }
110
115 static constexpr bool isGas(int phaseIdx)
116 {
117 assert(0 <= phaseIdx && phaseIdx < numPhases);
118
119 switch (phaseIdx)
120 {
121 case wPhaseIdx: return WettingFluid::isGas(); break;
122 case nPhaseIdx: return NonwettingFluid::isGas(); break;
123 case gPhaseIdx: return Gas::isGas(); break;
124 default: return false; // TODO: constexpr-compatible throw
125 }
126 }
127
141 static constexpr bool isIdealMixture(int phaseIdx)
142 { return true; }
143
153 static constexpr bool isCompressible(int phaseIdx)
154 {
155 assert(0 <= phaseIdx && phaseIdx < numPhases);
156
157 // let the fluids decide
158 switch(phaseIdx)
159 {
160 case wPhaseIdx: return WettingFluid::isCompressible(); break;
161 case nPhaseIdx: return NonwettingFluid::isCompressible(); break;
162 case gPhaseIdx: return Gas::isCompressible(); break;
163 default: return false; // TODO: constexpr-compatible throw
164 }
165 }
166
173 static constexpr bool isIdealGas(int phaseIdx)
174 {
175 assert(0 <= phaseIdx && phaseIdx < numPhases);
176
177 // let the fluids decide
178 switch(phaseIdx)
179 {
180 case wPhaseIdx: return WettingFluid::isIdealGas(); break;
181 case nPhaseIdx: return NonwettingFluid::isIdealGas(); break;
182 case gPhaseIdx: return Gas::isIdealGas(); break;
183 default: return false; // TODO: constexpr-compatible throw
184 }
185 }
186
187 /****************************************
188 * Component related static parameters
189 ****************************************/
190
192 static constexpr int numComponents = 3;//WettingFluid::numComponents + NonwettingFluid::numComponents + Gas::numComponents; // TODO: 3??
193
195 static constexpr int wCompIdx = 0;
197 static constexpr int nCompIdx = 1;
199 static constexpr int gCompIdx = 2; // TODO: correct??
200
206 static std::string componentName(int compIdx)
207 {
208 assert(0 <= compIdx && compIdx < numComponents);
209
210 switch(compIdx)
211 {
212 case wCompIdx: return WettingFluid::name(); break;
213 case nCompIdx: return NonwettingFluid::name(); break;
214 case gCompIdx: return Gas::name(); break;
215 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
216 }
217 }
218
223 static Scalar molarMass(int compIdx)
224 {
225 assert(0 <= compIdx && compIdx < numComponents);
226
227 switch(compIdx)
228 {
229 case wCompIdx: return WettingFluid::molarMass(); break;
230 case nCompIdx: return NonwettingFluid::molarMass(); break;
231 case gCompIdx: return Gas::molarMass(); break;
232 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
233 }
234 }
235
240 static Scalar criticalTemperature(int compIdx)
241 {
242 assert(0 <= compIdx && compIdx < numComponents);
243
244 switch(compIdx)
245 {
246 case wCompIdx: return WettingFluid::criticalTemperature(); break;
247 case nCompIdx: return NonwettingFluid::criticalTemperature(); break;
248 case gCompIdx: return Gas::criticalTemperature(); break;
249 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
250 }
251 }
252
257 static Scalar criticalPressure(int compIdx)
258 {
259 assert(0 <= compIdx && compIdx < numComponents);
260
261 switch(compIdx)
262 {
263 case wCompIdx: return WettingFluid::criticalPressure(); break;
264 case nCompIdx: return NonwettingFluid::criticalPressure(); break;
265 case gCompIdx: return Gas::criticalPressure(); break;
266 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
267 }
268 }
269
274 static Scalar acentricFactor(int compIdx)
275 {
276 assert(0 <= compIdx && compIdx < numComponents);
277
278 switch(compIdx)
279 {
280 case wCompIdx: return WettingFluid::Component::acentricFactor(); break;
281 case nCompIdx: return NonwettingFluid::Component::acentricFactor(); break;
282 case gCompIdx: return Gas::Component::acentricFactor(); break;
283 default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index");
284 }
285 }
286
287 /****************************************
288 * thermodynamic relations
289 ****************************************/
290
294 static constexpr void init()
295 {
296 // two gaseous phases at once do not make sense physically!
297 // (But two liquids are fine)
298 static_assert(!WettingFluid::isGas() && !NonwettingFluid::isGas() && Gas::isGas(), "There can only be one gaseous phase!");
299 }
300
312 static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
313 Scalar pressMin, Scalar pressMax, unsigned nPress)
314 {
315 // two gaseous phases at once do not make sense physically!
316 static_assert(!WettingFluid::isGas() && !NonwettingFluid::isGas() && Gas::isGas(), "There can only be one gaseous phase!");
317
318 if (WettingFluid::Component::isTabulated)
319 {
320 std::cout << "Initializing tables for the wetting fluid properties ("
321 << nTemp*nPress
322 << " entries).\n";
323
324 WettingFluid::Component::init(tempMin, tempMax, nTemp,
325 pressMin, pressMax, nPress);
326
327 }
328
329 if (NonwettingFluid::Component::isTabulated)
330 {
331 std::cout << "Initializing tables for the nonwetting fluid properties ("
332 << nTemp*nPress
333 << " entries).\n";
334
335 NonwettingFluid::Component::init(tempMin, tempMax, nTemp,
336 pressMin, pressMax, nPress);
337
338 }
339
340 if (Gas::Component::isTabulated)
341 {
342 std::cout << "Initializing tables for the gas fluid properties ("
343 << nTemp*nPress
344 << " entries).\n";
345
346 Gas::Component::init(tempMin, tempMax, nTemp,
347 pressMin, pressMax, nPress);
348
349 }
350 }
351
352 using Base::density;
357 template <class FluidState>
358 static Scalar density(const FluidState &fluidState,
359 int phaseIdx)
360 {
361 assert(0 <= phaseIdx && phaseIdx < numPhases);
362
363 Scalar temperature = fluidState.temperature(phaseIdx);
364 Scalar pressure = fluidState.pressure(phaseIdx);
365
366 switch(phaseIdx)
367 {
370 case gPhaseIdx: return Gas::density(temperature, pressure); break;
371 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
372 }
373 }
374
375 using Base::molarDensity;
385 template <class FluidState>
386 static Scalar molarDensity(const FluidState &fluidState,
387 int phaseIdx)
388 {
389 assert(0 <= phaseIdx && phaseIdx < numPhases);
390
391 Scalar temperature = fluidState.temperature(phaseIdx);
392 Scalar pressure = fluidState.pressure(phaseIdx);
393
394 switch(phaseIdx)
395 {
399 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
400 }
401 }
402
403 using Base::viscosity;
409 template <class FluidState>
410 static Scalar viscosity(const FluidState &fluidState,
411 int phaseIdx)
412 {
413 assert(0 <= phaseIdx && phaseIdx < numPhases);
414
415 Scalar temperature = fluidState.temperature(phaseIdx);
416 Scalar pressure = fluidState.pressure(phaseIdx);
417
418 switch(phaseIdx)
419 {
422 case gPhaseIdx: return Gas::viscosity(temperature, pressure); break;
423 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
424 }
425 }
426
444 template <class FluidState>
445 static Scalar fugacityCoefficient(const FluidState &fluidState,
446 int phaseIdx,
447 int compIdx)
448 {
449 assert(0 <= phaseIdx && phaseIdx < numPhases);
450 assert(0 <= compIdx && compIdx < numComponents);
451
452 if (phaseIdx == compIdx)
453 // We could calculate the real fugacity coefficient of
454 // the component in the fluid. Probably that's not worth
455 // the effort, since the fugacity coefficient of the other
456 // component is infinite anyway...
457 return 1.0;
458 return std::numeric_limits<Scalar>::infinity();
459 }
460
484 template <class FluidState>
485 static Scalar diffusionCoefficient(const FluidState &fluidState,
486 int phaseIdx,
487 int compIdx)
488 {
489 DUNE_THROW(Dune::InvalidStateException,
490 "Diffusion coefficients of components are meaningless if"
491 " immiscibility is assumed");
492 }
493
504 template <class FluidState>
505 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
506 int phaseIdx,
507 int compIIdx,
508 int compJIdx)
509
510 {
511 DUNE_THROW(Dune::InvalidStateException,
512 "Binary diffusion coefficients of components are meaningless if"
513 " immiscibility is assumed");
514 }
515
516 using Base::enthalpy;
522 template <class FluidState>
523 static Scalar enthalpy(const FluidState &fluidState,
524 int phaseIdx)
525 {
526 assert(0 <= phaseIdx && phaseIdx < numPhases);
527
528 Scalar temperature = fluidState.temperature(phaseIdx);
529 Scalar pressure = fluidState.pressure(phaseIdx);
530
531 switch(phaseIdx)
532 {
533 case wPhaseIdx: return WettingFluid::enthalpy(temperature, pressure); break;
534 case nPhaseIdx: return NonwettingFluid::enthalpy(temperature, pressure); break;
535 case gPhaseIdx: return Gas::enthalpy(temperature, pressure); break;
536 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
537 }
538 }
539
546 template <class FluidState>
547 static Scalar thermalConductivity(const FluidState &fluidState,
548 int phaseIdx)
549 {
550 assert(0 <= phaseIdx && phaseIdx < numPhases);
551
552 Scalar temperature = fluidState.temperature(phaseIdx);
553 Scalar pressure = fluidState.pressure(phaseIdx);
554
555 switch(phaseIdx)
556 {
557 case wPhaseIdx: return WettingFluid::thermalConductivity(temperature, pressure); break;
558 case nPhaseIdx: return NonwettingFluid::thermalConductivity(temperature, pressure); break;
559 case gPhaseIdx: return Gas::thermalConductivity(temperature, pressure); break;
560 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
561 }
562 }
563
564 using Base::heatCapacity;
576 template <class FluidState>
577 static Scalar heatCapacity(const FluidState &fluidState,
578 int phaseIdx)
579 {
580 assert(0 <= phaseIdx && phaseIdx < numPhases);
581
582 Scalar temperature = fluidState.temperature(phaseIdx);
583 Scalar pressure = fluidState.pressure(phaseIdx);
584
585 switch(phaseIdx)
586 {
587 case wPhaseIdx: return WettingFluid::heatCapacity(temperature, pressure); break;
588 case nPhaseIdx: return NonwettingFluid::heatCapacity(temperature, pressure); break;
589 case gPhaseIdx: return Gas::heatCapacity(temperature, pressure); break;
590 default: DUNE_THROW(Dune::InvalidStateException, "Invalid phase index");
591 }
592 }
593};
594
595} // end namespace FluidSystems
596} // end namespace Dumux
597
598#endif
A collection of input/output field names for common physical quantities.
Represents all relevant thermodynamic quantities of a multi-phase fluid system assuming immiscibility...
A liquid phase consisting of a single component.
A gaseous phase consisting of a single component.
Definition: adapt.hh:29
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51
std::string gaseousPhase() noexcept
I/O name of gaseous phase.
Definition: name.hh:123
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:74
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:83
std::string naplPhase() noexcept
I/O name of napl phase.
Definition: name.hh:131
std::string aqueousPhase() noexcept
I/O name of aqueous phase.
Definition: name.hh:127
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:34
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
IsAqueous struct.
Definition: components/base.hh:47
A fluid system for three-phase models assuming immiscibility and thermodynamic equilibrium.
Definition: 3pimmiscible.hh:62
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: 3pimmiscible.hh:206
static constexpr int numPhases
Number of phases in the fluid system.
Definition: 3pimmiscible.hh:78
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: 3pimmiscible.hh:153
static constexpr int wPhaseIdx
Index of the wetting phase.
Definition: 3pimmiscible.hh:81
static constexpr void init()
Initialize the fluid system's static parameters.
Definition: 3pimmiscible.hh:294
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition: 3pimmiscible.hh:91
static constexpr int gCompIdx
Index of the gas phase's component.
Definition: 3pimmiscible.hh:199
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Return the viscosity of a phase .
Definition: 3pimmiscible.hh:410
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:312
static constexpr int numComponents
Number of components in the fluid system.
Definition: 3pimmiscible.hh:192
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: 3pimmiscible.hh:223
static constexpr int wCompIdx
Index of the wetting phase's component.
Definition: 3pimmiscible.hh:195
static Scalar criticalPressure(int compIdx)
Critical pressure of a component .
Definition: 3pimmiscible.hh:257
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:445
static constexpr int nPhaseIdx
Index of the nonwetting phase.
Definition: 3pimmiscible.hh:83
static Scalar criticalTemperature(int compIdx)
Critical temperature of a component .
Definition: 3pimmiscible.hh:240
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition: 3pimmiscible.hh:115
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition: 3pimmiscible.hh:358
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:485
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition: 3pimmiscible.hh:108
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: 3pimmiscible.hh:577
static constexpr int gPhaseIdx
Index of the gas phase.
Definition: 3pimmiscible.hh:85
static Scalar acentricFactor(int compIdx)
The acentric factor of a component .
Definition: 3pimmiscible.hh:274
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:173
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
The molar density of a fluid phase in .
Definition: 3pimmiscible.hh:386
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: 3pimmiscible.hh:547
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:141
static constexpr int nCompIdx
Index of the nonwetting phase's component.
Definition: 3pimmiscible.hh:197
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Return the specific enthalpy of a fluid phase .
Definition: 3pimmiscible.hh:523
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:505
Fluid system base class.
Definition: fluidsystems/base.hh:45
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition: fluidsystems/base.hh:134
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: fluidsystems/base.hh:390
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the fugacity coefficient of an individual component in a fluid phase.
Definition: fluidsystems/base.hh:197
static Scalar diffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase .
Definition: fluidsystems/base.hh:278
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: fluidsystems/base.hh:326
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature, pressure and density, calculate its specific enthalpy .
Definition: fluidsystems/base.hh:363
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
Calculate the molar density of a fluid phase.
Definition: fluidsystems/base.hh:160
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: fluidsystems/base.hh:236
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: fluidsystems/base.hh:424
Base class for all components Components provide the thermodynamic relations for the liquid,...