Cantera  2.1.2
PDSS_Water.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_Water.cpp
3  *
4  */
5 /*
6  * Copyright (2006) Sandia Corporation. Under the terms of
7  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
8  * U.S. Government retains certain rights in this software.
9  */
10 #include "cantera/base/ct_defs.h"
11 
12 #include "cantera/base/xml.h"
13 #include "cantera/base/ctml.h"
15 
21 
22 #include <fstream>
23 
24 namespace Cantera
25 {
27  PDSS(),
28  m_sub(0),
29  m_waterProps(0),
30  m_dens(1000.0),
31  m_iState(WATER_LIQUID),
32  EW_Offset(0.0),
33  SW_Offset(0.0),
34  m_verbose(0),
35  m_allowGasPhase(false)
36 {
37  m_pdssType = cPDSS_WATER;
38  m_sub = new WaterPropsIAPWS();
40  m_spthermo = 0;
41  constructSet();
42  m_minTemp = 200.;
43  m_maxTemp = 10000.;
44 }
45 
47  PDSS(tp, spindex),
48  m_sub(0),
49  m_waterProps(0),
50  m_dens(1000.0),
51  m_iState(WATER_LIQUID),
52  EW_Offset(0.0),
53  SW_Offset(0.0),
54  m_verbose(0),
55  m_allowGasPhase(false)
56 {
57  m_pdssType = cPDSS_WATER;
58  m_sub = new WaterPropsIAPWS();
60  m_spthermo = 0;
61  constructSet();
62  m_minTemp = 200.;
63  m_maxTemp = 10000.;
64 }
65 
67  const std::string& inputFile, const std::string& id) :
68  PDSS(tp, spindex),
69  m_sub(0),
70  m_waterProps(0),
71  m_dens(1000.0),
72  m_iState(WATER_LIQUID),
73  EW_Offset(0.0),
74  SW_Offset(0.0),
75  m_verbose(0),
76  m_allowGasPhase(false)
77 {
78  m_pdssType = cPDSS_WATER;
79  m_sub = new WaterPropsIAPWS();
81  constructPDSSFile(tp, spindex, inputFile, id);
82  m_spthermo = 0;
83  m_minTemp = 200.;
84  m_maxTemp = 10000.;
85 }
86 
88  const XML_Node& speciesNode,
89  const XML_Node& phaseRoot, bool spInstalled) :
90  PDSS(tp, spindex),
91  m_sub(0),
92  m_waterProps(0),
93  m_dens(1000.0),
94  m_iState(WATER_LIQUID),
95  EW_Offset(0.0),
96  SW_Offset(0.0),
97  m_verbose(0),
98  m_allowGasPhase(false)
99 {
100  m_pdssType = cPDSS_WATER;
101  m_sub = new WaterPropsIAPWS();
103  std::string id= "";
104  constructPDSSXML(tp, spindex, phaseRoot, id) ;
105  initThermo();
106  m_spthermo = 0;
107  m_minTemp = 200.;
108  m_maxTemp = 10000.;
109 }
110 
112  PDSS(),
113  m_sub(0),
114  m_waterProps(0),
115  m_dens(1000.0),
116  m_iState(WATER_LIQUID),
117  EW_Offset(b.EW_Offset),
118  SW_Offset(b.SW_Offset),
119  m_verbose(b.m_verbose),
120  m_allowGasPhase(b.m_allowGasPhase)
121 {
122  m_sub = new WaterPropsIAPWS();
123  /*
124  * Use the assignment operator to do the brunt
125  * of the work for the copy constructor.
126  */
127  *this = b;
128 }
129 
131 {
132  if (&b == this) {
133  return *this;
134  }
135  /*
136  * Call the base class operator
137  */
138  PDSS::operator=(b);
139 
140  if (!m_sub) {
141  m_sub = new WaterPropsIAPWS();
142  }
143  m_sub->operator=(*(b.m_sub));
144 
145  if (!m_waterProps) {
147  }
148  m_waterProps->operator=(*(b.m_waterProps));
149 
150  m_dens = b.m_dens;
151  m_iState = b.m_iState;
152  EW_Offset = b.EW_Offset;
153  SW_Offset = b.SW_Offset;
154  m_verbose = b.m_verbose;
156 
157  return *this;
158 }
159 
161 {
162  delete m_waterProps;
163  delete m_sub;
164 }
165 
167 {
168  return new PDSS_Water(*this);
169 }
170 
172  const XML_Node& phaseNode, const std::string& id)
173 {
174  constructSet();
175 }
176 
178  const std::string& inputFile, const std::string& id)
179 {
180  if (inputFile.size() == 0) {
181  throw CanteraError("PDSS_Water::constructPDSSFile",
182  "input file is null");
183  }
184  std::string path = findInputFile(inputFile);
185  std::ifstream fin(path.c_str());
186  if (!fin) {
187  throw CanteraError("PDSS_Water::initThermo","could not open "
188  +path+" for reading.");
189  }
190  /*
191  * The phase object automatically constructs an XML object.
192  * Use this object to store information.
193  */
194 
195  XML_Node* fxml = new XML_Node();
196  fxml->build(fin);
197  XML_Node* fxml_phase = findXMLPhase(fxml, id);
198  if (!fxml_phase) {
199  throw CanteraError("PDSS_Water::initThermo",
200  "ERROR: Can not find phase named " +
201  id + " in file named " + inputFile);
202  }
203  constructPDSSXML(tp, spindex, *fxml_phase, id);
204  delete fxml;
205 }
206 
208 {
209  delete m_sub;
210  m_sub = new WaterPropsIAPWS();
211  if (m_sub == 0) {
212  throw CanteraError("PDSS_Water::initThermo",
213  "could not create new substance object.");
214  }
215  /*
216  * Calculate the molecular weight.
217  * hard coded to Cantera's elements and Water.
218  */
219  m_mw = 2 * 1.00794 + 15.9994;
220 
221  /*
222  * Set the baseline
223  */
224  doublereal T = 298.15;
225 
226  m_p0 = OneAtm;
227 
228  doublereal presLow = 1.0E-2;
229  doublereal oneBar = 1.0E5;
230  doublereal dens = 1.0E-9;
231  m_dens = m_sub->density(T, presLow, WATER_GAS, dens);
232  m_pres = presLow;
233  SW_Offset = 0.0;
234  doublereal s = entropy_mole();
235  s -= GasConstant * log(oneBar/presLow);
236  if (s != 188.835E3) {
237  SW_Offset = 188.835E3 - s;
238  }
239  s = entropy_mole();
240  s -= GasConstant * log(oneBar/presLow);
241  //printf("s = %g\n", s);
242 
243  doublereal h = enthalpy_mole();
244  if (h != -241.826E6) {
245  EW_Offset = -241.826E6 - h;
246  }
247  h = enthalpy_mole();
248  //printf("h = %g\n", h);
249 
250  /*
251  * Set the initial state of the system to 298.15 K and
252  * 1 bar.
253  */
254  setTemperature(298.15);
255  m_dens = m_sub->density(298.15, OneAtm, WATER_LIQUID);
256  m_pres = OneAtm;
257 }
258 
260 {
262 }
263 
264 void PDSS_Water::initThermoXML(const XML_Node& phaseNode, const std::string& id)
265 {
266  PDSS::initThermoXML(phaseNode, id);
267 }
268 
269 doublereal PDSS_Water::enthalpy_mole() const
270 {
271  doublereal h = m_sub->enthalpy();
272  return h + EW_Offset;
273 }
274 
275 doublereal PDSS_Water::intEnergy_mole() const
276 {
277  doublereal u = m_sub->intEnergy();
278  return u + EW_Offset;
279 }
280 
281 doublereal PDSS_Water::entropy_mole() const
282 {
283  doublereal s = m_sub->entropy();
284  return s + SW_Offset;
285 }
286 
287 doublereal PDSS_Water::gibbs_mole() const
288 {
289  doublereal g = m_sub->Gibbs();
290  return g + EW_Offset - SW_Offset*m_temp;
291 }
292 
293 doublereal PDSS_Water::cp_mole() const
294 {
295  return m_sub->cp();
296 }
297 
298 doublereal PDSS_Water::cv_mole() const
299 {
300  return m_sub->cv();
301 }
302 
303 doublereal PDSS_Water::molarVolume() const
304 {
305  return m_sub->molarVolume();
306 }
307 
308 doublereal PDSS_Water::gibbs_RT_ref() const
309 {
310  doublereal T = m_temp;
311  m_sub->density(T, m_p0);
312  doublereal h = m_sub->enthalpy();
314  return (h + EW_Offset - SW_Offset*T)/(T * GasConstant);
315 }
316 
317 doublereal PDSS_Water::enthalpy_RT_ref() const
318 {
319  doublereal T = m_temp;
320  m_sub->density(T, m_p0);
321  doublereal h = m_sub->enthalpy();
323  return (h + EW_Offset)/(T * GasConstant);
324 }
325 
326 doublereal PDSS_Water::entropy_R_ref() const
327 {
328  doublereal T = m_temp;
329  m_sub->density(T, m_p0);
330  doublereal s = m_sub->entropy();
332  return (s + SW_Offset)/GasConstant;
333 }
334 
335 doublereal PDSS_Water::cp_R_ref() const
336 {
337  doublereal T = m_temp;
338  m_sub->density(T, m_p0);
339  doublereal cp = m_sub->cp();
341  return cp/GasConstant;
342 }
343 
344 doublereal PDSS_Water::molarVolume_ref() const
345 {
346  doublereal T = m_temp;
347  m_sub->density(T, m_p0);
348  doublereal mv = m_sub->molarVolume();
350  return mv;
351 }
352 
353 doublereal PDSS_Water::pressure() const
354 {
355  doublereal p = m_sub->pressure();
356  m_pres = p;
357  return p;
358 }
359 
360 void PDSS_Water::setPressure(doublereal p)
361 {
362  // In this routine we must be sure to only find the water branch of the
363  // curve and not the gas branch
364  doublereal T = m_temp;
365  doublereal dens = m_dens;
366  int waterState = WATER_LIQUID;
367  if (T > m_sub->Tcrit()) {
368  waterState = WATER_SUPERCRIT;
369  }
370 
371 #ifdef DEBUG_HKM
372  //printf("waterPDSS: set pres = %g t = %g, waterState = %d\n",
373  // p, T, waterState);
374 #endif
375  doublereal dd = m_sub->density(T, p, waterState, dens);
376  if (dd <= 0.0) {
377  std::string stateString = "T = " +
378  fp2str(T) + " K and p = " + fp2str(p) + " Pa";
379  throw CanteraError("PDSS_Water:setPressure()",
380  "Failed to set water SS state: " + stateString);
381  }
382  m_dens = dd;
383  m_pres = p;
384 
385  // We are only putting the phase check here because of speed considerations.
386  m_iState = m_sub->phaseState(true);
387  if (! m_allowGasPhase) {
388  if (m_iState != WATER_SUPERCRIT && m_iState != WATER_LIQUID && m_iState != WATER_UNSTABLELIQUID) {
389  throw CanteraError("PDSS_Water::setPressure",
390  "Water State isn't liquid or crit");
391  }
392  }
393 }
394 
396 {
397  return m_sub->coeffThermExp();
398 }
399 
401 {
402  doublereal pres = pressure();
403  doublereal dens_save = m_dens;
404  doublereal tt = m_temp - 0.04;
405  doublereal dd = m_sub->density(tt, pres, m_iState, m_dens);
406  if (dd < 0.0) {
407  throw CanteraError("PDSS_Water::dthermalExpansionCoeffdT",
408  "unable to solve for the density at T = " + fp2str(tt) + ", P = " + fp2str(pres));
409  }
410  doublereal vald = m_sub->coeffThermExp();
411  m_sub->setState_TR(m_temp, dens_save);
412  doublereal val2 = m_sub->coeffThermExp();
413  return (val2 - vald) / 0.04;
414 }
415 
417 {
419 }
420 
421 doublereal PDSS_Water::critTemperature() const
422 {
423  return m_sub->Tcrit();
424 }
425 
426 doublereal PDSS_Water::critPressure() const
427 {
428  return m_sub->Pcrit();
429 }
430 
431 doublereal PDSS_Water::critDensity() const
432 {
433  return m_sub->Rhocrit();
434 }
435 
436 void PDSS_Water::setDensity(doublereal dens)
437 {
438  m_dens = dens;
440 }
441 
442 doublereal PDSS_Water::density() const
443 {
444  return m_dens;
445 }
446 
447 void PDSS_Water::setTemperature(doublereal temp)
448 {
449  m_temp = temp;
450  doublereal dd = m_dens;
451  m_sub->setState_TR(temp, dd);
452 }
453 
454 void PDSS_Water::setState_TP(doublereal temp, doublereal pres)
455 {
456  m_temp = temp;
457  setPressure(pres);
458 }
459 
460 void PDSS_Water::setState_TR(doublereal temp, doublereal dens)
461 {
462  m_temp = temp;
463  m_dens = dens;
465 }
466 
467 doublereal PDSS_Water::pref_safe(doublereal temp) const
468 {
469  if (temp < m_sub->Tcrit()) {
470  doublereal pp = m_sub->psat_est(temp);
471  if (pp > OneAtm) {
472  return pp;
473  }
474  } else {
475  return m_sub->Pcrit();
476  }
477  return OneAtm;
478 }
479 
480 doublereal PDSS_Water::satPressure(doublereal t)
481 {
482  doublereal pp = m_sub->psat(t, WATER_LIQUID);
483  m_dens = m_sub->density();
484  m_temp = t;
485  return pp;
486 }
487 
488 }
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:293
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_Water.cpp:326
doublereal isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: PDSS_Water.cpp:395
doublereal m_dens
State of the system - density.
Definition: PDSS_Water.h:306
WaterPropsIAPWS * m_sub
Pointer to the WaterPropsIAPWS object, which does the actual calculations for the real equation of st...
Definition: PDSS_Water.h:289
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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
doublereal psat_est(doublereal temperature) const
This function returns an estimated value for the saturation pressure.
SpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:615
PDSS_Water & operator=(const PDSS_Water &b)
Assignment operator.
Definition: PDSS_Water.cpp:130
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:71
doublereal Tcrit() const
Returns the critical temperature of water (Kelvin)
void setState_TR(doublereal temperature, doublereal rho)
Set the internal state of the object wrt temperature and density.
std::string findInputFile(const std::string &name)
Find an input file.
Definition: global.cpp:191
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:175
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
void setDensity(doublereal dens)
Set the density of the water phase.
Definition: PDSS_Water.cpp:436
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
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.
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:576
virtual doublereal critTemperature() const
critical temperature
Definition: PDSS_Water.cpp:421
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual doublereal dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient. Units: 1/K2.
Definition: PDSS_Water.cpp:400
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.
void constructSet()
Internal routine that initializes the underlying water model.
Definition: PDSS_Water.cpp:207
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:442
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS_Water.cpp:264
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:570
void constructPDSSXML(VPStandardStateTP *vptp_ptr, int spindex, const XML_Node &phaseNode, const std::string &id)
Initialization of a PDSS object using an xml tree.
Definition: PDSS_Water.cpp:171
virtual doublereal critPressure() const
critical pressure
Definition: PDSS_Water.cpp:426
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_Water.cpp:344
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:269
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
void constructPDSSFile(VPStandardStateTP *vptp_ptr, int spindex, const std::string &inputFile, const std::string &id)
Initialization of a PDSS object using an input XML file.
Definition: PDSS_Water.cpp:177
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:467
virtual doublereal gibbs_RT_ref() const
Return the molar gibbs free energy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:308
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:183
doublereal molarVolume() const
Calculate the molar volume (kmol m-3) at the last temperature and density.
bool m_verbose
Verbose flag - used?
Definition: PDSS_Water.h:335
The WaterProps class is used to house several approximation routines for properties of water...
Definition: WaterProps.h:96
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:454
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:29
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:54
doublereal enthalpy() const
Calculate the enthalpy in mks units of J kmol-1 using the last temperature and density.
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_Water.cpp:480
Classes providing support for XML data files.
doublereal Rhocrit() const
Return the critical density of water (kg m-3)
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:317
virtual doublereal pressure() const
Returns the pressure (Pa)
Definition: PDSS_Water.cpp:353
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_Water.cpp:275
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Definition: PDSS_Water.cpp:166
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_Water.cpp:287
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS_Water.cpp:259
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:298
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density...
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_Water.cpp:460
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:585
int m_iState
state of the fluid
Definition: PDSS_Water.h:318
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_Water.cpp:447
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:582
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_Water.cpp:303
virtual doublereal critDensity() const
critical density
Definition: PDSS_Water.cpp:431
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: PDSS_Water.h:332
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
doublereal Pcrit() const
Returns the critical pressure of water (22.064E6 Pa)
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:195
virtual ~PDSS_Water()
Destructor.
Definition: PDSS_Water.cpp:160
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:573
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: PDSS_Water.cpp:416
PDSS & operator=(const PDSS &b)
Assignment operator.
Definition: PDSS.cpp:110
Contains declarations for string manipulation functions within Cantera.
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
WaterProps * m_waterProps
Pointer to the WaterProps object.
Definition: PDSS_Water.h:299
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_Water.cpp:360
bool m_allowGasPhase
Since this phase represents a liquid phase, it's an error to return a gas-phase answer.
Definition: PDSS_Water.h:344
doublereal EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition: PDSS_Water.h:325
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:776
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_Water.cpp:335
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:281
PDSS_Water()
Bare constructor.
Definition: PDSS_Water.cpp:26
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:579
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:601
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.
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...