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