Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/ctml.h"
14 
15 #include <fstream>
16 
17 namespace Cantera
18 {
20  m_waterProps(&m_sub),
21  m_dens(1000.0),
22  m_iState(WATER_LIQUID),
23  EW_Offset(0.0),
24  SW_Offset(0.0),
25  m_verbose(0),
26  m_allowGasPhase(false)
27 {
28  m_pdssType = cPDSS_WATER;
29  m_spthermo = 0;
30  constructSet();
31  m_minTemp = 200.;
32  m_maxTemp = 10000.;
33 }
34 
36  PDSS(tp, spindex),
37  m_waterProps(&m_sub),
38  m_dens(1000.0),
39  m_iState(WATER_LIQUID),
40  EW_Offset(0.0),
41  SW_Offset(0.0),
42  m_verbose(0),
43  m_allowGasPhase(false)
44 {
45  m_pdssType = cPDSS_WATER;
46  m_spthermo = 0;
47  constructSet();
48  m_minTemp = 200.;
49  m_maxTemp = 10000.;
50 }
51 
53  const std::string& inputFile, const std::string& id) :
54  PDSS(tp, spindex),
55  m_waterProps(&m_sub),
56  m_dens(1000.0),
57  m_iState(WATER_LIQUID),
58  EW_Offset(0.0),
59  SW_Offset(0.0),
60  m_verbose(0),
61  m_allowGasPhase(false)
62 {
63  m_pdssType = cPDSS_WATER;
64  constructPDSSFile(tp, spindex, inputFile, id);
65  m_spthermo = 0;
66  m_minTemp = 200.;
67  m_maxTemp = 10000.;
68 }
69 
71  const XML_Node& speciesNode,
72  const XML_Node& phaseRoot, bool spInstalled) :
73  PDSS(tp, spindex),
74  m_waterProps(&m_sub),
75  m_dens(1000.0),
76  m_iState(WATER_LIQUID),
77  EW_Offset(0.0),
78  SW_Offset(0.0),
79  m_verbose(0),
80  m_allowGasPhase(false)
81 {
82  m_pdssType = cPDSS_WATER;
83  std::string id= "";
84  constructPDSSXML(tp, spindex, phaseRoot, id) ;
85  initThermo();
86  m_spthermo = 0;
87  m_minTemp = 200.;
88  m_maxTemp = 10000.;
89 }
90 
92  PDSS(),
93  m_waterProps(&m_sub),
94  m_dens(1000.0),
95  m_iState(WATER_LIQUID),
96  EW_Offset(b.EW_Offset),
97  SW_Offset(b.SW_Offset),
98  m_verbose(b.m_verbose),
99  m_allowGasPhase(b.m_allowGasPhase)
100 {
101  /*
102  * Use the assignment operator to do the brunt
103  * of the work for the copy constructor.
104  */
105  *this = b;
106 }
107 
109 {
110  if (&b == this) {
111  return *this;
112  }
113  /*
114  * Call the base class operator
115  */
116  PDSS::operator=(b);
117 
118  m_sub = b.m_sub;
120  m_dens = b.m_dens;
121  m_iState = b.m_iState;
122  EW_Offset = b.EW_Offset;
123  SW_Offset = b.SW_Offset;
124  m_verbose = b.m_verbose;
126 
127  return *this;
128 }
129 
131 {
132  return new PDSS_Water(*this);
133 }
134 
136  const XML_Node& phaseNode, const std::string& id)
137 {
138  constructSet();
139 }
140 
142  const std::string& inputFile, const std::string& id)
143 {
144  if (inputFile.size() == 0) {
145  throw CanteraError("PDSS_Water::constructPDSSFile",
146  "input file is null");
147  }
148  std::string path = findInputFile(inputFile);
149  std::ifstream fin(path.c_str());
150  if (!fin) {
151  throw CanteraError("PDSS_Water::initThermo","could not open "
152  +path+" for reading.");
153  }
154  /*
155  * The phase object automatically constructs an XML object.
156  * Use this object to store information.
157  */
158 
159  XML_Node fxml;
160  fxml.build(fin);
161  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
162  if (!fxml_phase) {
163  throw CanteraError("PDSS_Water::initThermo",
164  "ERROR: Can not find phase named " +
165  id + " in file named " + inputFile);
166  }
167  constructPDSSXML(tp, spindex, *fxml_phase, id);
168 }
169 
171 {
172  /*
173  * Calculate the molecular weight.
174  * hard coded to Cantera's elements and Water.
175  */
176  m_mw = 2 * 1.00794 + 15.9994;
177 
178  /*
179  * Set the baseline
180  */
181  doublereal T = 298.15;
182 
183  m_p0 = OneAtm;
184 
185  doublereal presLow = 1.0E-2;
186  doublereal oneBar = 1.0E5;
187  doublereal dens = 1.0E-9;
188  m_dens = m_sub.density(T, presLow, WATER_GAS, dens);
189  m_pres = presLow;
190  SW_Offset = 0.0;
191  doublereal s = entropy_mole();
192  s -= GasConstant * log(oneBar/presLow);
193  if (s != 188.835E3) {
194  SW_Offset = 188.835E3 - s;
195  }
196  s = entropy_mole();
197  s -= GasConstant * log(oneBar/presLow);
198 
199  doublereal h = enthalpy_mole();
200  if (h != -241.826E6) {
201  EW_Offset = -241.826E6 - h;
202  }
203  h = enthalpy_mole();
204 
205  /*
206  * Set the initial state of the system to 298.15 K and
207  * 1 bar.
208  */
209  setTemperature(298.15);
210  m_dens = m_sub.density(298.15, OneAtm, WATER_LIQUID);
211  m_pres = OneAtm;
212 }
213 
214 doublereal PDSS_Water::enthalpy_mole() const
215 {
216  return m_sub.enthalpy() + EW_Offset;
217 }
218 
219 doublereal PDSS_Water::intEnergy_mole() const
220 {
221  return m_sub.intEnergy() + EW_Offset;
222 }
223 
224 doublereal PDSS_Water::entropy_mole() const
225 {
226  return m_sub.entropy() + SW_Offset;
227 }
228 
229 doublereal PDSS_Water::gibbs_mole() const
230 {
231  return m_sub.Gibbs() + EW_Offset - SW_Offset*m_temp;
232 }
233 
234 doublereal PDSS_Water::cp_mole() const
235 {
236  return m_sub.cp();
237 }
238 
239 doublereal PDSS_Water::cv_mole() const
240 {
241  return m_sub.cv();
242 }
243 
244 doublereal PDSS_Water::molarVolume() const
245 {
246  return m_sub.molarVolume();
247 }
248 
249 doublereal PDSS_Water::gibbs_RT_ref() const
250 {
251  doublereal T = m_temp;
252  m_sub.density(T, m_p0);
253  doublereal h = m_sub.enthalpy();
255  return (h + EW_Offset - SW_Offset*T)/(T * GasConstant);
256 }
257 
258 doublereal PDSS_Water::enthalpy_RT_ref() const
259 {
260  doublereal T = m_temp;
261  m_sub.density(T, m_p0);
262  doublereal h = m_sub.enthalpy();
264  return (h + EW_Offset)/(T * GasConstant);
265 }
266 
267 doublereal PDSS_Water::entropy_R_ref() const
268 {
269  doublereal T = m_temp;
270  m_sub.density(T, m_p0);
271  doublereal s = m_sub.entropy();
273  return (s + SW_Offset)/GasConstant;
274 }
275 
276 doublereal PDSS_Water::cp_R_ref() const
277 {
278  doublereal T = m_temp;
279  m_sub.density(T, m_p0);
280  doublereal cp = m_sub.cp();
282  return cp/GasConstant;
283 }
284 
285 doublereal PDSS_Water::molarVolume_ref() const
286 {
287  doublereal T = m_temp;
288  m_sub.density(T, m_p0);
289  doublereal mv = m_sub.molarVolume();
291  return mv;
292 }
293 
294 doublereal PDSS_Water::pressure() const
295 {
296  m_pres = m_sub.pressure();
297  return m_pres;
298 }
299 
300 void PDSS_Water::setPressure(doublereal p)
301 {
302  // In this routine we must be sure to only find the water branch of the
303  // curve and not the gas branch
304  doublereal T = m_temp;
305  doublereal dens = m_dens;
306  int waterState = WATER_LIQUID;
307  if (T > m_sub.Tcrit()) {
308  waterState = WATER_SUPERCRIT;
309  }
310 
311  doublereal dd = m_sub.density(T, p, waterState, dens);
312  if (dd <= 0.0) {
313  std::string stateString = "T = " +
314  fp2str(T) + " K and p = " + fp2str(p) + " Pa";
315  throw CanteraError("PDSS_Water:setPressure()",
316  "Failed to set water SS state: " + stateString);
317  }
318  m_dens = dd;
319  m_pres = p;
320 
321  // We are only putting the phase check here because of speed considerations.
322  m_iState = m_sub.phaseState(true);
323  if (! m_allowGasPhase) {
324  if (m_iState != WATER_SUPERCRIT && m_iState != WATER_LIQUID && m_iState != WATER_UNSTABLELIQUID) {
325  throw CanteraError("PDSS_Water::setPressure",
326  "Water State isn't liquid or crit");
327  }
328  }
329 }
330 
332 {
333  return m_sub.coeffThermExp();
334 }
335 
337 {
338  doublereal pres = pressure();
339  doublereal dens_save = m_dens;
340  doublereal tt = m_temp - 0.04;
341  doublereal dd = m_sub.density(tt, pres, m_iState, m_dens);
342  if (dd < 0.0) {
343  throw CanteraError("PDSS_Water::dthermalExpansionCoeffdT",
344  "unable to solve for the density at T = " + fp2str(tt) + ", P = " + fp2str(pres));
345  }
346  doublereal vald = m_sub.coeffThermExp();
347  m_sub.setState_TR(m_temp, dens_save);
348  doublereal val2 = m_sub.coeffThermExp();
349  return (val2 - vald) / 0.04;
350 }
351 
353 {
355 }
356 
357 doublereal PDSS_Water::critTemperature() const
358 {
359  return m_sub.Tcrit();
360 }
361 
362 doublereal PDSS_Water::critPressure() const
363 {
364  return m_sub.Pcrit();
365 }
366 
367 doublereal PDSS_Water::critDensity() const
368 {
369  return m_sub.Rhocrit();
370 }
371 
372 void PDSS_Water::setDensity(doublereal dens)
373 {
374  m_dens = dens;
376 }
377 
378 doublereal PDSS_Water::density() const
379 {
380  return m_dens;
381 }
382 
383 void PDSS_Water::setTemperature(doublereal temp)
384 {
385  m_temp = temp;
386  m_sub.setState_TR(temp, m_dens);
387 }
388 
389 void PDSS_Water::setState_TP(doublereal temp, doublereal pres)
390 {
391  m_temp = temp;
392  setPressure(pres);
393 }
394 
395 void PDSS_Water::setState_TR(doublereal temp, doublereal dens)
396 {
397  m_temp = temp;
398  m_dens = dens;
400 }
401 
402 doublereal PDSS_Water::pref_safe(doublereal temp) const
403 {
404  if (temp < m_sub.Tcrit()) {
405  doublereal pp = m_sub.psat_est(temp);
406  if (pp > OneAtm) {
407  return pp;
408  }
409  } else {
410  return m_sub.Pcrit();
411  }
412  return OneAtm;
413 }
414 
415 doublereal PDSS_Water::satPressure(doublereal t)
416 {
417  doublereal pp = m_sub.psat(t, WATER_LIQUID);
418  m_dens = m_sub.density();
419  m_temp = t;
420  return pp;
421 }
422 
423 }
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:234
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_Water.cpp:267
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:331
doublereal m_dens
State of the system - density.
Definition: PDSS_Water.h:297
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:1108
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:604
PDSS_Water & operator=(const PDSS_Water &b)
Assignment operator.
Definition: PDSS_Water.cpp:108
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
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:156
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:372
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
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 m_pres
State of the system - pressure.
Definition: PDSS.h:565
WaterPropsIAPWS m_sub
Pointer to the WaterPropsIAPWS object, which does the actual calculations for the real equation of st...
Definition: PDSS_Water.h:280
virtual doublereal critTemperature() const
critical temperature
Definition: PDSS_Water.cpp:357
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...
virtual doublereal dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient. Units: 1/K2.
Definition: PDSS_Water.cpp:336
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
doublereal coeffThermExp() const
Returns the coefficient of thermal expansion.
void constructSet()
Internal routine that initializes the underlying water model.
Definition: PDSS_Water.cpp:170
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:378
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:559
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:135
virtual doublereal critPressure() const
critical pressure
Definition: PDSS_Water.cpp:362
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_Water.cpp:285
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:214
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:141
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:402
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:249
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:173
WaterProps m_waterProps
Pointer to the WaterProps object.
Definition: PDSS_Water.h:290
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:326
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:389
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:51
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:415
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:258
virtual doublereal pressure() const
Returns the pressure (Pa)
Definition: PDSS_Water.cpp:294
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_Water.cpp:219
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Definition: PDSS_Water.cpp:130
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_Water.cpp:229
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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:239
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:395
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:574
int m_iState
state of the fluid
Definition: PDSS_Water.h:309
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_Water.cpp:383
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:571
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_Water.cpp:244
virtual doublereal critDensity() const
critical density
Definition: PDSS_Water.cpp:367
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: PDSS_Water.h:323
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:193
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:562
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: PDSS_Water.cpp:352
PDSS & operator=(const PDSS &b)
Assignment operator.
Definition: PDSS.cpp:104
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...
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_Water.cpp:300
bool m_allowGasPhase
Since this phase represents a liquid phase, it's an error to return a gas-phase answer.
Definition: PDSS_Water.h:335
doublereal EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition: PDSS_Water.h:316
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:764
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_Water.cpp:276
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:224
PDSS_Water()
Bare constructor.
Definition: PDSS_Water.cpp:19
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:568
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:590
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...