Cantera 2.6.0
WaterSSTP.cpp
Go to the documentation of this file.
1/**
2 * @file WaterSSTP.cpp
3 * Definitions for a ThermoPhase class consisting of pure water (see \ref thermoprops
4 * and class \link Cantera::WaterSSTP WaterSSTP\endlink).
5 */
6
7// This file is part of Cantera. See License.txt in the top-level directory or
8// at https://cantera.org/license.txt for license and copyright information.
9
13
14using namespace std;
15
16namespace Cantera
17{
18WaterSSTP::WaterSSTP(const std::string& inputFile, const std::string& id) :
19 m_mw(0.0),
20 EW_Offset(0.0),
21 SW_Offset(0.0),
22 m_ready(false),
23 m_allowGasPhase(false)
24{
25 initThermoFile(inputFile, id);
26}
27
28WaterSSTP::WaterSSTP(XML_Node& phaseRoot, const std::string& id) :
29 m_mw(0.0),
30 EW_Offset(0.0),
31 SW_Offset(0.0),
32 m_ready(false),
33 m_allowGasPhase(false)
34{
35 importPhase(phaseRoot, this);
36}
37
38std::string WaterSSTP::phaseOfMatter() const {
39 const vector<std::string> phases = {
40 "gas", "liquid", "supercritical", "unstable-liquid", "unstable-gas"
41 };
42 return phases[m_sub.phaseState()];
43}
44
46{
48
49 // Calculate the molecular weight. Note while there may be a very good
50 // calculated weight in the steam table class, using this weight may lead to
51 // codes exhibiting mass loss issues. We need to grab the elemental atomic
52 // weights used in the Element class and calculate a consistent H2O
53 // molecular weight based on that.
54 size_t nH = elementIndex("H");
55 if (nH == npos) {
56 throw CanteraError("WaterSSTP::initThermo",
57 "H not an element");
58 }
59 double mw_H = atomicWeight(nH);
60 size_t nO = elementIndex("O");
61 if (nO == npos) {
62 throw CanteraError("WaterSSTP::initThermo",
63 "O not an element");
64 }
65 double mw_O = atomicWeight(nO);
66 m_mw = 2.0 * mw_H + mw_O;
68
69 // Set the baseline
70 doublereal T = 298.15;
71 Phase::setDensity(7.0E-8);
73
74 doublereal presLow = 1.0E-2;
75 doublereal oneBar = 1.0E5;
76 doublereal dd = m_sub.density(T, presLow, WATER_GAS, 7.0E-8);
77 setDensity(dd);
79 SW_Offset = 0.0;
80 doublereal s = entropy_mole();
81 s -= GasConstant * log(oneBar/presLow);
82 if (s != 188.835E3) {
83 SW_Offset = 188.835E3 - s;
84 }
85 s = entropy_mole();
86 s -= GasConstant * log(oneBar/presLow);
87
88 doublereal h = enthalpy_mole();
89 if (h != -241.826E6) {
90 EW_Offset = -241.826E6 - h;
91 }
92 h = enthalpy_mole();
93
94 // Set the initial state of the system to 298.15 K and 1 bar.
95 setTemperature(298.15);
96 double rho0 = m_sub.density(298.15, OneAtm, WATER_LIQUID);
97 setDensity(rho0);
98
99 m_waterProps.reset(new WaterProps(&m_sub));
100
101 // Set the flag to say we are ready to calculate stuff
102 m_ready = true;
103}
104
106{
107 eosdata._require("model","PureLiquidWater");
108}
109
110void WaterSSTP::getEnthalpy_RT(doublereal* hrt) const
111{
112 *hrt = (m_sub.enthalpy() + EW_Offset) / RT();
113}
114
115void WaterSSTP::getIntEnergy_RT(doublereal* ubar) const
116{
117 *ubar = (m_sub.intEnergy() + EW_Offset)/GasConstant;
118}
119
120void WaterSSTP::getEntropy_R(doublereal* sr) const
121{
122 sr[0] = (m_sub.entropy() + SW_Offset) / GasConstant;
123}
124
125void WaterSSTP::getGibbs_RT(doublereal* grt) const
126{
127 *grt = (m_sub.Gibbs() + EW_Offset) / RT() - SW_Offset / GasConstant;
128 if (!m_ready) {
129 throw CanteraError("waterSSTP::getGibbs_RT", "Phase not ready");
130 }
131}
132
133void WaterSSTP::getStandardChemPotentials(doublereal* gss) const
134{
135 *gss = (m_sub.Gibbs() + EW_Offset - SW_Offset*temperature());
136 if (!m_ready) {
137 throw CanteraError("waterSSTP::getStandardChemPotentials",
138 "Phase not ready");
139 }
140}
141
142void WaterSSTP::getCp_R(doublereal* cpr) const
143{
144 cpr[0] = m_sub.cp() / GasConstant;
145}
146
147doublereal WaterSSTP::cv_mole() const
148{
149 return m_sub.cv();
150}
151
152void WaterSSTP::getEnthalpy_RT_ref(doublereal* hrt) const
153{
154 doublereal p = pressure();
155 double T = temperature();
156 double dens = density();
157 int waterState = WATER_GAS;
158 double rc = m_sub.Rhocrit();
159 if (dens > rc) {
160 waterState = WATER_LIQUID;
161 }
162 doublereal dd = m_sub.density(T, OneAtm, waterState, dens);
163 if (dd <= 0.0) {
164 throw CanteraError("WaterSSTP::getEnthalpy_RT_ref", "error");
165 }
166 doublereal h = m_sub.enthalpy();
167 *hrt = (h + EW_Offset) / RT();
168 dd = m_sub.density(T, p, waterState, dens);
169}
170
171void WaterSSTP::getGibbs_RT_ref(doublereal* grt) const
172{
173 doublereal p = pressure();
174 double T = temperature();
175 double dens = density();
176 int waterState = WATER_GAS;
177 double rc = m_sub.Rhocrit();
178 if (dens > rc) {
179 waterState = WATER_LIQUID;
180 }
181 doublereal dd = m_sub.density(T, OneAtm, waterState, dens);
182 if (dd <= 0.0) {
183 throw CanteraError("WaterSSTP::getGibbs_RT_ref", "error");
184 }
185 m_sub.setState_TR(T, dd);
186 doublereal g = m_sub.Gibbs();
187 *grt = (g + EW_Offset - SW_Offset*T)/ RT();
188 dd = m_sub.density(T, p, waterState, dens);
189}
190
191void WaterSSTP::getGibbs_ref(doublereal* g) const
192{
194 for (size_t k = 0; k < m_kk; k++) {
195 g[k] *= RT();
196 }
197}
198
199void WaterSSTP::getEntropy_R_ref(doublereal* sr) const
200{
201 doublereal p = pressure();
202 double T = temperature();
203 double dens = density();
204 int waterState = WATER_GAS;
205 double rc = m_sub.Rhocrit();
206 if (dens > rc) {
207 waterState = WATER_LIQUID;
208 }
209 doublereal dd = m_sub.density(T, OneAtm, waterState, dens);
210
211 if (dd <= 0.0) {
212 throw CanteraError("WaterSSTP::getEntropy_R_ref", "error");
213 }
214 m_sub.setState_TR(T, dd);
215
216 doublereal s = m_sub.entropy();
217 *sr = (s + SW_Offset)/ GasConstant;
218 dd = m_sub.density(T, p, waterState, dens);
219}
220
221void WaterSSTP::getCp_R_ref(doublereal* cpr) const
222{
223 doublereal p = pressure();
224 double T = temperature();
225 double dens = density();
226 int waterState = WATER_GAS;
227 double rc = m_sub.Rhocrit();
228 if (dens > rc) {
229 waterState = WATER_LIQUID;
230 }
231 doublereal dd = m_sub.density(T, OneAtm, waterState, dens);
232 m_sub.setState_TR(T, dd);
233 if (dd <= 0.0) {
234 throw CanteraError("WaterSSTP::getCp_R_ref", "error");
235 }
236 doublereal cp = m_sub.cp();
237 *cpr = cp / GasConstant;
238 dd = m_sub.density(T, p, waterState, dens);
239}
240
241void WaterSSTP::getStandardVolumes_ref(doublereal* vol) const
242{
243 doublereal p = pressure();
244 double T = temperature();
245 double dens = density();
246 int waterState = WATER_GAS;
247 double rc = m_sub.Rhocrit();
248 if (dens > rc) {
249 waterState = WATER_LIQUID;
250 }
251 doublereal dd = m_sub.density(T, OneAtm, waterState, dens);
252 if (dd <= 0.0) {
253 throw CanteraError("WaterSSTP::getStandardVolumes_ref", "error");
254 }
255 *vol = meanMolecularWeight() /dd;
256 dd = m_sub.density(T, p, waterState, dens);
257}
258
259doublereal WaterSSTP::pressure() const
260{
261 return m_sub.pressure();
262}
263
264void WaterSSTP::setPressure(doublereal p)
265{
266 double T = temperature();
267 double dens = density();
268 double pp = m_sub.psat(T);
269 int waterState = WATER_SUPERCRIT;
270 if (T < m_sub.Tcrit()) {
271 if (p >= pp) {
272 waterState = WATER_LIQUID;
273 dens = 1000.;
274 } else if (!m_allowGasPhase) {
275 throw CanteraError("WaterSSTP::setPressure",
276 "Model assumes liquid phase; pressure p = {} lies below\n"
277 "the saturation pressure (P_sat = {}).", p, pp);
278 }
279 }
280
281 double dd = m_sub.density(T, p, waterState, dens);
282 if (dd <= 0.0) {
283 throw CanteraError("WaterSSTP::setPressure", "Error");
284 }
285 setDensity(dd);
286}
287
289{
291}
292
294{
295 return m_sub.coeffThermExp();
296}
297
299{
300 doublereal pres = pressure();
301 doublereal dens_save = density();
302 double T = temperature();
303 double tt = T - 0.04;
304 doublereal dd = m_sub.density(tt, pres, WATER_LIQUID, dens_save);
305 if (dd < 0.0) {
306 throw CanteraError("WaterSSTP::dthermalExpansionCoeffdT",
307 "Unable to solve for the density at T = {}, P = {}", tt, pres);
308 }
309 doublereal vald = m_sub.coeffThermExp();
310 m_sub.setState_TR(T, dens_save);
311 doublereal val2 = m_sub.coeffThermExp();
312 return (val2 - vald) / 0.04;
313}
314
316{
317 return m_sub.Tcrit();
318}
319
320doublereal WaterSSTP::critPressure() const
321{
322 return m_sub.Pcrit();
323}
324
325doublereal WaterSSTP::critDensity() const
326{
327 return m_sub.Rhocrit();
328}
329
330void WaterSSTP::setTemperature(const doublereal temp)
331{
332 if (temp < 273.16) {
333 throw CanteraError("WaterSSTP::setTemperature",
334 "Model assumes liquid phase; temperature T = {} lies below\n"
335 "the triple point temperature (T_triple = 273.16).", temp);
336 }
338 m_sub.setState_TR(temp, density());
339}
340
341void WaterSSTP::setDensity(const doublereal dens)
342{
343 Phase::setDensity(dens);
345}
346
347doublereal WaterSSTP::satPressure(doublereal t) {
348 doublereal tsave = temperature();
349 doublereal dsave = density();
350 doublereal pp = m_sub.psat(t);
351 m_sub.setState_TR(tsave, dsave);
352 return pp;
353}
354
355doublereal WaterSSTP::vaporFraction() const
356{
357 if (temperature() >= m_sub.Tcrit()) {
358 double dens = density();
359 if (dens >= m_sub.Rhocrit()) {
360 return 0.0;
361 }
362 return 1.0;
363 }
364 // If below tcrit we always return 0 from this class
365 return 0.0;
366}
367
368}
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Declares a ThermoPhase class consisting of pure water (see Thermodynamic Properties and class WaterSS...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
doublereal atomicWeight(size_t m) const
Atomic weight of element m.
Definition: Phase.cpp:121
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
Definition: Phase.cpp:106
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition: Phase.cpp:687
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:751
virtual double density() const
Density (kg/m^3).
Definition: Phase.h:679
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:719
void setMolecularWeight(const int k, const double mw)
Set the molecular weight of a single species to a given value.
Definition: Phase.cpp:989
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
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.
doublereal coeffThermExp() const
Returns the coefficient of thermal expansion.
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density.
doublereal enthalpy() const
Calculate the enthalpy in mks units of J kmol-1 using the last temperature and density.
doublereal Tcrit() const
Returns the critical temperature of water (Kelvin)
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
doublereal Rhocrit() const
Return the critical density of water (kg m-3)
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
doublereal psat(doublereal temperature, int waterState=WATER_LIQUID)
This function returns the saturation pressure given the temperature as an input parameter,...
void setState_TR(doublereal temperature, doublereal rho)
Set the internal state of the object wrt temperature and density.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
doublereal isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
doublereal Pcrit() const
Returns the critical pressure of water (22.064E6 Pa)
The WaterProps class is used to house several approximation routines for properties of water.
Definition: WaterProps.h:100
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: WaterSSTP.cpp:171
WaterPropsIAPWS m_sub
WaterPropsIAPWS that calculates the real properties of water.
Definition: WaterSSTP.h:231
bool m_ready
Boolean is true if object has been properly initialized for calculation.
Definition: WaterSSTP.h:259
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: WaterSSTP.cpp:125
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
Definition: WaterSSTP.cpp:259
virtual doublereal critPressure() const
Critical pressure (Pa).
Definition: WaterSSTP.cpp:320
doublereal EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition: WaterSSTP.h:249
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: WaterSSTP.cpp:147
virtual doublereal vaporFraction() const
Return the fraction of vapor at the current conditions.
Definition: WaterSSTP.cpp:355
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: WaterSSTP.cpp:293
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: WaterSSTP.cpp:142
virtual doublereal dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient.
Definition: WaterSSTP.cpp:298
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: WaterSSTP.cpp:120
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: WaterSSTP.cpp:264
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: WaterSSTP.cpp:45
virtual void getStandardChemPotentials(doublereal *gss) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: WaterSSTP.cpp:133
virtual doublereal critTemperature() const
Critical temperature (K).
Definition: WaterSSTP.cpp:315
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition: WaterSSTP.cpp:199
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition: WaterSSTP.cpp:115
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
Definition: WaterSSTP.cpp:330
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition: WaterSSTP.cpp:221
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: WaterSSTP.cpp:105
doublereal m_mw
Molecular weight of Water -> Cantera assumption.
Definition: WaterSSTP.h:242
virtual void getStandardVolumes_ref(doublereal *vol) const
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
Definition: WaterSSTP.cpp:241
virtual void setDensity(const doublereal dens)
Set the density of the phase.
Definition: WaterSSTP.cpp:341
virtual doublereal satPressure(doublereal t)
Return the saturation pressure given the temperature.
Definition: WaterSSTP.cpp:347
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: WaterSSTP.h:256
WaterSSTP(const std::string &inputFile="", const std::string &id="")
Full constructor for a water phase.
Definition: WaterSSTP.cpp:18
bool m_allowGasPhase
Since this phase represents a liquid (or supercritical) phase, it is an error to return a gas-phase a...
Definition: WaterSSTP.h:267
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
Definition: WaterSSTP.cpp:191
std::unique_ptr< WaterProps > m_waterProps
Pointer to the WaterProps object.
Definition: WaterSSTP.h:239
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: WaterSSTP.cpp:110
virtual doublereal critDensity() const
Critical density (kg/m3).
Definition: WaterSSTP.cpp:325
virtual std::string phaseOfMatter() const
String indicating the mechanical phase of the matter in this Phase.
Definition: WaterSSTP.cpp:38
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Definition: WaterSSTP.cpp:152
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: WaterSSTP.cpp:288
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
void _require(const std::string &a, const std::string &v) const
Require that the current XML node has an attribute named by the first argument, a,...
Definition: xml.cpp:577
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:192
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:81
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Contains declarations for string manipulation functions within Cantera.