Cantera  2.1.2
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  * Copyright (2006) Sandia Corporation. Under the terms of
8  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
9  * U.S. Government retains certain rights in this software.
10  */
11 
16 #include "cantera/base/xml.h"
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 WaterSSTP::WaterSSTP() :
25  m_sub(0),
26  m_waterProps(0),
27  m_mw(0.0),
28  EW_Offset(0.0),
29  SW_Offset(0.0),
30  m_ready(false),
31  m_allowGasPhase(false)
32 {
33 }
34 
35 WaterSSTP::WaterSSTP(const std::string& inputFile, const std::string& id) :
37  m_sub(0),
38  m_waterProps(0),
39  m_mw(0.0),
40  EW_Offset(0.0),
41  SW_Offset(0.0),
42  m_ready(false),
43  m_allowGasPhase(false)
44 {
45  initThermoFile(inputFile, id);
46 }
47 
48 WaterSSTP::WaterSSTP(XML_Node& phaseRoot, const std::string& id) :
50  m_sub(0),
51  m_waterProps(0),
52  m_mw(0.0),
53  EW_Offset(0.0),
54  SW_Offset(0.0),
55  m_ready(false),
56  m_allowGasPhase(false)
57 {
58  importPhase(*findXMLPhase(&phaseRoot, id), this);
59 }
60 
62  SingleSpeciesTP(b),
63  m_sub(0),
64  m_waterProps(0),
65  m_mw(b.m_mw),
66  EW_Offset(b.EW_Offset),
67  SW_Offset(b.SW_Offset),
68  m_ready(false),
69  m_allowGasPhase(b.m_allowGasPhase)
70 {
71  m_sub = new WaterPropsIAPWS(*(b.m_sub));
73 
74  /*
75  * Use the assignment operator to do the brunt
76  * of the work for the copy constructor.
77  */
78  *this = b;
79 }
80 
82 {
83  if (&b == this) {
84  return *this;
85  }
86  m_sub->operator=(*(b.m_sub));
87 
88  if (!m_waterProps) {
90  }
91  m_waterProps->operator=(*(b.m_waterProps));
92 
93 
94  m_mw = b.m_mw;
95  m_ready = b.m_ready;
97  return *this;
98 }
99 
101 {
102  return new WaterSSTP(*this);
103 }
104 
106 {
107  delete m_sub;
108  delete m_waterProps;
109 }
110 
112 {
114 }
115 
116 void WaterSSTP::
117 initThermoXML(XML_Node& phaseNode, const std::string& id)
118 {
119  /*
120  * Do initializations that don't depend on knowing the XML file
121  */
122  initThermo();
123  delete m_sub;
124  m_sub = new WaterPropsIAPWS();
125  if (m_sub == 0) {
126  throw CanteraError("WaterSSTP::initThermo",
127  "could not create new substance object.");
128  }
129  /*
130  * Calculate the molecular weight. Note while there may
131  * be a very good calculated weight in the steam table
132  * class, using this weight may lead to codes exhibiting
133  * mass loss issues. We need to grab the elemental
134  * atomic weights used in the Element class and calculate
135  * a consistent H2O molecular weight based on that.
136  */
137  size_t nH = elementIndex("H");
138  if (nH == npos) {
139  throw CanteraError("WaterSSTP::initThermo",
140  "H not an element");
141  }
142  double mw_H = atomicWeight(nH);
143  size_t nO = elementIndex("O");
144  if (nO == npos) {
145  throw CanteraError("WaterSSTP::initThermo",
146  "O not an element");
147  }
148  double mw_O = atomicWeight(nO);
149  m_mw = 2.0 * mw_H + mw_O;
151  double one = 1.0;
152  setMoleFractions(&one);
153 
154  /*
155  * Set the baseline
156  */
157  doublereal T = 298.15;
158  Phase::setDensity(7.0E-8);
160 
161  doublereal presLow = 1.0E-2;
162  doublereal oneBar = 1.0E5;
163  doublereal dd = m_sub->density(T, presLow, WATER_GAS, 7.0E-8);
164  setDensity(dd);
165  setTemperature(T);
166  SW_Offset = 0.0;
167  doublereal s = entropy_mole();
168  s -= GasConstant * log(oneBar/presLow);
169  if (s != 188.835E3) {
170  SW_Offset = 188.835E3 - s;
171  }
172  s = entropy_mole();
173  s -= GasConstant * log(oneBar/presLow);
174  //printf("s = %g\n", s);
175 
176  doublereal h = enthalpy_mole();
177  if (h != -241.826E6) {
178  EW_Offset = -241.826E6 - h;
179  }
180  h = enthalpy_mole();
181 
182  //printf("h = %g\n", h);
183 
184 
185  /*
186  * Set the initial state of the system to 298.15 K and
187  * 1 bar.
188  */
189  setTemperature(298.15);
190  double rho0 = m_sub->density(298.15, OneAtm, WATER_LIQUID);
191  setDensity(rho0);
192 
194 
195 
196  /*
197  * We have to do something with the thermo function here.
198  */
199  if (m_spthermo) {
200  delete m_spthermo;
201  m_spthermo = 0;
202  }
203 
204  /*
205  * Set the flag to say we are ready to calculate stuff
206  */
207  m_ready = true;
208 }
209 
210 void WaterSSTP::
212 {
213  eosdata._require("model","PureLiquidWater");
214 }
215 
216 void WaterSSTP::getEnthalpy_RT(doublereal* hrt) const
217 {
218  double T = temperature();
219  doublereal h = m_sub->enthalpy();
220  *hrt = (h + EW_Offset)/(GasConstant*T);
221 }
222 
223 void WaterSSTP::getIntEnergy_RT(doublereal* ubar) const
224 {
225  doublereal u = m_sub->intEnergy();
226  *ubar = (u + EW_Offset)/GasConstant;
227 }
228 
229 void WaterSSTP::getEntropy_R(doublereal* sr) const
230 {
231  doublereal s = m_sub->entropy();
232  sr[0] = (s + SW_Offset) / GasConstant;
233 }
234 
235 void WaterSSTP::getGibbs_RT(doublereal* grt) const
236 {
237  double T = temperature();
238  doublereal g = m_sub->Gibbs();
239  *grt = (g + EW_Offset - SW_Offset*T) / (GasConstant * T);
240  if (!m_ready) {
241  throw CanteraError("waterSSTP::", "Phase not ready");
242  }
243 }
244 
245 void WaterSSTP::getStandardChemPotentials(doublereal* gss) const
246 {
247  double T = temperature();
248  doublereal g = m_sub->Gibbs();
249  *gss = (g + EW_Offset - SW_Offset*T);
250  if (!m_ready) {
251  throw CanteraError("waterSSTP::", "Phase not ready");
252  }
253 }
254 
255 void WaterSSTP::getCp_R(doublereal* cpr) const
256 {
257  doublereal cp = m_sub->cp();
258  cpr[0] = cp / GasConstant;
259 }
260 
261 doublereal WaterSSTP::cv_mole() const
262 {
263  return m_sub->cv();
264 }
265 
266 void WaterSSTP::getEnthalpy_RT_ref(doublereal* hrt) const
267 {
268  doublereal p = pressure();
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, OneAtm, waterState, dens);
277  if (dd <= 0.0) {
278  throw CanteraError("setPressure", "error");
279  }
280  doublereal h = m_sub->enthalpy();
281  *hrt = (h + EW_Offset) / (GasConstant * T);
282  dd = m_sub->density(T, p, waterState, dens);
283 }
284 
285 void WaterSSTP::getGibbs_RT_ref(doublereal* grt) const
286 {
287  doublereal p = pressure();
288  double T = temperature();
289  double dens = density();
290  int waterState = WATER_GAS;
291  double rc = m_sub->Rhocrit();
292  if (dens > rc) {
293  waterState = WATER_LIQUID;
294  }
295  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
296  if (dd <= 0.0) {
297  throw CanteraError("setPressure", "error");
298  }
299  m_sub->setState_TR(T, dd);
300  doublereal g = m_sub->Gibbs();
301  *grt = (g + EW_Offset - SW_Offset*T)/ (GasConstant * T);
302  dd = m_sub->density(T, p, waterState, dens);
303 
304 }
305 
306 void WaterSSTP::getGibbs_ref(doublereal* g) const
307 {
308  getGibbs_RT_ref(g);
309  doublereal rt = _RT();
310  for (size_t k = 0; k < m_kk; k++) {
311  g[k] *= rt;
312  }
313 }
314 
315 void WaterSSTP::getEntropy_R_ref(doublereal* sr) const
316 {
317  doublereal p = pressure();
318  double T = temperature();
319  double dens = density();
320  int waterState = WATER_GAS;
321  double rc = m_sub->Rhocrit();
322  if (dens > rc) {
323  waterState = WATER_LIQUID;
324  }
325  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
326 
327  if (dd <= 0.0) {
328  throw CanteraError("setPressure", "error");
329  }
330  m_sub->setState_TR(T, dd);
331 
332  doublereal s = m_sub->entropy();
333  *sr = (s + SW_Offset)/ (GasConstant);
334  dd = m_sub->density(T, p, waterState, dens);
335 
336 }
337 
338 void WaterSSTP::getCp_R_ref(doublereal* cpr) const
339 {
340  doublereal p = pressure();
341  double T = temperature();
342  double dens = density();
343  int waterState = WATER_GAS;
344  double rc = m_sub->Rhocrit();
345  if (dens > rc) {
346  waterState = WATER_LIQUID;
347  }
348  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
349  m_sub->setState_TR(T, dd);
350  if (dd <= 0.0) {
351  throw CanteraError("setPressure", "error");
352  }
353  doublereal cp = m_sub->cp();
354  *cpr = cp / (GasConstant);
355  dd = m_sub->density(T, p, waterState, dens);
356 }
357 
358 void WaterSSTP::getStandardVolumes_ref(doublereal* vol) const
359 {
360  doublereal p = pressure();
361  double T = temperature();
362  double dens = density();
363  int waterState = WATER_GAS;
364  double rc = m_sub->Rhocrit();
365  if (dens > rc) {
366  waterState = WATER_LIQUID;
367  }
368  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
369  if (dd <= 0.0) {
370  throw CanteraError("setPressure", "error");
371  }
372  *vol = meanMolecularWeight() /dd;
373  dd = m_sub->density(T, p, waterState, dens);
374 }
375 
376 doublereal WaterSSTP::pressure() const
377 {
378  return m_sub->pressure();
379 }
380 
381 void WaterSSTP::
382 setPressure(doublereal p)
383 {
384  double T = temperature();
385  double dens = density();
386  int waterState = WATER_GAS;
387  double rc = m_sub->Rhocrit();
388  if (dens > rc) {
389  waterState = WATER_LIQUID;
390  }
391  doublereal dd = m_sub->density(T, p, waterState, dens);
392  if (dd <= 0.0) {
393  throw CanteraError("setPressure", "error");
394  }
395  setDensity(dd);
396 }
397 
399 {
401 }
402 
404 {
405  return m_sub->coeffThermExp();
406 }
407 
409 {
410  doublereal pres = pressure();
411  doublereal dens_save = density();
412  double T = temperature();
413  double tt = T - 0.04;
414  doublereal dd = m_sub->density(tt, pres, WATER_LIQUID, dens_save);
415  if (dd < 0.0) {
416  throw CanteraError("WaterSSTP::dthermalExpansionCoeffdT",
417  "Unable to solve for the density at T = " + fp2str(tt) + ", P = " + fp2str(pres));
418  }
419  doublereal vald = m_sub->coeffThermExp();
420  m_sub->setState_TR(T, dens_save);
421  doublereal val2 = m_sub->coeffThermExp();
422  return (val2 - vald) / 0.04;
423 }
424 
425 doublereal WaterSSTP::critTemperature() const
426 {
427  return m_sub->Tcrit();
428 }
429 
430 doublereal WaterSSTP::critPressure() const
431 {
432  return m_sub->Pcrit();
433 }
434 
435 doublereal WaterSSTP::critDensity() const
436 {
437  return m_sub->Rhocrit();
438 }
439 
440 void WaterSSTP::setTemperature(const doublereal temp)
441 {
442  Phase::setTemperature(temp);
443  doublereal dd = density();
444  m_sub->setState_TR(temp, dd);
445 }
446 
447 void WaterSSTP::setDensity(const doublereal dens)
448 {
449  Phase::setDensity(dens);
450  doublereal temp = temperature();
451  m_sub->setState_TR(temp, dens);
452 }
453 
454 doublereal WaterSSTP::satPressure(doublereal t) {
455  doublereal tsave = temperature();
456  doublereal dsave = density();
457  doublereal pp = m_sub->psat(t);
458  m_sub->setState_TR(tsave, dsave);
459  return pp;
460 }
461 
462 doublereal WaterSSTP::vaporFraction() const
463 {
464  if (temperature() >= m_sub->Tcrit()) {
465  double dens = density();
466  if (dens >= m_sub->Rhocrit()) {
467  return 0.0;
468  }
469  return 1.0;
470  }
471  /*
472  * If below tcrit we always return 0 from this class
473  */
474  return 0.0;
475 }
476 
477 }
virtual void getEntropy_R_ref(doublereal *er) const
Definition: WaterSSTP.cpp:315
virtual void getStandardChemPotentials(doublereal *gss) const
Get the gibbs function for the species standard states at the current T and P of the solution...
Definition: WaterSSTP.cpp:245
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:614
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:534
doublereal isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
Definition: xml.cpp:1104
virtual void setDensity(const doublereal dens)
Set the density of the phase.
Definition: WaterSSTP.cpp:447
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:71
doublereal Tcrit() const
Returns the critical temperature of water (Kelvin)
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
Definition: WaterSSTP.cpp:376
void setState_TR(doublereal temperature, doublereal rho)
Set the internal state of the object wrt temperature and density.
doublereal _RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:977
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: WaterSSTP.cpp:382
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
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 for calculating the equation of state of water.
virtual ~WaterSSTP()
Destructor.
Definition: WaterSSTP.cpp:105
doublereal atomicWeight(size_t m) const
Atomic weight of element m.
Definition: Phase.cpp:179
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
Header for a class used to house several approximation routines for properties of water...
doublereal coeffThermExp() const
Returns the coefficient of thermal expansion.
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional gibbs function for the species standard states at the current T and P of the s...
Definition: WaterSSTP.cpp:235
WaterProps * m_waterProps
Pointer to the WaterProps object.
Definition: WaterSSTP.h:470
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: WaterSSTP.cpp:211
WaterSSTP()
Base constructor.
Definition: WaterSSTP.cpp:23
Declares a ThermoPhase class consisting of pure water (see Thermodynamic Properties and class WaterSS...
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition: WaterSSTP.cpp:266
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Definition: WaterSSTP.cpp:117
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: WaterSSTP.cpp:261
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty thermophase object.
doublereal EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition: WaterSSTP.h:480
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: WaterSSTP.cpp:403
virtual doublereal critTemperature() const
critical temperature
Definition: WaterSSTP.cpp:425
doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
The WaterProps class is used to house several approximation routines for properties of water...
Definition: WaterProps.h:96
doublereal m_mw
Molecular weight of Water -> Cantera assumption.
Definition: WaterSSTP.h:473
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:29
doublereal enthalpy() const
Calculate the enthalpy in mks units of J kmol-1 using the last temperature and density.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
Definition: WaterSSTP.cpp:223
Classes providing support for XML data files.
doublereal Rhocrit() const
Return the critical density of water (kg m-3)
WaterSSTP & operator=(const WaterSSTP &)
Assignment operator.
Definition: WaterSSTP.cpp:81
doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
virtual doublereal critDensity() const
critical density
Definition: WaterSSTP.cpp:435
Class for single-component water.
Definition: WaterSSTP.h:125
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
WaterPropsIAPWS * m_sub
Pointer to the WaterPropsIAPWS that calculates the real properties of water.
Definition: WaterSSTP.h:460
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values There is no restriction on the sum of the mole fractio...
Definition: Phase.cpp:306
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: WaterSSTP.cpp:454
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density...
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: WaterSSTP.cpp:398
void setMolecularWeight(const int k, const double mw)
Set the molecular weight of a single species to a given value.
Definition: Phase.h:711
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
doublereal Pcrit() const
Returns the critical pressure of water (22.064E6 Pa)
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: WaterSSTP.cpp:111
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
Definition: Phase.cpp:164
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
Definition: WaterSSTP.cpp:440
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:562
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:358
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:588
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
void getEntropy_R(doublereal *sr) const
Get the nondimensional Entropies for the species standard states at the current T and P of the soluti...
Definition: WaterSSTP.cpp:229
Contains declarations for string manipulation functions within Cantera.
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: WaterSSTP.h:487
void getEnthalpy_RT(doublereal *hrt) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
Definition: WaterSSTP.cpp:216
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional heat capacity at constant pressure function for the species standard states at...
Definition: WaterSSTP.cpp:255
virtual void getCp_R_ref(doublereal *cprt) const
Definition: WaterSSTP.cpp:338
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
bool m_allowGasPhase
Since this phase represents a liquid phase, it's an error to return a gas-phase answer.
Definition: WaterSSTP.h:498
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1625
virtual doublereal critPressure() const
critical pressure
Definition: WaterSSTP.cpp:430
virtual void getGibbs_RT_ref(doublereal *grt) const
Definition: WaterSSTP.cpp:285
The SingleSpeciesTP class is a filter class for ThermoPhase.
virtual doublereal dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient. Units: 1/K2.
Definition: WaterSSTP.cpp:408
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
Definition: Phase.h:549
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.
ThermoPhase * duplMyselfAsThermoPhase() const
Duplicator from a ThermoPhase object.
Definition: WaterSSTP.cpp:100
virtual doublereal vaporFraction() const
Return the fraction of vapor at the current conditions.
Definition: WaterSSTP.cpp:462
virtual void getGibbs_ref(doublereal *g) const
Definition: WaterSSTP.cpp:306
bool m_ready
Boolean is true if object has been properly initialized for calculation.
Definition: WaterSSTP.h:490
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...