Cantera 2.6.0

PDSS_Water.cpp
Go to the documentation of this file.
1/**
2 * @file PDSS_Water.cpp
3 */
4
5// This file is part of Cantera. See License.txt in the top-level directory or
6// at https://cantera.org/license.txt for license and copyright information.
7
8#include "cantera/base/ctml.h"
9#include "cantera/thermo/PDSS_Water.h"
10#include "cantera/thermo/WaterPropsIAPWS.h"
11#include "cantera/base/stringUtils.h"
12#include "cantera/thermo/Elements.h"
13
14 namespace Cantera
15{
16 PDSS_Water::PDSS_Water() :
17 m_waterProps(&m_sub),
18 m_dens(1000.0),
19 m_iState(WATER_LIQUID),
20 EW_Offset(0.0),
21 SW_Offset(0.0),
22 m_allowGasPhase(false)
23{
24 m_minTemp = 200.;
25 m_maxTemp = 10000.;
26 m_mw = 2*getElementWeight("H") + getElementWeight("O");
27
28 // Set the baseline
29 doublereal T = 298.15;
30 m_p0 = OneAtm;
31 doublereal presLow = 1.0E-2;
32 doublereal oneBar = 1.0E5;
33 doublereal dens = 1.0E-9;
34 m_dens = m_sub.density(T, presLow, WATER_GAS, dens);
35 m_pres = presLow;
36 SW_Offset = 0.0;
37 doublereal s = entropy_mole();
38 s -= GasConstant * log(oneBar/presLow);
39 if (s != 188.835E3) {
40 SW_Offset = 188.835E3 - s;
41 }
42 s = entropy_mole();
43 s -= GasConstant * log(oneBar/presLow);
44
45 doublereal h = enthalpy_mole();
46 if (h != -241.826E6) {
47 EW_Offset = -241.826E6 - h;
48 }
49 h = enthalpy_mole();
50
51 // Set the initial state of the system to 298.15 K and 1 bar.
52 setTemperature(298.15);
53 m_dens = m_sub.density(298.15, OneAtm, WATER_LIQUID);
54 m_pres = OneAtm;
55}
56
57doublereal PDSS_Water::enthalpy_mole() const
58{
59 return m_sub.enthalpy() + EW_Offset;
60}
61
62doublereal PDSS_Water::intEnergy_mole() const
63{
64 return m_sub.intEnergy() + EW_Offset;
65}
66
67doublereal PDSS_Water::entropy_mole() const
68{
69 return m_sub.entropy() + SW_Offset;
70}
71
72doublereal PDSS_Water::gibbs_mole() const
73{
74 return m_sub.Gibbs() + EW_Offset - SW_Offset*m_temp;
75}
76
77doublereal PDSS_Water::cp_mole() const
78{
79 return m_sub.cp();
80}
81
82doublereal PDSS_Water::cv_mole() const
83{
84 return m_sub.cv();
85}
86
87doublereal PDSS_Water::molarVolume() const
88{
89 return m_sub.molarVolume();
90}
91
92doublereal PDSS_Water::gibbs_RT_ref() const
93{
94 doublereal T = m_temp;
95 m_sub.density(T, m_p0, m_iState);
96 doublereal h = m_sub.enthalpy();
97 m_sub.setState_TR(m_temp, m_dens);
98 return (h + EW_Offset - SW_Offset*T)/(T * GasConstant);
99}
100
101doublereal PDSS_Water::enthalpy_RT_ref() const
102{
103 doublereal T = m_temp;
104 m_sub.density(T, m_p0, m_iState);
105 doublereal h = m_sub.enthalpy();
106 m_sub.setState_TR(m_temp, m_dens);
107 return (h + EW_Offset)/(T * GasConstant);
108}
109
110doublereal PDSS_Water::entropy_R_ref() const
111{
112 doublereal T = m_temp;
113 m_sub.density(T, m_p0, m_iState);
114 doublereal s = m_sub.entropy();
115 m_sub.setState_TR(m_temp, m_dens);
116 return (s + SW_Offset)/GasConstant;
117}
118
119doublereal PDSS_Water::cp_R_ref() const
120{
121 doublereal T = m_temp;
122 m_sub.density(T, m_p0, m_iState);
123 doublereal cp = m_sub.cp();
124 m_sub.setState_TR(m_temp, m_dens);
125 return cp/GasConstant;
126}
127
128doublereal PDSS_Water::molarVolume_ref() const
129{
130 doublereal T = m_temp;
131 m_sub.density(T, m_p0, m_iState);
132 doublereal mv = m_sub.molarVolume();
133 m_sub.setState_TR(m_temp, m_dens);
134 return mv;
135}
136
137doublereal PDSS_Water::pressure() const
138{
139 m_pres = m_sub.pressure();
140 return m_pres;
141}
142
143 void PDSS_Water::setPressure(doublereal p)
144{
145 // In this routine we must be sure to only find the water branch of the
146 // curve and not the gas branch
147 doublereal T = m_temp;
148 doublereal dens = m_dens;
149 int waterState = WATER_LIQUID;
150 if (T > m_sub.Tcrit()) {
151 waterState = WATER_SUPERCRIT;
152 }
153
154 doublereal dd = m_sub.density(T, p, waterState, dens);
155 if (dd <= 0.0) {
156 throw CanteraError("PDSS_Water:setPressure",
157 "Failed to set water SS state: T = {} K and p = {} Pa", T, p);
158 }
159 m_dens = dd;
160 m_pres = p;
161
162 // We are only putting the phase check here because of speed considerations.
163 m_iState = m_sub.phaseState(true);
164 if (!m_allowGasPhase && m_iState != WATER_SUPERCRIT && m_iState != WATER_LIQUID && m_iState != WATER_UNSTABLELIQUID) {
165 throw CanteraError("PDSS_Water::setPressure",
166 "Water State isn't liquid or crit");
167 }
168}
169
170doublereal PDSS_Water::thermalExpansionCoeff() const
171{
172 return m_sub.coeffThermExp();
173}
174
175doublereal PDSS_Water::dthermalExpansionCoeffdT() const
176{
177 doublereal pres = pressure();
178 doublereal dens_save = m_dens;
179 doublereal tt = m_temp - 0.04;
180 doublereal dd = m_sub.density(tt, pres, m_iState, m_dens);
181 if (dd < 0.0) {
182 throw CanteraError("PDSS_Water::dthermalExpansionCoeffdT",
183 "unable to solve for the density at T = {}, P = {}", tt, pres);
184 }
185 doublereal vald = m_sub.coeffThermExp();
186 m_sub.setState_TR(m_temp, dens_save);
187 doublereal val2 = m_sub.coeffThermExp();
188 return (val2 - vald) / 0.04;
189}
190
191doublereal PDSS_Water::isothermalCompressibility() const
192{
193 return m_sub.isothermalCompressibility();
194}
195
196doublereal PDSS_Water::critTemperature() const
197{
198 return m_sub.Tcrit();
199}
200
201doublereal PDSS_Water::critPressure() const
202{
203 return m_sub.Pcrit();
204}
205
206doublereal PDSS_Water::critDensity() const
207{
208 return m_sub.Rhocrit();
209}
210
211 void PDSS_Water::setDensity(doublereal dens)
212{
213 m_dens = dens;
214 m_sub.setState_TR(m_temp, m_dens);
215}
216
217doublereal PDSS_Water::density() const
218{
219 return m_dens;
220}
221
222 void PDSS_Water::setTemperature(doublereal temp)
223{
224 m_temp = temp;
225 m_sub.setState_TR(temp, m_dens);
226}
227
228 void PDSS_Water::setState_TP(doublereal temp, doublereal pres)
229{
230 m_temp = temp;
231 setPressure(pres);
232}
233
234 void PDSS_Water::setState_TR(doublereal temp, doublereal dens)
235{
236 m_temp = temp;
237 m_dens = dens;
238 m_sub.setState_TR(m_temp, m_dens);
239}
240
241doublereal PDSS_Water::pref_safe(doublereal temp) const
242{
243 if (temp < m_sub.Tcrit()) {
244 doublereal pp = m_sub.psat_est(temp);
245 if (pp > OneAtm) {
246 return pp;
247 }
248 } else {
249 return m_sub.Pcrit();
250 }
251 return OneAtm;
252}
253
254doublereal PDSS_Water::satPressure(doublereal t)
255{
256 doublereal pp = m_sub.psat(t, WATER_LIQUID);
257 m_dens = m_sub.density();
258 m_temp = t;
259 return pp;
260}
261
262 void PDSS_Water::getParameters(AnyMap& eosNode) const
263{
264 eosNode["model"] = "liquid-water-IAPWS95";
265}
266
267}
Elements.h
Contains the getElementWeight function and the definitions of element constraint types.
PDSS_Water.h
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
WaterPropsIAPWS.h
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::PDSS_Water::getParameters
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS_Water.cpp:262
Cantera::PDSS_Water::cp_R_ref
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_Water.cpp:119
Cantera::PDSS_Water::m_sub
WaterPropsIAPWS m_sub
Pointer to the WaterPropsIAPWS object, which does the actual calculations for the real equation of st...
Definition: PDSS_Water.h:161
Cantera::PDSS_Water::pressure
virtual doublereal pressure() const
Returns the pressure (Pa)
Definition: PDSS_Water.cpp:137
Cantera::PDSS_Water::cp_mole
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:77
Cantera::PDSS_Water::pref_safe
doublereal pref_safe(doublereal temp) const
Returns a reference pressure value that can be safely calculated by the underlying real equation of s...
Definition: PDSS_Water.cpp:241
Cantera::PDSS_Water::critPressure
virtual doublereal critPressure() const
critical pressure
Definition: PDSS_Water.cpp:201
Cantera::PDSS_Water::enthalpy_mole
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:57
Cantera::PDSS_Water::setPressure
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_Water.cpp:143
Cantera::PDSS_Water::setState_TP
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:228
Cantera::PDSS_Water::EW_Offset
doublereal EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition: PDSS_Water.h:197
Cantera::PDSS_Water::cv_mole
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:82
Cantera::PDSS_Water::thermalExpansionCoeff
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: PDSS_Water.cpp:170
Cantera::PDSS_Water::setTemperature
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_Water.cpp:222
Cantera::PDSS_Water::dthermalExpansionCoeffdT
virtual doublereal dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient.
Definition: PDSS_Water.cpp:175
Cantera::PDSS_Water::entropy_mole
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:67
Cantera::PDSS_Water::setDensity
void setDensity(doublereal dens)
Set the density of the water phase.
Definition: PDSS_Water.cpp:211
Cantera::PDSS_Water::molarVolume_ref
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_Water.cpp:128
Cantera::PDSS_Water::critTemperature
virtual doublereal critTemperature() const
critical temperature
Definition: PDSS_Water.cpp:196
Cantera::PDSS_Water::molarVolume
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_Water.cpp:87
Cantera::PDSS_Water::gibbs_mole
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_Water.cpp:72
Cantera::PDSS_Water::m_iState
int m_iState
state of the fluid
Definition: PDSS_Water.h:190
Cantera::PDSS_Water::enthalpy_RT_ref
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:101
Cantera::PDSS_Water::setState_TR
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_Water.cpp:234
Cantera::PDSS_Water::density
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:217
Cantera::PDSS_Water::entropy_R_ref
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_Water.cpp:110
Cantera::PDSS_Water::satPressure
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_Water.cpp:254
Cantera::PDSS_Water::m_dens
doublereal m_dens
State of the system - density.
Definition: PDSS_Water.h:178
Cantera::PDSS_Water::gibbs_RT_ref
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:92
Cantera::PDSS_Water::SW_Offset
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: PDSS_Water.h:204
Cantera::PDSS_Water::m_allowGasPhase
bool m_allowGasPhase
Since this phase represents a liquid phase, it's an error to return a gas-phase answer.
Definition: PDSS_Water.h:213
Cantera::PDSS_Water::critDensity
virtual doublereal critDensity() const
critical density
Definition: PDSS_Water.cpp:206
Cantera::PDSS_Water::PDSS_Water
PDSS_Water()
Default constructor.
Definition: PDSS_Water.cpp:16
Cantera::PDSS_Water::intEnergy_mole
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_Water.cpp:62
Cantera::PDSS_Water::isothermalCompressibility
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: PDSS_Water.cpp:191
Cantera::PDSS::m_pres
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:458
Cantera::PDSS::m_temp
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:455
Cantera::PDSS::m_maxTemp
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:467
Cantera::PDSS::m_p0
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:461
Cantera::PDSS::m_mw
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:470
Cantera::PDSS::m_minTemp
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:464
Cantera::WaterPropsIAPWS::density
doublereal density(doublereal temperature, doublereal pressure, int phase=-1, doublereal rhoguess=-1.0)
Calculates the density given the temperature and the pressure, and a guess at the density.
Definition: WaterPropsIAPWS.cpp:78
Cantera::WaterPropsIAPWS::coeffThermExp
doublereal coeffThermExp() const
Returns the coefficient of thermal expansion.
Definition: WaterPropsIAPWS.cpp:259
Cantera::WaterPropsIAPWS::cp
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
Definition: WaterPropsIAPWS.cpp:612
Cantera::WaterPropsIAPWS::pressure
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density.
Definition: WaterPropsIAPWS.cpp:70
Cantera::WaterPropsIAPWS::enthalpy
doublereal enthalpy() const
Calculate the enthalpy in mks units of J kmol-1 using the last temperature and density.
Definition: WaterPropsIAPWS.cpp:586
Cantera::WaterPropsIAPWS::Tcrit
doublereal Tcrit() const
Returns the critical temperature of water (Kelvin)
Definition: WaterPropsIAPWS.h:380
Cantera::WaterPropsIAPWS::cv
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
Definition: WaterPropsIAPWS.cpp:606
Cantera::WaterPropsIAPWS::molarVolume
doublereal molarVolume() const
Calculate the molar volume (kmol m-3) at the last temperature and density.
Definition: WaterPropsIAPWS.cpp:618
Cantera::WaterPropsIAPWS::entropy
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
Definition: WaterPropsIAPWS.cpp:600
Cantera::WaterPropsIAPWS::intEnergy
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
Definition: WaterPropsIAPWS.cpp:593
Cantera::WaterPropsIAPWS::Rhocrit
doublereal Rhocrit() const
Return the critical density of water (kg m-3)
Definition: WaterPropsIAPWS.h:396
Cantera::WaterPropsIAPWS::Gibbs
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
Definition: WaterPropsIAPWS.cpp:267
Cantera::WaterPropsIAPWS::psat_est
doublereal psat_est(doublereal temperature) const
This function returns an estimated value for the saturation pressure.
Definition: WaterPropsIAPWS.cpp:202
Cantera::WaterPropsIAPWS::psat
doublereal psat(doublereal temperature, int waterState=WATER_LIQUID)
This function returns the saturation pressure given the temperature as an input parameter,...
Definition: WaterPropsIAPWS.cpp:323
Cantera::WaterPropsIAPWS::setState_TR
void setState_TR(doublereal temperature, doublereal rho)
Set the internal state of the object wrt temperature and density.
Definition: WaterPropsIAPWS.cpp:580
Cantera::WaterPropsIAPWS::phaseState
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
Definition: WaterPropsIAPWS.cpp:365
Cantera::WaterPropsIAPWS::isothermalCompressibility
doublereal isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
Definition: WaterPropsIAPWS.cpp:240
Cantera::WaterPropsIAPWS::Pcrit
doublereal Pcrit() const
Returns the critical pressure of water (22.064E6 Pa)
Definition: WaterPropsIAPWS.h:388
ctml.h
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::OneAtm
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:81
Cantera::getElementWeight
double getElementWeight(const std::string &ename)
Get the atomic weight of an element.
Definition: Elements.cpp:207
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
stringUtils.h
Contains declarations for string manipulation functions within Cantera.