Cantera  2.3.0
PDSS_Water.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_Water.cpp
3  */
4 
5 // This file is part of Cantera. See License.txt in the top-level directory or
6 // at http://www.cantera.org/license.txt for license and copyright information.
7 
8 #include "cantera/base/ctml.h"
12 
13 namespace Cantera
14 {
16  m_waterProps(&m_sub),
17  m_dens(1000.0),
18  m_iState(WATER_LIQUID),
19  EW_Offset(0.0),
20  SW_Offset(0.0),
21  m_verbose(0),
22  m_allowGasPhase(false)
23 {
24  m_pdssType = cPDSS_WATER;
25  m_spthermo = 0;
26  constructSet();
27  m_minTemp = 200.;
28  m_maxTemp = 10000.;
29 }
30 
32  PDSS(tp, spindex),
33  m_waterProps(&m_sub),
34  m_dens(1000.0),
35  m_iState(WATER_LIQUID),
36  EW_Offset(0.0),
37  SW_Offset(0.0),
38  m_verbose(0),
39  m_allowGasPhase(false)
40 {
41  m_pdssType = cPDSS_WATER;
42  m_spthermo = 0;
43  constructSet();
44  m_minTemp = 200.;
45  m_maxTemp = 10000.;
46 }
47 
49  const std::string& inputFile, const std::string& id) :
50  PDSS(tp, spindex),
51  m_waterProps(&m_sub),
52  m_dens(1000.0),
53  m_iState(WATER_LIQUID),
54  EW_Offset(0.0),
55  SW_Offset(0.0),
56  m_verbose(0),
57  m_allowGasPhase(false)
58 {
59  warn_deprecated("PDSS_Water constructor from XML input file",
60  "To be removed after Cantera 2.3.");
61  m_pdssType = cPDSS_WATER;
62  constructPDSSFile(tp, spindex, inputFile, id);
63  m_spthermo = 0;
64  m_minTemp = 200.;
65  m_maxTemp = 10000.;
66 }
67 
69  const XML_Node& speciesNode,
70  const XML_Node& phaseRoot, bool spInstalled) :
71  PDSS(tp, spindex),
72  m_waterProps(&m_sub),
73  m_dens(1000.0),
74  m_iState(WATER_LIQUID),
75  EW_Offset(0.0),
76  SW_Offset(0.0),
77  m_verbose(0),
78  m_allowGasPhase(false)
79 {
80  m_pdssType = cPDSS_WATER;
81  std::string id= "";
82  constructPDSSXML(tp, spindex, phaseRoot, id);
83  initThermo();
84  m_spthermo = 0;
85  m_minTemp = 200.;
86  m_maxTemp = 10000.;
87 }
88 
90  PDSS(),
91  m_waterProps(&m_sub),
92  m_dens(1000.0),
93  m_iState(WATER_LIQUID),
94  EW_Offset(b.EW_Offset),
95  SW_Offset(b.SW_Offset),
96  m_verbose(b.m_verbose),
97  m_allowGasPhase(b.m_allowGasPhase)
98 {
99  // Use the assignment operator to do the brunt of the work for the copy
100  // constructor.
101  *this = b;
102 }
103 
104 PDSS_Water& PDSS_Water::operator=(const PDSS_Water& b)
105 {
106  if (&b == this) {
107  return *this;
108  }
109  // Call the base class operator
110  PDSS::operator=(b);
111 
112  m_sub = b.m_sub;
113  m_waterProps = b.m_waterProps;
114  m_dens = b.m_dens;
115  m_iState = b.m_iState;
116  EW_Offset = b.EW_Offset;
117  SW_Offset = b.SW_Offset;
118  m_verbose = b.m_verbose;
119  m_allowGasPhase = b.m_allowGasPhase;
120 
121  return *this;
122 }
123 
125 {
126  return new PDSS_Water(*this);
127 }
128 
130  const XML_Node& phaseNode, const std::string& id)
131 {
132  constructSet();
133 }
134 
136  const std::string& inputFile, const std::string& id)
137 {
138  warn_deprecated("PDSS_Water::constructPDSSFile",
139  "To be removed after Cantera 2.3.");
140  if (inputFile.size() == 0) {
141  throw CanteraError("PDSS_Water::constructPDSSFile",
142  "input file is null");
143  }
144 
145  // The phase object automatically constructs an XML object. Use this object
146  // to store information.
147  XML_Node fxml;
148  fxml.build(findInputFile(inputFile));
149  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
150  if (!fxml_phase) {
151  throw CanteraError("PDSS_Water::initThermo",
152  "ERROR: Can not find phase named " +
153  id + " in file named " + inputFile);
154  }
155  constructPDSSXML(tp, spindex, *fxml_phase, id);
156 }
157 
159 {
160  // Calculate the molecular weight. hard coded to Cantera's elements and
161  // Water.
162  m_mw = 2 * 1.00794 + 15.9994;
163 
164  // Set the baseline
165  doublereal T = 298.15;
166  m_p0 = OneAtm;
167  doublereal presLow = 1.0E-2;
168  doublereal oneBar = 1.0E5;
169  doublereal dens = 1.0E-9;
170  m_dens = m_sub.density(T, presLow, WATER_GAS, dens);
171  m_pres = presLow;
172  SW_Offset = 0.0;
173  doublereal s = entropy_mole();
174  s -= GasConstant * log(oneBar/presLow);
175  if (s != 188.835E3) {
176  SW_Offset = 188.835E3 - s;
177  }
178  s = entropy_mole();
179  s -= GasConstant * log(oneBar/presLow);
180 
181  doublereal h = enthalpy_mole();
182  if (h != -241.826E6) {
183  EW_Offset = -241.826E6 - h;
184  }
185  h = enthalpy_mole();
186 
187  // Set the initial state of the system to 298.15 K and 1 bar.
188  setTemperature(298.15);
189  m_dens = m_sub.density(298.15, OneAtm, WATER_LIQUID);
190  m_pres = OneAtm;
191 }
192 
193 doublereal PDSS_Water::enthalpy_mole() const
194 {
195  return m_sub.enthalpy() + EW_Offset;
196 }
197 
198 doublereal PDSS_Water::intEnergy_mole() const
199 {
200  return m_sub.intEnergy() + EW_Offset;
201 }
202 
203 doublereal PDSS_Water::entropy_mole() const
204 {
205  return m_sub.entropy() + SW_Offset;
206 }
207 
208 doublereal PDSS_Water::gibbs_mole() const
209 {
210  return m_sub.Gibbs() + EW_Offset - SW_Offset*m_temp;
211 }
212 
213 doublereal PDSS_Water::cp_mole() const
214 {
215  return m_sub.cp();
216 }
217 
218 doublereal PDSS_Water::cv_mole() const
219 {
220  return m_sub.cv();
221 }
222 
223 doublereal PDSS_Water::molarVolume() const
224 {
225  return m_sub.molarVolume();
226 }
227 
228 doublereal PDSS_Water::gibbs_RT_ref() const
229 {
230  doublereal T = m_temp;
231  m_sub.density(T, m_p0);
232  doublereal h = m_sub.enthalpy();
234  return (h + EW_Offset - SW_Offset*T)/(T * GasConstant);
235 }
236 
237 doublereal PDSS_Water::enthalpy_RT_ref() const
238 {
239  doublereal T = m_temp;
240  m_sub.density(T, m_p0);
241  doublereal h = m_sub.enthalpy();
243  return (h + EW_Offset)/(T * GasConstant);
244 }
245 
246 doublereal PDSS_Water::entropy_R_ref() const
247 {
248  doublereal T = m_temp;
249  m_sub.density(T, m_p0);
250  doublereal s = m_sub.entropy();
252  return (s + SW_Offset)/GasConstant;
253 }
254 
255 doublereal PDSS_Water::cp_R_ref() const
256 {
257  doublereal T = m_temp;
258  m_sub.density(T, m_p0);
259  doublereal cp = m_sub.cp();
261  return cp/GasConstant;
262 }
263 
264 doublereal PDSS_Water::molarVolume_ref() const
265 {
266  doublereal T = m_temp;
267  m_sub.density(T, m_p0);
268  doublereal mv = m_sub.molarVolume();
270  return mv;
271 }
272 
273 doublereal PDSS_Water::pressure() const
274 {
275  m_pres = m_sub.pressure();
276  return m_pres;
277 }
278 
279 void PDSS_Water::setPressure(doublereal p)
280 {
281  // In this routine we must be sure to only find the water branch of the
282  // curve and not the gas branch
283  doublereal T = m_temp;
284  doublereal dens = m_dens;
285  int waterState = WATER_LIQUID;
286  if (T > m_sub.Tcrit()) {
287  waterState = WATER_SUPERCRIT;
288  }
289 
290  doublereal dd = m_sub.density(T, p, waterState, dens);
291  if (dd <= 0.0) {
292  throw CanteraError("PDSS_Water:setPressure()",
293  "Failed to set water SS state: T = {} K and p = {} Pa", T, p);
294  }
295  m_dens = dd;
296  m_pres = p;
297 
298  // We are only putting the phase check here because of speed considerations.
299  m_iState = m_sub.phaseState(true);
300  if (!m_allowGasPhase && m_iState != WATER_SUPERCRIT && m_iState != WATER_LIQUID && m_iState != WATER_UNSTABLELIQUID) {
301  throw CanteraError("PDSS_Water::setPressure",
302  "Water State isn't liquid or crit");
303  }
304 }
305 
307 {
308  return m_sub.coeffThermExp();
309 }
310 
312 {
313  doublereal pres = pressure();
314  doublereal dens_save = m_dens;
315  doublereal tt = m_temp - 0.04;
316  doublereal dd = m_sub.density(tt, pres, m_iState, m_dens);
317  if (dd < 0.0) {
318  throw CanteraError("PDSS_Water::dthermalExpansionCoeffdT",
319  "unable to solve for the density at T = {}, P = {}", tt, pres);
320  }
321  doublereal vald = m_sub.coeffThermExp();
322  m_sub.setState_TR(m_temp, dens_save);
323  doublereal val2 = m_sub.coeffThermExp();
324  return (val2 - vald) / 0.04;
325 }
326 
328 {
330 }
331 
332 doublereal PDSS_Water::critTemperature() const
333 {
334  return m_sub.Tcrit();
335 }
336 
337 doublereal PDSS_Water::critPressure() const
338 {
339  return m_sub.Pcrit();
340 }
341 
342 doublereal PDSS_Water::critDensity() const
343 {
344  return m_sub.Rhocrit();
345 }
346 
347 void PDSS_Water::setDensity(doublereal dens)
348 {
349  m_dens = dens;
351 }
352 
353 doublereal PDSS_Water::density() const
354 {
355  return m_dens;
356 }
357 
358 void PDSS_Water::setTemperature(doublereal temp)
359 {
360  m_temp = temp;
361  m_sub.setState_TR(temp, m_dens);
362 }
363 
364 void PDSS_Water::setState_TP(doublereal temp, doublereal pres)
365 {
366  m_temp = temp;
367  setPressure(pres);
368 }
369 
370 void PDSS_Water::setState_TR(doublereal temp, doublereal dens)
371 {
372  m_temp = temp;
373  m_dens = dens;
375 }
376 
377 doublereal PDSS_Water::pref_safe(doublereal temp) const
378 {
379  if (temp < m_sub.Tcrit()) {
380  doublereal pp = m_sub.psat_est(temp);
381  if (pp > OneAtm) {
382  return pp;
383  }
384  } else {
385  return m_sub.Pcrit();
386  }
387  return OneAtm;
388 }
389 
390 doublereal PDSS_Water::satPressure(doublereal t)
391 {
392  doublereal pp = m_sub.psat(t, WATER_LIQUID);
393  m_dens = m_sub.density();
394  m_temp = t;
395  return pp;
396 }
397 
398 }
doublereal psat_est(doublereal temperature) const
This function returns an estimated value for the saturation pressure.
doublereal m_dens
State of the system - density.
Definition: PDSS_Water.h:271
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:1038
virtual doublereal critPressure() const
critical pressure
Definition: PDSS_Water.cpp:337
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
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.
std::string findInputFile(const std::string &name)
Find an input file.
Definition: global.cpp:155
virtual doublereal pressure() const
Returns the pressure (Pa)
Definition: PDSS_Water.cpp:273
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
void setDensity(doublereal dens)
Set the density of the water phase.
Definition: PDSS_Water.cpp:347
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...
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Definition: PDSS_Water.cpp:124
virtual doublereal critDensity() const
critical density
Definition: PDSS_Water.cpp:342
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:544
WaterPropsIAPWS m_sub
Pointer to the WaterPropsIAPWS object, which does the actual calculations for the real equation of st...
Definition: PDSS_Water.h:254
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:218
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
doublereal molarVolume() const
Calculate the molar volume (kmol m-3) at the last temperature and density.
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_Water.cpp:255
void constructSet()
Internal routine that initializes the underlying water model.
Definition: PDSS_Water.cpp:158
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:538
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:129
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: PDSS_Water.cpp:327
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density...
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:135
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)
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:175
WaterProps m_waterProps
Pointer to the WaterProps object.
Definition: PDSS_Water.h:264
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:306
bool m_verbose
Verbose flag - used?
Definition: PDSS_Water.h:300
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:364
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:49
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_Water.cpp:390
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_Water.cpp:246
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:203
void build(const std::string &filename)
Populate the XML tree from an input file.
Definition: xml.cpp:716
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:377
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_Water.cpp:223
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:213
virtual doublereal dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient.
Definition: PDSS_Water.cpp:311
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_Water.cpp:370
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:553
int m_iState
state of the fluid
Definition: PDSS_Water.h:283
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_Water.cpp:358
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:550
doublereal coeffThermExp() const
Returns the coefficient of thermal expansion.
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_Water.cpp:208
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_Water.cpp:198
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: PDSS_Water.h:297
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:176
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:237
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_Water.cpp:264
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:541
PDSS & operator=(const PDSS &b)
Definition: PDSS.cpp:103
doublereal Tcrit() const
Returns the critical temperature of water (Kelvin)
Contains declarations for string manipulation functions within Cantera.
virtual doublereal critTemperature() const
critical temperature
Definition: PDSS_Water.cpp:332
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:228
MultiSpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:579
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_Water.cpp:279
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:353
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
bool m_allowGasPhase
Since this phase represents a liquid phase, it&#39;s an error to return a gas-phase answer.
Definition: PDSS_Water.h:309
Namespace for the Cantera kernel.
Definition: application.cpp:29
doublereal EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition: PDSS_Water.h:290
PDSS_Water()
Bare constructor.
Definition: PDSS_Water.cpp:15
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:547
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:567
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 doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:193
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...