version 3.8
2pimmiscible.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_2P_IMMISCIBLE_FLUID_SYSTEM_HH
13#define DUMUX_2P_IMMISCIBLE_FLUID_SYSTEM_HH
14
15#include <limits>
16#include <cassert>
17
18#include <dune/common/exceptions.hh>
19
24#include <dumux/io/name.hh>
25
26#include "base.hh"
27
28namespace Dumux {
29namespace FluidSystems {
30
44template <class Scalar, class Fluid0, class Fluid1>
46: public Base<Scalar, TwoPImmiscible<Scalar, Fluid0, Fluid1> >
47{
48 static_assert((Fluid0::numPhases == 1), "Fluid0 has more than one phase");
49 static_assert((Fluid1::numPhases == 1), "Fluid1 has more than one phase");
50 static_assert((Fluid0::numComponents == 1), "Fluid0 has more than one component");
51 static_assert((Fluid1::numComponents == 1), "Fluid1 has more than one component");
52 // two gaseous phases at once do not make sense physically! (but two liquids are fine)
53 static_assert(!Fluid0::isGas() || !Fluid1::isGas(), "One phase has to be a liquid!");
54
56
57public:
58 static constexpr int numPhases = 2;
59 static constexpr int numComponents = 2;
60
61 static constexpr int phase0Idx = 0;
62 static constexpr int phase1Idx = 1;
63 static constexpr int comp0Idx = 0;
64 static constexpr int comp1Idx = 1;
65
66 /****************************************
67 * Fluid phase related static parameters
68 ****************************************/
73 static std::string phaseName(int phaseIdx)
74 {
75 assert(0 <= phaseIdx && phaseIdx < numPhases);
76
77 if (!Fluid0::isGas() && !Fluid1::isGas())
78 {
81
82 if (name0 != name1)
83 return (phaseIdx == phase0Idx) ? name0 : name1;
84 else
85 return (phaseIdx == phase0Idx) ? name0 + "_0" : name1 + "_1";
86 }
87 else
88 {
89 if (phaseIdx == phase0Idx)
90 return Fluid0::isGas() ? IOName::gaseousPhase() : IOName::liquidPhase();
91 else
92 return Fluid1::isGas() ? IOName::gaseousPhase() : IOName::liquidPhase();
93 }
94 }
95
99 static constexpr bool isMiscible()
100 { return false; }
101
106 static constexpr bool isGas(int phaseIdx)
107 {
108 assert(0 <= phaseIdx && phaseIdx < numPhases);
109
110 if (phaseIdx == phase0Idx)
111 return Fluid0::isGas();
112 return Fluid1::isGas();
113 }
114
128 static bool isIdealMixture(int phaseIdx)
129 {
130 assert(0 <= phaseIdx && phaseIdx < numPhases);
131
132 // we assume immisibility
133 return true;
134 }
135
142 static constexpr bool isIdealGas(int phaseIdx)
143 {
144 assert(0 <= phaseIdx && phaseIdx < numPhases);
145
146 // let the fluids decide
147 if (phaseIdx == phase0Idx)
148 return Fluid0::isIdealGas();
149 return Fluid1::isIdealGas();
150 }
151
161 static constexpr bool isCompressible(int phaseIdx)
162 {
163 assert(0 <= phaseIdx && phaseIdx < numPhases);
164
165 // let the fluids decide
166 if (phaseIdx == phase0Idx)
167 return Fluid0::isCompressible();
168 return Fluid1::isCompressible();
169 }
170
176 static constexpr bool viscosityIsConstant(int phaseIdx)
177 {
178 assert(0 <= phaseIdx && phaseIdx < numPhases);
179
180 // let the fluids decide
181 if (phaseIdx == phase0Idx)
182 return Fluid0::viscosityIsConstant();
183 return Fluid1::viscosityIsConstant();
184 }
185
192 static bool isIdealFluid1(int phaseIdx)
193 {
194 assert(0 <= phaseIdx && phaseIdx < numPhases);
195
196 // let the fluids decide
197 if (phaseIdx == phase0Idx)
198 return Fluid0::isIdealFluid1();
199 return Fluid1::isIdealFluid1();
200 }
201
202 /****************************************
203 * Component related static parameters
204 ****************************************/
210 static std::string componentName(int compIdx)
211 {
212 assert(0 <= compIdx && compIdx < numComponents);
213
214 if (compIdx == comp0Idx)
215 return Fluid0::name();
216 return Fluid1::name();
217 }
218
223 static Scalar molarMass(int compIdx)
224 {
225 assert(0 <= compIdx && compIdx < numComponents);
226
227 if (compIdx == comp0Idx)
228 return Fluid0::molarMass();
229 return Fluid1::molarMass();
230 }
231
236 static Scalar criticalTemperature(int compIdx)
237 {
238 assert(0 <= compIdx && compIdx < numComponents);
239
240 if (compIdx == comp0Idx)
241 return Fluid0::criticalTemperature();
242 return Fluid1::criticalTemperature();
243 }
244
249 static Scalar criticalPressure(int compIdx)
250 {
251 assert(0 <= compIdx && compIdx < numComponents);
252
253 if (compIdx == comp0Idx)
254 return Fluid0::criticalPressure();
255 return Fluid1::criticalPressure();
256 }
257
262 static Scalar acentricFactor(int compIdx)
263 {
264 assert(0 <= compIdx && compIdx < numComponents);
265
266 if (compIdx == comp0Idx)
267 return Fluid0::acentricFactor();
268 return Fluid1::acentricFactor();
269 }
270
271 /****************************************
272 * thermodynamic relations
273 ****************************************/
274
278 static void init()
279 {
280 // initialize with some default values
281 init(/*tempMin=*/273.15, /*tempMax=*/623.15, /*numTemp=*/100,
282 /*pMin=*/-10.0, /*pMax=*/20e6, /*numP=*/200);
283 }
284
296 static void init(Scalar tempMin, Scalar tempMax, std::size_t nTemp,
297 Scalar pressMin, Scalar pressMax, std::size_t nPress)
298 {
299 if (Fluid0::Component::isTabulated)
300 Fluid0::Component::init(tempMin, tempMax, nTemp, pressMin, pressMax, nPress);
301
302 if (Fluid1::Component::isTabulated)
303 Fluid1::Component::init(tempMin, tempMax, nTemp, pressMin, pressMax, nPress);
304 }
305
308 template <class FluidState>
309 static Scalar density(const FluidState &fluidState,
310 int phaseIdx)
311 {
312 assert(0 <= phaseIdx && phaseIdx < numPhases);
313
314 Scalar temperature = fluidState.temperature(phaseIdx);
315 Scalar pressure = fluidState.pressure(phaseIdx);
316 if (phaseIdx == phase0Idx)
319 }
320
323 template <class FluidState>
324 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
325 {
326 Scalar temperature = fluidState.temperature(phaseIdx);
327 Scalar pressure = fluidState.pressure(phaseIdx);
328 if (phaseIdx == phase0Idx)
331 }
332
335 template <class FluidState>
336 static Scalar viscosity(const FluidState &fluidState,
337 int phaseIdx)
338 {
339 assert(0 <= phaseIdx && phaseIdx < numPhases);
340
341 Scalar temperature = fluidState.temperature(phaseIdx);
342 Scalar pressure = fluidState.pressure(phaseIdx);
343 if (phaseIdx == phase0Idx)
346 }
347
350 template <class FluidState>
351 static Scalar fugacityCoefficient(const FluidState &fluidState,
352 int phaseIdx,
353 int compIdx)
354 {
355 assert(0 <= phaseIdx && phaseIdx < numPhases);
356 assert(0 <= compIdx && compIdx < numComponents);
357
358 if (phaseIdx == compIdx)
359 // We could calculate the real fugacity coefficient of
360 // the component in the fluid. Probably that's not worth
361 // the effort, since the fugacity coefficient of the other
362 // component is infinite anyway...
363 return 1.0;
364 return std::numeric_limits<Scalar>::infinity();
365 }
366
369 template <class FluidState>
370 static Scalar diffusionCoefficient(const FluidState &fluidState,
371 int phaseIdx,
372 int compIdx)
373 {
374 DUNE_THROW(Dune::InvalidStateException,
375 "Diffusion coefficients of components are meaningless if"
376 " immiscibility is assumed");
377 }
378
381 template <class FluidState>
382 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
383 int phaseIdx,
384 int compIIdx,
385 int compJIdx)
386
387 {
388 DUNE_THROW(Dune::InvalidStateException,
389 "Binary diffusion coefficients of components are meaningless if"
390 " immiscibility is assumed");
391 }
392
395 template <class FluidState>
396 static Scalar enthalpy(const FluidState &fluidState,
397 int phaseIdx)
398 {
399 assert(0 <= phaseIdx && phaseIdx < numPhases);
400
401 Scalar temperature = fluidState.temperature(phaseIdx);
402 Scalar pressure = fluidState.pressure(phaseIdx);
403 if (phaseIdx == phase0Idx)
404 return Fluid0::enthalpy(temperature, pressure);
405 return Fluid1::enthalpy(temperature, pressure);
406 }
407
410 template <class FluidState>
411 static Scalar thermalConductivity(const FluidState &fluidState,
412 int phaseIdx)
413 {
414 assert(0 <= phaseIdx && phaseIdx < numPhases);
415
416 Scalar temperature = fluidState.temperature(phaseIdx);
417 Scalar pressure = fluidState.pressure(phaseIdx);
418 if (phaseIdx == phase0Idx)
419 return Fluid0::thermalConductivity(temperature, pressure);
420 return Fluid1::thermalConductivity(temperature, pressure);
421 }
422
425 template <class FluidState>
426 static Scalar heatCapacity(const FluidState &fluidState,
427 int phaseIdx)
428 {
429 assert(0 <= phaseIdx && phaseIdx < numPhases);
430
431 Scalar temperature = fluidState.temperature(phaseIdx);
432 Scalar pressure = fluidState.pressure(phaseIdx);
433 if (phaseIdx == phase0Idx)
434 return Fluid0::heatCapacity(temperature, pressure);
435 return Fluid1::heatCapacity(temperature, pressure);
436 }
437};
438
439} // end namespace FluidSystems
440} // end namespace Dumux
441
442#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
Scalar Scalar
export the scalar type
Definition: fluidsystems/base.hh:36
A fluid system for two-phase models assuming immiscibility and thermodynamic equilibrium.
Definition: 2pimmiscible.hh:47
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: 2pimmiscible.hh:382
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition: 2pimmiscible.hh:73
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: 2pimmiscible.hh:210
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: 2pimmiscible.hh:161
static Scalar acentricFactor(int compIdx)
The acentric factor of a component .
Definition: 2pimmiscible.hh:262
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature, pressure and density, calculate its specific enthalpy .
Definition: 2pimmiscible.hh:396
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition: 2pimmiscible.hh:99
static bool isIdealFluid1(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: 2pimmiscible.hh:192
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: 2pimmiscible.hh:411
static bool isIdealMixture(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: 2pimmiscible.hh:128
static void init(Scalar tempMin, Scalar tempMax, std::size_t nTemp, Scalar pressMin, Scalar pressMax, std::size_t nPress)
Initialize the fluid system's static parameters using problem specific temperature and pressure range...
Definition: 2pimmiscible.hh:296
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: 2pimmiscible.hh:336
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the fugacity coefficient of an individual component in a fluid phase.
Definition: 2pimmiscible.hh:351
static Scalar diffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase .
Definition: 2pimmiscible.hh:370
static constexpr bool isIdealGas(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: 2pimmiscible.hh:142
static constexpr int comp0Idx
index of the first component
Definition: 2pimmiscible.hh:63
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: 2pimmiscible.hh:426
static constexpr int phase0Idx
index of the first phase
Definition: 2pimmiscible.hh:61
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition: 2pimmiscible.hh:309
static constexpr bool viscosityIsConstant(int phaseIdx)
Returns true if the liquid phase viscostiy is constant.
Definition: 2pimmiscible.hh:176
static constexpr int numPhases
Number of phases in the fluid system.
Definition: 2pimmiscible.hh:58
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
Calculate the molar density of a fluid phase.
Definition: 2pimmiscible.hh:324
static void init()
Initialize the fluid system's static parameters.
Definition: 2pimmiscible.hh:278
static Scalar criticalPressure(int compIdx)
Critical pressure of a component .
Definition: 2pimmiscible.hh:249
static Scalar criticalTemperature(int compIdx)
Critical temperature of a component .
Definition: 2pimmiscible.hh:236
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition: 2pimmiscible.hh:106
static constexpr int comp1Idx
index of the second component
Definition: 2pimmiscible.hh:64
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: 2pimmiscible.hh:223
static constexpr int numComponents
Number of components in the fluid system.
Definition: 2pimmiscible.hh:59
static constexpr int phase1Idx
index of the second phase
Definition: 2pimmiscible.hh:62
Base class for all components Components provide the thermodynamic relations for the liquid,...
Fluid system base class.
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 liquidPhase() noexcept
I/O name of liquid phase.
Definition: name.hh:107
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