version 3.11-dev
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
2p1c.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_2P_1C_FLUID_SYSTEM_HH
13#define DUMUX_2P_1C_FLUID_SYSTEM_HH
14
15#include <limits>
16#include <cassert>
17#include <iostream>
18
19#include <dune/common/exceptions.hh>
20
21#include <dumux/io/name.hh>
22
23#include "base.hh"
24
25namespace Dumux::FluidSystems {
26
31template <class Scalar, class ComponentType>
33 : public Base<Scalar, TwoPOneC<Scalar, ComponentType> >
34{
36 using Component = ComponentType;
37
38public:
39 static constexpr int numPhases = 2;
40 static constexpr int numComponents = 1;
41
42 static constexpr int liquidPhaseIdx = 0;
43 static constexpr int gasPhaseIdx = 1;
44 static constexpr int phase0Idx = liquidPhaseIdx;
45 static constexpr int phase1Idx = gasPhaseIdx;
46
47 static constexpr int comp0Idx = 0;
48
49 /****************************************
50 * Fluid phase related static parameters
51 ****************************************/
57 static std::string phaseName(int phaseIdx)
58 {
59 static std::string name[] = {
60 std::string(IOName::liquidPhase()),
61 std::string(IOName::gaseousPhase()),
62 };
63
64 assert(0 <= phaseIdx && phaseIdx < numPhases);
65 return name[phaseIdx];
66 }
67
71 static constexpr bool isMiscible()
72 { return false; }
73
79 static constexpr bool isGas(int phaseIdx)
80 {
81 assert(0 <= phaseIdx && phaseIdx < numPhases);
82 return phaseIdx == gasPhaseIdx;
83 }
84
99 static constexpr bool isIdealMixture(int phaseIdx)
100 {
101 assert(0 <= phaseIdx && phaseIdx < numPhases);
102 // we assume Henry's and Raoult's laws for the water phase and
103 // and no interaction between gas molecules of different
104 // components, so all phases are ideal mixtures!
105 return true;
106 }
107
117 static constexpr bool isCompressible(int phaseIdx)
118 {
119 assert(0 <= phaseIdx && phaseIdx < numPhases);
120 // gases are always compressible
121 if (phaseIdx == gasPhaseIdx)
122 return true;
123 // the component decides for the liquid phase...
124 return Component::liquidIsCompressible();
125 }
126
133 static constexpr bool isIdealGas(int phaseIdx)
134 {
135 assert(0 <= phaseIdx && phaseIdx < numPhases);
136
137 if (phaseIdx == gasPhaseIdx)
138 // let the components decide
139 return Component::gasIsIdeal();
140 return false; // not a gas
141 }
142
143 /****************************************
144 * Component related static parameters
145 ****************************************/
146
152 static std::string componentName(int compIdx)
153 {
154 assert(0 <= compIdx && compIdx < numComponents);
155 return Component::name();
156 }
157
163 static Scalar molarMass(int compIdx)
164 {
165 assert(0 <= compIdx && compIdx < numComponents);
166 return Component::molarMass();
167 }
168
174 static Scalar criticalTemperature(int compIdx)
175 {
176 assert(0 <= compIdx && compIdx < numComponents);
177 return Component::criticalTemperature();
178 }
179
185 static Scalar criticalPressure(int compIdx)
186 {
187 assert(0 <= compIdx && compIdx < numComponents);
188 return Component::criticalPressure();
189 }
190
196 static Scalar criticalMolarVolume(int compIdx)
197 {
198 DUNE_THROW(Dune::NotImplemented,
199 "TwoPOneC::criticalMolarVolume()");
200 return 0;
201 }
202
208 static Scalar acentricFactor(int compIdx)
209 {
210 assert(0 <= compIdx && compIdx < numComponents);
211 return Component::acentricFactor();
212 }
213
214 /****************************************
215 * thermodynamic relations
216 ****************************************/
217
224 static void init()
225 {
226 init(/*tempMin=*/273.15,
227 /*tempMax=*/623.15,
228 /*numTemp=*/100,
229 /*pMin=*/0.0,
230 /*pMax=*/20e6,
231 /*numP=*/200);
232 }
233
245 static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
246 Scalar pressMin, Scalar pressMax, unsigned nPress)
247 {
248 if (Component::isTabulated)
249 {
250 Component::init(tempMin, tempMax, nTemp,
251 pressMin, pressMax, nPress);
252 }
253 }
254
257 template <class FluidState>
258 static Scalar density(const FluidState &fluidState,
259 int phaseIdx)
260 {
261 assert(0 <= phaseIdx && phaseIdx < numPhases);
262
263 Scalar temperature = fluidState.temperature(phaseIdx);
264 Scalar pressure = fluidState.pressure(phaseIdx);
265
266 // liquid phase
267 if (phaseIdx == liquidPhaseIdx) {
268 return Component::liquidDensity(temperature, pressure);
269 }
270 else if (phaseIdx == gasPhaseIdx)// gas phase
271 {
272 return Component::gasDensity(temperature, pressure);
273 }
274 else
275 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index.");
276 }
277
280 template <class FluidState>
281 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
282 {
283 Scalar temperature = fluidState.temperature(phaseIdx);
284 Scalar pressure = fluidState.temperature(phaseIdx);
285 if (phaseIdx == liquidPhaseIdx)
286 return Component::liquidMolarDensity(temperature, pressure);
287 else if (phaseIdx == gasPhaseIdx)
288 return Component::gasMolarDensity(temperature, pressure);
289 else
290 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index.");
291 }
292
295 template <class FluidState>
296 static Scalar viscosity(const FluidState &fluidState,
297 int phaseIdx)
298 {
299 assert(0 <= phaseIdx && phaseIdx < numPhases);
300
301 Scalar temperature = fluidState.temperature(phaseIdx);
302 Scalar pressure = fluidState.pressure(phaseIdx);
303
304 // liquid phase
305 if (phaseIdx == liquidPhaseIdx)
306 return Component::liquidViscosity(temperature, pressure);
307 else if (phaseIdx == gasPhaseIdx) // gas phase
308 return Component::gasViscosity(temperature, pressure);
309 else
310 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index.");
311 }
312
319 template <class FluidState>
320 static Scalar vaporTemperature(const FluidState &fluidState,
321 const unsigned int phaseIdx)
322 {
323 assert(0 <= phaseIdx && phaseIdx < numPhases);
324 Scalar pressure = fluidState.pressure(gasPhaseIdx);
325
326 return Component::vaporTemperature(pressure);
327 }
328
357 template <class FluidState>
358 static Scalar fugacityCoefficient(const FluidState &fluidState,
359 int phaseIdx,
360 int compIdx)
361 {
362 assert(0 <= phaseIdx && phaseIdx < numPhases);
363 assert(0 <= compIdx && compIdx < numComponents);
364
365 Scalar temperature = fluidState.temperature(phaseIdx);
366 Scalar pressure = fluidState.pressure(phaseIdx);
367
368 // liquid phase
369 if (phaseIdx == liquidPhaseIdx)
370 return Component::vaporPressure(temperature)/pressure;
371
372 // for the gas phase, assume an ideal gas when it comes to
373 // fugacity (-> fugacity == partial pressure)
374 else if (phaseIdx == gasPhaseIdx)
375 return 1.0;
376
377 else
378 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index.");
379 }
380
381
384 template <class FluidState>
385 static Scalar diffusionCoefficient(const FluidState &fluidState,
386 int phaseIdx,
387 int compIdx)
388 {
389 // TODO!
390 DUNE_THROW(Dune::NotImplemented, "Diffusion coefficients");
391 }
392
395 template <class FluidState>
396 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
397 int phaseIdx,
398 int compIIdx,
399 int compJIdx)
400
401 { DUNE_THROW(Dune::NotImplemented, "Binary Diffusion coefficients"); }
402
405 template <class FluidState>
406 static Scalar enthalpy(const FluidState &fluidState,
407 int phaseIdx)
408 {
409 assert(0 <= phaseIdx && phaseIdx < numPhases);
410
411 // liquid phase
412 if (phaseIdx == liquidPhaseIdx)
413 return Component::liquidEnthalpy(fluidState.temperature(phaseIdx),
414 fluidState.pressure(phaseIdx));
415
416 else if (phaseIdx == gasPhaseIdx) // gas phase
417 return Component::gasEnthalpy(fluidState.temperature(phaseIdx),
418 fluidState.pressure(phaseIdx));
419
420 else
421 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index.");
422 }
423
426 template <class FluidState>
427 static Scalar thermalConductivity(const FluidState &fluidState,
428 const int phaseIdx)
429 {
430 assert(0 <= phaseIdx && phaseIdx < numPhases);
431 // liquid phase
432 if (phaseIdx == liquidPhaseIdx)
433 return Component::liquidThermalConductivity(fluidState.temperature(phaseIdx),
434 fluidState.pressure(phaseIdx)); //0.68 ;
435
436 else if (phaseIdx == gasPhaseIdx) // gas phase
437 return Component::gasThermalConductivity(fluidState.temperature(phaseIdx),
438 fluidState.pressure(phaseIdx)); //0.0248;
439
440 else
441 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index.");
442 }
443
446 template <class FluidState>
447 static Scalar heatCapacity(const FluidState &fluidState,
448 int phaseIdx)
449 {
450 assert(0 <= phaseIdx && phaseIdx < numPhases);
451 // liquid phase
452 if (phaseIdx == liquidPhaseIdx)
453 return Component::liquidHeatCapacity(fluidState.temperature(phaseIdx),
454 fluidState.pressure(phaseIdx));//4.217e3 ;
455
456 else if (phaseIdx == gasPhaseIdx) // gas phase
457 return Component::gasHeatCapacity(fluidState.temperature(phaseIdx),
458 fluidState.pressure(phaseIdx));//2.029e3;
459
460 else
461 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index.");
462 }
463};
464
465} // end namespace Dumux::FluidSystems
466
467#endif
Fluid system base class.
Definition: fluidsystems/base.hh:32
Scalar Scalar
export the scalar type
Definition: fluidsystems/base.hh:35
A two-phase fluid system with only one component.
Definition: 2p1c.hh:34
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature, pressure and density, calculate its specific enthalpy .
Definition: 2p1c.hh:406
static Scalar molarMass(int compIdx)
Return the molar mass of a component in [kg/mol].
Definition: 2p1c.hh:163
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition: 2p1c.hh:71
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: 2p1c.hh:152
static constexpr bool isIdealGas(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: 2p1c.hh:133
static Scalar criticalMolarVolume(int compIdx)
Molar volume of a component at the critical point [m^3/mol].
Definition: 2p1c.hh:196
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: 2p1c.hh:245
static constexpr int comp0Idx
index of the only component
Definition: 2p1c.hh:47
static Scalar criticalTemperature(int compIdx)
Critical temperature of a component [K].
Definition: 2p1c.hh:174
static constexpr int numPhases
Number of phases in the fluid system.
Definition: 2p1c.hh:39
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: 2p1c.hh:117
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition: 2p1c.hh:57
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the fugacity coefficient [-] of an individual component in a fluid phase.
Definition: 2p1c.hh:358
static Scalar criticalPressure(int compIdx)
Critical pressure of a component [Pa].
Definition: 2p1c.hh:185
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: 2p1c.hh:447
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
Calculate the molar density of a fluid phase.
Definition: 2p1c.hh:281
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: 2p1c.hh:396
static constexpr int phase1Idx
index of the second phase
Definition: 2p1c.hh:45
static constexpr int liquidPhaseIdx
index of the liquid phase
Definition: 2p1c.hh:42
static constexpr int numComponents
Number of components in the fluid system.
Definition: 2p1c.hh:40
static Scalar diffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase .
Definition: 2p1c.hh:385
static constexpr int gasPhaseIdx
index of the gas phase
Definition: 2p1c.hh:43
static Scalar thermalConductivity(const FluidState &fluidState, const int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: 2p1c.hh:427
static Scalar vaporTemperature(const FluidState &fluidState, const unsigned int phaseIdx)
calculate the temperature of vapor at a given pressure on the vapor pressure curve.
Definition: 2p1c.hh:320
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition: 2p1c.hh:258
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition: 2p1c.hh:79
static constexpr bool isIdealMixture(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: 2p1c.hh:99
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: 2p1c.hh:296
static void init()
Initialize the fluid system's static parameters generically.
Definition: 2p1c.hh:224
static constexpr int phase0Idx
index of the first phase
Definition: 2p1c.hh:44
static Scalar acentricFactor(int compIdx)
The acentric factor of a component [].
Definition: 2p1c.hh:208
Fluid system base class.
A collection of input/output field names for common physical quantities.
Definition: h2o.hh:901
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 liquidPhase() noexcept
I/O name of liquid phase.
Definition: name.hh:107
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:22