mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[thermo] Add IAPWS as alternative backend to existing Water wrapper
While the current 'liquid-water-IAPWS95' thermo model only implements liquid (and supercritical) states, the underlying IAPWS formulation can be extended beyond in future revisions. - avoid 'liquid' as part of the nomenclature - YAML phase name is updated to `water-iapws95` - Instead of creating a new wrapper, `iapws95` is added as an alternative backend to the existing `Water` class
This commit is contained in:
committed by
Ray Speth
parent
1880e2402c
commit
4ba894df55
@@ -25,7 +25,7 @@ phases:
|
||||
T: 300.0
|
||||
P: 1.01325e+05
|
||||
pure-fluid-name: water
|
||||
- name: liquid-water
|
||||
- name: water-iapws95
|
||||
elements: [O, H]
|
||||
species: [H2O]
|
||||
thermo: liquid-water-IAPWS95
|
||||
|
||||
@@ -4,64 +4,48 @@
|
||||
from . import PureFluid, _cantera
|
||||
|
||||
|
||||
def Water():
|
||||
def Water(backend='default'):
|
||||
"""
|
||||
Create a `PureFluid` object using the equation of state for water and the
|
||||
`WaterTransport` class for viscosity and thermal conductivity.
|
||||
|
||||
The object returned by this method implements an accurate equation of
|
||||
state for water that can be used in the liquid, vapor, saturated
|
||||
liquid/vapor, and supercritical regions of the phase diagram. The
|
||||
equation of state is taken from
|
||||
The object returned by this method implements an accurate equation of state
|
||||
for water, where implementations are selected using the *backend* switch.
|
||||
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances.* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
For the ``default`` backend, the equation of state is taken from
|
||||
|
||||
whereas formulas for transport are taken from
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances.* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
|
||||
J. V. Sengers, J. T. R. Watson, *Improved International Formulations for
|
||||
the Viscosity and Thermal Conductivity of Water Substance,* J. Phys. Chem.
|
||||
Ref. Data, 15, 1291, 1986.
|
||||
which can be used in the liquid, vapor, saturated liquid/vapor, and
|
||||
supercritical regions of the phase diagram.
|
||||
|
||||
For more details, see classes Cantera::PureFluid, tpx::water and
|
||||
Cantera::WaterTransport in the Cantera C++ source code documentation.
|
||||
The ``iapws95`` backend implements an IAPWS (International Association for
|
||||
the Properties of Water and Steam) formulation for thermodynamic properties
|
||||
taken from
|
||||
|
||||
J. V. Sengers, J. T. R. Watson, *Improved International Formulations for
|
||||
the Viscosity and Thermal Conductivity of Water Substance,* J. Phys.
|
||||
Chem. Ref. Data, 15, 1291, 1986.
|
||||
|
||||
which currently only implements liquid and supercritical regions.
|
||||
|
||||
For more details, see classes Cantera::PureFluid, tpx::water,
|
||||
Cantera::WaterSSTP and Cantera::WaterTransport in the Cantera C++ source
|
||||
code documentation.
|
||||
"""
|
||||
class WaterWithTransport(PureFluid, _cantera.Transport):
|
||||
__slots__ = ()
|
||||
|
||||
return WaterWithTransport('liquidvapor.yaml', 'water',
|
||||
transport_model='Water')
|
||||
if backend == 'default':
|
||||
return WaterWithTransport('liquidvapor.yaml', 'water',
|
||||
transport_model='Water')
|
||||
if backend == 'iapws95':
|
||||
return WaterWithTransport('liquidvapor.yaml', 'water-iapws95',
|
||||
transport_model='Water')
|
||||
|
||||
|
||||
def LiquidWater():
|
||||
"""
|
||||
Create a `PureFluid` object using the IAPWS Formulation 1995 for
|
||||
thermodynamic properties and the `WaterTransport` class for viscosity
|
||||
and thermal conductivity.
|
||||
|
||||
The object returned by this method implements an accurate equation of
|
||||
state for water that can be used in the liquid and supercritical regions
|
||||
of the phase diagram. The equation of state is taken from
|
||||
|
||||
W. Wagner, A. Pruss, *The IAPWS Formulation 1995 for the Thermodynamic
|
||||
Properties of Ordinary Water Substance for General and Scientific Use,*
|
||||
J. Phys. Chem. Ref. Dat, 31, 387, 2002.
|
||||
|
||||
whereas formulas for transport are taken from
|
||||
|
||||
J. V. Sengers, J. T. R. Watson, *Improved International Formulations for
|
||||
the Viscosity and Thermal Conductivity of Water Substance,* J. Phys. Chem.
|
||||
Ref. Data, 15, 1291, 1986.
|
||||
|
||||
For more details, see classes Cantera::PureFluid, Cantera::WaterSSTP and
|
||||
Cantera::WaterTransport in the Cantera C++ source code documentation.
|
||||
"""
|
||||
class WaterWithTransport(PureFluid, _cantera.Transport):
|
||||
__slots__ = ()
|
||||
|
||||
return WaterWithTransport('liquidvapor.yaml', 'liquid-water',
|
||||
transport_model='Water')
|
||||
raise KeyError("Unknown backend '{}'".format(backend))
|
||||
|
||||
|
||||
def Nitrogen():
|
||||
@@ -73,9 +57,9 @@ def Nitrogen():
|
||||
liquid/vapor, and supercritical regions of the phase diagram. The
|
||||
equation of state is taken from
|
||||
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
|
||||
For more details, see classes Cantera::PureFluid and tpx::nitrogen in the
|
||||
Cantera C++ source code documentation.
|
||||
@@ -92,9 +76,9 @@ def Methane():
|
||||
liquid/vapor, and supercritical regions of the phase diagram. The
|
||||
equation of state is taken from
|
||||
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
|
||||
For more details, see classes Cantera::PureFluid and tpx::methane in the
|
||||
Cantera C++ source code documentation.
|
||||
@@ -111,9 +95,9 @@ def Hydrogen():
|
||||
liquid/vapor, and supercritical regions of the phase diagram. The
|
||||
equation of state is taken from
|
||||
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
|
||||
For more details, see classes Cantera::PureFluid and tpx::hydrogen in the
|
||||
Cantera C++ source code documentation.
|
||||
@@ -130,9 +114,9 @@ def Oxygen():
|
||||
liquid/vapor, and supercritical regions of the phase diagram. The
|
||||
equation of state is taken from
|
||||
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
|
||||
For more details, see classes Cantera::PureFluid and tpx::oxygen in the
|
||||
Cantera C++ source code documentation.
|
||||
@@ -149,11 +133,11 @@ def Hfc134a():
|
||||
vapor, saturated liquid/vapor, and supercritical regions of the phase
|
||||
diagram. Implements the equation of state given in:
|
||||
|
||||
R. Tillner-Roth and H. D. Baehr. *An International Standard Formulation for
|
||||
The Thermodynamic Properties of 1,1,1,2-Tetrafluoroethane (HFC-134a) for
|
||||
Temperatures From 170 K to 455 K and Pressures up to 70 MPa.* J. Phys.
|
||||
Chem. Ref. Data, Vol. 23, No. 5, 1994. pp. 657--729.
|
||||
http://dx.doi.org/10.1063/1.555958
|
||||
R. Tillner-Roth, H. D. Baehr. *An International Standard Formulation for
|
||||
The Thermodynamic Properties of 1,1,1,2-Tetrafluoroethane (HFC-134a) for
|
||||
Temperatures From 170 K to 455 K and Pressures up to 70 MPa.* J. Phys.
|
||||
Chem. Ref. Data, Vol. 23, No. 5, 1994. pp. 657--729.
|
||||
http://dx.doi.org/10.1063/1.555958
|
||||
|
||||
For more details, see classes Cantera::PureFluid and tpx::HFC134a in the
|
||||
Cantera C++ source code documentation.
|
||||
@@ -170,9 +154,9 @@ def CarbonDioxide():
|
||||
liquid/vapor, and supercritical regions of the phase diagram. The
|
||||
equation of state is taken from
|
||||
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances.* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances.* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
|
||||
For more details, see classes Cantera::PureFluid and tpx::CarbonDioxide in
|
||||
the Cantera C++ source code documentation.
|
||||
@@ -189,9 +173,9 @@ def Heptane():
|
||||
liquid/vapor, and supercritical regions of the phase diagram. The
|
||||
equation of state is taken from
|
||||
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances.* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
W. C. Reynolds, *Thermodynamic Properties in SI: graphs, tables, and
|
||||
computational equations for forty substances.* Stanford: Stanford
|
||||
University, 1979. Print.
|
||||
|
||||
For more details, see classes Cantera::PureFluid and tpx::Heptane in the
|
||||
Cantera C++ source code documentation.
|
||||
|
||||
@@ -357,8 +357,17 @@ class TestPureFluid(utilities.CanteraTest):
|
||||
co2 = ct.CarbonDioxide()
|
||||
self.assertEqual(co2.phase_of_matter, "gas")
|
||||
|
||||
def test_liquidwater(self):
|
||||
w = ct.LiquidWater()
|
||||
def test_water_backends(self):
|
||||
w = ct.Water(backend='default')
|
||||
self.assertEqual(w.thermo_model, 'PureFluid')
|
||||
w = ct.Water(backend='iapws95')
|
||||
self.assertEqual(w.thermo_model, 'Water')
|
||||
with self.assertRaisesRegex(KeyError, 'Unknown backend'):
|
||||
ct.Water('foobar')
|
||||
|
||||
|
||||
def test_water_iapws(self):
|
||||
w = ct.Water(backend='iapws95')
|
||||
self.assertNear(w.critical_density, 322.)
|
||||
self.assertNear(w.critical_temperature, 647.096)
|
||||
self.assertNear(w.critical_pressure, 22064000.0)
|
||||
@@ -382,9 +391,9 @@ class TestPureFluid(utilities.CanteraTest):
|
||||
self.assertEqual(w.phase_of_matter, "liquid")
|
||||
w.TP = w.T, w.P_sat
|
||||
self.assertEqual(w.phase_of_matter, "liquid")
|
||||
with self.assertRaisesRegex(ct.CanteraError, "violates model assumptions"):
|
||||
with self.assertRaisesRegex(ct.CanteraError, "Not implemented"):
|
||||
w.TP = 273.1599999, ct.one_atm
|
||||
with self.assertRaisesRegex(ct.CanteraError, "violates model assumptions"):
|
||||
with self.assertRaisesRegex(ct.CanteraError, "Not implemented"):
|
||||
w.TP = 500, ct.one_atm
|
||||
|
||||
|
||||
|
||||
@@ -282,18 +282,14 @@ void WaterSSTP::setPressure(doublereal p)
|
||||
dens = 1000.;
|
||||
} else if (!m_allowGasPhase) {
|
||||
throw CanteraError("WaterSSTP::setPressure",
|
||||
"Pressure p = {} lies below the saturation "
|
||||
"pressure\n(P_sat = {}), which violates model "
|
||||
"assumptions.", p, pp);
|
||||
"Not implemented: pressure p = {} lies below\n"
|
||||
"the saturation pressure (P_sat = {}).", p, pp);
|
||||
}
|
||||
}
|
||||
|
||||
double dd = m_sub.density(T, p, waterState, dens);
|
||||
if (dd <= 0.0) {
|
||||
throw CanteraError("WaterSSTP::setPressure",
|
||||
"error: T = {}, p = {}, psat = {}\n"
|
||||
"density_guess = {}, density_fail = {}",
|
||||
T, p, pp, dens, dd);
|
||||
throw CanteraError("WaterSSTP::setPressure", "Error");
|
||||
}
|
||||
setDensity(dd);
|
||||
}
|
||||
@@ -344,8 +340,8 @@ void WaterSSTP::setTemperature(const doublereal temp)
|
||||
{
|
||||
if (temp < 273.16) {
|
||||
throw CanteraError("WaterSSTP::setTemperature",
|
||||
"Temperature T = {} lies below the triple point "
|
||||
"temperature,\nwhich violates model assumptions.",
|
||||
"Not implemented: temperature T = {} lies below\n"
|
||||
"the triple point temperature (T_triple = 273.16).",
|
||||
temp);
|
||||
}
|
||||
Phase::setTemperature(temp);
|
||||
|
||||
@@ -21,7 +21,7 @@ int main()
|
||||
#endif
|
||||
double pres;
|
||||
try {
|
||||
ThermoPhase* w = newPhase("liquid-water.xml");
|
||||
ThermoPhase* w = newPhase("liquidvapor.yaml", "water-iapws95");
|
||||
(dynamic_cast<WaterSSTP*>(w))->allowGasPhase(true);
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user