Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
17 
18 using namespace std;
19 
20 namespace Cantera
21 {
22 WaterSSTP::WaterSSTP() :
23  m_sub(0),
24  m_waterProps(0),
25  m_mw(0.0),
26  EW_Offset(0.0),
27  SW_Offset(0.0),
28  m_ready(false),
29  m_allowGasPhase(false)
30 {
31 }
32 
33 WaterSSTP::WaterSSTP(const std::string& inputFile, const std::string& id) :
34  m_sub(0),
35  m_waterProps(0),
36  m_mw(0.0),
37  EW_Offset(0.0),
38  SW_Offset(0.0),
39  m_ready(false),
40  m_allowGasPhase(false)
41 {
42  initThermoFile(inputFile, id);
43 }
44 
45 WaterSSTP::WaterSSTP(XML_Node& phaseRoot, const std::string& id) :
46  m_sub(0),
47  m_waterProps(0),
48  m_mw(0.0),
49  EW_Offset(0.0),
50  SW_Offset(0.0),
51  m_ready(false),
52  m_allowGasPhase(false)
53 {
54  importPhase(*findXMLPhase(&phaseRoot, id), this);
55 }
56 
58  SingleSpeciesTP(b),
59  m_sub(0),
60  m_waterProps(0),
61  m_mw(b.m_mw),
62  EW_Offset(b.EW_Offset),
63  SW_Offset(b.SW_Offset),
64  m_ready(false),
65  m_allowGasPhase(b.m_allowGasPhase)
66 {
67  m_sub = new WaterPropsIAPWS(*(b.m_sub));
69 
70  /*
71  * Use the assignment operator to do the brunt
72  * of the work for the copy constructor.
73  */
74  *this = b;
75 }
76 
78 {
79  if (&b == this) {
80  return *this;
81  }
82  *m_sub = *b.m_sub;
83 
84  if (!m_waterProps) {
86  }
88 
89  m_mw = b.m_mw;
90  m_ready = b.m_ready;
92  return *this;
93 }
94 
96 {
97  return new WaterSSTP(*this);
98 }
99 
101 {
102  delete m_sub;
103  delete m_waterProps;
104 }
105 
106 void WaterSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
107 {
108  /*
109  * Do initializations that don't depend on knowing the XML file
110  */
111  initThermo();
112  delete m_sub;
113  m_sub = new WaterPropsIAPWS();
114  if (m_sub == 0) {
115  throw CanteraError("WaterSSTP::initThermo",
116  "could not create new substance object.");
117  }
118  /*
119  * Calculate the molecular weight. Note while there may
120  * be a very good calculated weight in the steam table
121  * class, using this weight may lead to codes exhibiting
122  * mass loss issues. We need to grab the elemental
123  * atomic weights used in the Element class and calculate
124  * a consistent H2O molecular weight based on that.
125  */
126  size_t nH = elementIndex("H");
127  if (nH == npos) {
128  throw CanteraError("WaterSSTP::initThermo",
129  "H not an element");
130  }
131  double mw_H = atomicWeight(nH);
132  size_t nO = elementIndex("O");
133  if (nO == npos) {
134  throw CanteraError("WaterSSTP::initThermo",
135  "O not an element");
136  }
137  double mw_O = atomicWeight(nO);
138  m_mw = 2.0 * mw_H + mw_O;
140  double one = 1.0;
141  setMoleFractions(&one);
142 
143  /*
144  * Set the baseline
145  */
146  doublereal T = 298.15;
147  Phase::setDensity(7.0E-8);
149 
150  doublereal presLow = 1.0E-2;
151  doublereal oneBar = 1.0E5;
152  doublereal dd = m_sub->density(T, presLow, WATER_GAS, 7.0E-8);
153  setDensity(dd);
154  setTemperature(T);
155  SW_Offset = 0.0;
156  doublereal s = entropy_mole();
157  s -= GasConstant * log(oneBar/presLow);
158  if (s != 188.835E3) {
159  SW_Offset = 188.835E3 - s;
160  }
161  s = entropy_mole();
162  s -= GasConstant * log(oneBar/presLow);
163 
164  doublereal h = enthalpy_mole();
165  if (h != -241.826E6) {
166  EW_Offset = -241.826E6 - h;
167  }
168  h = enthalpy_mole();
169 
170  /*
171  * Set the initial state of the system to 298.15 K and
172  * 1 bar.
173  */
174  setTemperature(298.15);
175  double rho0 = m_sub->density(298.15, OneAtm, WATER_LIQUID);
176  setDensity(rho0);
177 
179 
180 
181  /*
182  * We have to do something with the thermo function here.
183  */
184  delete m_spthermo;
185  m_spthermo = 0;
186 
187  /*
188  * Set the flag to say we are ready to calculate stuff
189  */
190  m_ready = true;
191 }
192 
194 {
195  eosdata._require("model","PureLiquidWater");
196 }
197 
198 void WaterSSTP::getEnthalpy_RT(doublereal* hrt) const
199 {
200  *hrt = (m_sub->enthalpy() + EW_Offset)/(GasConstant*temperature());
201 }
202 
203 void WaterSSTP::getIntEnergy_RT(doublereal* ubar) const
204 {
205  *ubar = (m_sub->intEnergy() + EW_Offset)/GasConstant;
206 }
207 
208 void WaterSSTP::getEntropy_R(doublereal* sr) const
209 {
210  sr[0] = (m_sub->entropy() + SW_Offset) / GasConstant;
211 }
212 
213 void WaterSSTP::getGibbs_RT(doublereal* grt) const
214 {
215  double T = temperature();
216  *grt = (m_sub->Gibbs() + EW_Offset - SW_Offset*T) / (GasConstant * T);
217  if (!m_ready) {
218  throw CanteraError("waterSSTP::", "Phase not ready");
219  }
220 }
221 
222 void WaterSSTP::getStandardChemPotentials(doublereal* gss) const
223 {
224  *gss = (m_sub->Gibbs() + EW_Offset - SW_Offset*temperature());
225  if (!m_ready) {
226  throw CanteraError("waterSSTP::", "Phase not ready");
227  }
228 }
229 
230 void WaterSSTP::getCp_R(doublereal* cpr) const
231 {
232  cpr[0] = m_sub->cp() / GasConstant;
233 }
234 
235 doublereal WaterSSTP::cv_mole() const
236 {
237  return m_sub->cv();
238 }
239 
240 void WaterSSTP::getEnthalpy_RT_ref(doublereal* hrt) const
241 {
242  doublereal p = pressure();
243  double T = temperature();
244  double dens = density();
245  int waterState = WATER_GAS;
246  double rc = m_sub->Rhocrit();
247  if (dens > rc) {
248  waterState = WATER_LIQUID;
249  }
250  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
251  if (dd <= 0.0) {
252  throw CanteraError("setPressure", "error");
253  }
254  doublereal h = m_sub->enthalpy();
255  *hrt = (h + EW_Offset) / (GasConstant * T);
256  dd = m_sub->density(T, p, waterState, dens);
257 }
258 
259 void WaterSSTP::getGibbs_RT_ref(doublereal* grt) const
260 {
261  doublereal p = pressure();
262  double T = temperature();
263  double dens = density();
264  int waterState = WATER_GAS;
265  double rc = m_sub->Rhocrit();
266  if (dens > rc) {
267  waterState = WATER_LIQUID;
268  }
269  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
270  if (dd <= 0.0) {
271  throw CanteraError("setPressure", "error");
272  }
273  m_sub->setState_TR(T, dd);
274  doublereal g = m_sub->Gibbs();
275  *grt = (g + EW_Offset - SW_Offset*T)/ (GasConstant * T);
276  dd = m_sub->density(T, p, waterState, dens);
277 
278 }
279 
280 void WaterSSTP::getGibbs_ref(doublereal* g) const
281 {
282  getGibbs_RT_ref(g);
283  doublereal rt = _RT();
284  for (size_t k = 0; k < m_kk; k++) {
285  g[k] *= rt;
286  }
287 }
288 
289 void WaterSSTP::getEntropy_R_ref(doublereal* sr) const
290 {
291  doublereal p = pressure();
292  double T = temperature();
293  double dens = density();
294  int waterState = WATER_GAS;
295  double rc = m_sub->Rhocrit();
296  if (dens > rc) {
297  waterState = WATER_LIQUID;
298  }
299  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
300 
301  if (dd <= 0.0) {
302  throw CanteraError("setPressure", "error");
303  }
304  m_sub->setState_TR(T, dd);
305 
306  doublereal s = m_sub->entropy();
307  *sr = (s + SW_Offset)/ (GasConstant);
308  dd = m_sub->density(T, p, waterState, dens);
309 
310 }
311 
312 void WaterSSTP::getCp_R_ref(doublereal* cpr) const
313 {
314  doublereal p = pressure();
315  double T = temperature();
316  double dens = density();
317  int waterState = WATER_GAS;
318  double rc = m_sub->Rhocrit();
319  if (dens > rc) {
320  waterState = WATER_LIQUID;
321  }
322  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
323  m_sub->setState_TR(T, dd);
324  if (dd <= 0.0) {
325  throw CanteraError("setPressure", "error");
326  }
327  doublereal cp = m_sub->cp();
328  *cpr = cp / (GasConstant);
329  dd = m_sub->density(T, p, waterState, dens);
330 }
331 
332 void WaterSSTP::getStandardVolumes_ref(doublereal* vol) const
333 {
334  doublereal p = pressure();
335  double T = temperature();
336  double dens = density();
337  int waterState = WATER_GAS;
338  double rc = m_sub->Rhocrit();
339  if (dens > rc) {
340  waterState = WATER_LIQUID;
341  }
342  doublereal dd = m_sub->density(T, OneAtm, waterState, dens);
343  if (dd <= 0.0) {
344  throw CanteraError("setPressure", "error");
345  }
346  *vol = meanMolecularWeight() /dd;
347  dd = m_sub->density(T, p, waterState, dens);
348 }
349 
350 doublereal WaterSSTP::pressure() const
351 {
352  return m_sub->pressure();
353 }
354 
355 void WaterSSTP::setPressure(doublereal p)
356 {
357  double T = temperature();
358  double dens = density();
359  int waterState = WATER_GAS;
360  double rc = m_sub->Rhocrit();
361  if (dens > rc) {
362  waterState = WATER_LIQUID;
363  }
364  doublereal dd = m_sub->density(T, p, waterState, dens);
365  if (dd <= 0.0) {
366  throw CanteraError("setPressure", "error");
367  }
368  setDensity(dd);
369 }
370 
372 {
374 }
375 
377 {
378  return m_sub->coeffThermExp();
379 }
380 
382 {
383  doublereal pres = pressure();
384  doublereal dens_save = density();
385  double T = temperature();
386  double tt = T - 0.04;
387  doublereal dd = m_sub->density(tt, pres, WATER_LIQUID, dens_save);
388  if (dd < 0.0) {
389  throw CanteraError("WaterSSTP::dthermalExpansionCoeffdT",
390  "Unable to solve for the density at T = " + fp2str(tt) + ", P = " + fp2str(pres));
391  }
392  doublereal vald = m_sub->coeffThermExp();
393  m_sub->setState_TR(T, dens_save);
394  doublereal val2 = m_sub->coeffThermExp();
395  return (val2 - vald) / 0.04;
396 }
397 
398 doublereal WaterSSTP::critTemperature() const
399 {
400  return m_sub->Tcrit();
401 }
402 
403 doublereal WaterSSTP::critPressure() const
404 {
405  return m_sub->Pcrit();
406 }
407 
408 doublereal WaterSSTP::critDensity() const
409 {
410  return m_sub->Rhocrit();
411 }
412 
413 void WaterSSTP::setTemperature(const doublereal temp)
414 {
415  Phase::setTemperature(temp);
416  m_sub->setState_TR(temp, density());
417 }
418 
419 void WaterSSTP::setDensity(const doublereal dens)
420 {
421  Phase::setDensity(dens);
422  m_sub->setState_TR(temperature(), dens);
423 }
424 
425 doublereal WaterSSTP::satPressure(doublereal t) {
426  doublereal tsave = temperature();
427  doublereal dsave = density();
428  doublereal pp = m_sub->psat(t);
429  m_sub->setState_TR(tsave, dsave);
430  return pp;
431 }
432 
433 doublereal WaterSSTP::vaporFraction() const
434 {
435  if (temperature() >= m_sub->Tcrit()) {
436  double dens = density();
437  if (dens >= m_sub->Rhocrit()) {
438  return 0.0;
439  }
440  return 1.0;
441  }
442  /*
443  * If below tcrit we always return 0 from this class
444  */
445  return 0.0;
446 }
447 
448 }
virtual void getEntropy_R_ref(doublereal *er) const
Definition: WaterSSTP.cpp:289
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:222
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:603
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:608
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:1108
virtual void setDensity(const doublereal dens)
Set the density of the phase.
Definition: WaterSSTP.cpp:419
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
doublereal Tcrit() const
Returns the critical temperature of water (Kelvin)
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
Definition: WaterSSTP.cpp:350
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:936
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:355
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:100
doublereal atomicWeight(size_t m) const
Atomic weight of element m.
Definition: Phase.cpp:207
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:213
WaterProps * m_waterProps
Pointer to the WaterProps object.
Definition: WaterSSTP.h:450
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: WaterSSTP.cpp:193
WaterSSTP()
Base constructor.
Definition: WaterSSTP.cpp:22
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:240
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
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:106
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: WaterSSTP.cpp:235
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:460
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: WaterSSTP.cpp:376
virtual doublereal critTemperature() const
critical temperature
Definition: WaterSSTP.cpp:398
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:453
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
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:203
doublereal Rhocrit() const
Return the critical density of water (kg m-3)
WaterSSTP & operator=(const WaterSSTP &)
Assignment operator.
Definition: WaterSSTP.cpp:77
doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
virtual doublereal critDensity() const
critical density
Definition: WaterSSTP.cpp:408
Class for single-component water.
Definition: WaterSSTP.h:125
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
WaterPropsIAPWS * m_sub
Pointer to the WaterPropsIAPWS that calculates the real properties of water.
Definition: WaterSSTP.h:440
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: WaterSSTP.cpp:425
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:371
void setMolecularWeight(const int k, const double mw)
Set the molecular weight of a single species to a given value.
Definition: Phase.h:838
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
doublereal Pcrit() const
Returns the critical pressure of water (22.064E6 Pa)
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
Definition: Phase.cpp:192
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
Definition: WaterSSTP.cpp:413
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:638
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:332
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:669
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
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:208
Contains declarations for string manipulation functions within Cantera.
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: WaterSSTP.h:467
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:198
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
void setMoleFractions(const doublereal *const x)
Mole fractions are fixed, with x[0] = 1.0.
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:230
virtual void getCp_R_ref(doublereal *cprt) const
Definition: WaterSSTP.cpp:312
size_t m_kk
Number of species in the phase.
Definition: Phase.h:843
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:478
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
virtual doublereal critPressure() const
critical pressure
Definition: WaterSSTP.cpp:403
virtual void getGibbs_RT_ref(doublereal *grt) const
Definition: WaterSSTP.cpp:259
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:381
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:623
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:95
virtual doublereal vaporFraction() const
Return the fraction of vapor at the current conditions.
Definition: WaterSSTP.cpp:433
virtual void getGibbs_ref(doublereal *g) const
Definition: WaterSSTP.cpp:280
bool m_ready
Boolean is true if object has been properly initialized for calculation.
Definition: WaterSSTP.h:470
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...