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