Cantera  2.0
PDSS_Water.h
Go to the documentation of this file.
1 /**
2  * @file PDSS_Water.h
3  * Implementation of a pressure dependent standard state
4  * virtual function for a Pure Water Phase
5  * (see \ref pdssthermo and class \link Cantera::PDSS_Water PDSS_Water\endlink).
6  */
7 /*
8  * Copyright (2006) Sandia Corporation. Under the terms of
9  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
10  * U.S. Government retains certain rights in this software.
11  */
12 #ifndef CT_PDSS_WATER_H
13 #define CT_PDSS_WATER_H
14 
15 #include "cantera/base/ct_defs.h"
16 #include "PDSS.h"
17 #include "VPStandardStateTP.h"
18 
19 
20 
21 
22 namespace Cantera
23 {
24 class WaterPropsIAPWS;
25 class WaterProps;
26 
27 //! Class for the liquid water pressure dependent
28 //! standard state
29 /*!
30  *
31  * Notes:
32  * Base state for thermodynamic properties:
33  *
34  * The thermodynamic base state for water is set to the NIST basis here
35  * by specifying constants EW_Offset and SW_Offset. These offsets are
36  * specified so that the following properties hold:
37  *
38  * Delta_Hfo_gas(298.15) = -241.826 kJ/gmol
39  * So_gas(298.15, 1bar) = 188.835 J/gmolK
40  *
41  * (http://webbook.nist.gov)
42  *
43  * The "o" here refers to a hypothetical ideal gas state. The way
44  * we achieve this in practice is to evaluate at a very low pressure
45  * and then use the theoretical ideal gas results to scale up to
46  * higher pressures:
47  *
48  * Ho(1bar) = H(P0)
49  *
50  * So(1bar) = S(P0) + RT ln(1bar/P0)
51  *
52  * The offsets used in the steam tables are different than NIST's.
53  * They assume u_liq(TP) = 0.0, s_liq(TP) = 0.0, where TP is the
54  * triple point conditions.
55  *
56  * @ingroup pdssthermo
57  */
58 class PDSS_Water : public PDSS
59 {
60 
61 public:
62 
63  /**
64  * @name Constructors
65  * @{
66  */
67 
68  //! Bare constructor
69  /*!
70  * eliminate?
71  */
72  PDSS_Water();
73 
74  //! Constructor that initializes the object by examining the XML entries
75  //! from the ThermoPhase object
76  /*!
77  * This function calls the constructPDSS member function.
78  *
79  * @param tp Pointer to the ThermoPhase object pertaining to the phase
80  * @param spindex Species index of the species in the phase
81  */
82  PDSS_Water(VPStandardStateTP* tp, int spindex);
83 
84  //! Copy Constructor
85  /*!
86  * @param b object to be copied
87  */
88  PDSS_Water(const PDSS_Water& b);
89 
90  //! Assignment operator
91  /*!
92  * @param b Object to be copied
93  */
94  PDSS_Water& operator=(const PDSS_Water& b);
95 
96  //! Constructor that initializes the object by examining the input file
97  //! of the variable pressure ThermoPhase object
98  /*!
99  * This function calls the constructPDSSFile member function.
100  *
101  * @param tp Pointer to the variable pressure ThermoPhase object pertaining to the phase
102  * @param spindex Species index of the species in the phase
103  * @param inputFile String name of the input file
104  * @param id String name of the phase in the input file. The default
105  * is the empty string, in which case the first phase in the
106  * file is used.
107  */
108  PDSS_Water(VPStandardStateTP* tp, int spindex,
109  std::string inputFile, std::string id = "");
110 
111  //! Constructor that initializes the object by examining the input file
112  //! of the variable pressure ThermoPhase object
113  /*!
114  * This function calls the constructPDSSXML member function.
115  *
116  * @param tp Pointer to the ThermoPhase object pertaining to the phase
117  * @param spindex Species index of the species in the phase
118  * @param speciesNode Reference to the species XML tree.
119  * @param phaseRef Reference to the XML tree containing the phase information.
120  * @param spInstalled Is the species already installed.
121  */
122  PDSS_Water(VPStandardStateTP* tp, int spindex, const XML_Node& speciesNode,
123  const XML_Node& phaseRef, bool spInstalled);
124 
125  //! Destructor
126  virtual ~PDSS_Water();
127 
128  //! Duplication routine for objects which inherit from %PDSS
129  /*!
130  * This virtual routine can be used to duplicate %PDSS objects
131  * inherited from %PDSS even if the application only has
132  * a pointer to %PDSS to work with.
133  *
134  * @return returns a pointer to the base %PDSS object type
135  */
136  virtual PDSS* duplMyselfAsPDSS() const;
137 
138  /**
139  * @}
140  * @name Utilities
141  * @{
142  */
143 
144  /**
145  * @}
146  * @name Molar Thermodynamic Properties of the Species Standard State
147  * in the Solution
148  * @{
149  */
150 
151  //! Return the molar enthalpy in units of J kmol-1
152  /*!
153  * Returns the species standard state enthalpy in J kmol-1 at the
154  * current temperature and pressure.
155  *
156  * @return returns the species standard state enthalpy in J kmol-1
157  */
158  virtual doublereal enthalpy_mole() const;
159 
160  //! Return the molar internal Energy in units of J kmol-1
161  /*!
162  * Returns the species standard state internal Energy in J kmol-1 at the
163  * current temperature and pressure.
164  *
165  * @return returns the species standard state internal Energy in J kmol-1
166  */
167  virtual doublereal intEnergy_mole() const;
168 
169  //! Return the molar entropy in units of J kmol-1 K-1
170  /*!
171  * Returns the species standard state entropy in J kmol-1 K-1 at the
172  * current temperature and pressure.
173  *
174  * @return returns the species standard state entropy in J kmol-1 K-1
175  */
176  virtual doublereal entropy_mole() const;
177 
178  //! Return the molar gibbs free energy in units of J kmol-1
179  /*!
180  * Returns the species standard state gibbs free energy in J kmol-1 at the
181  * current temperature and pressure.
182  *
183  * @return returns the species standard state gibbs free energy in J kmol-1
184  */
185  virtual doublereal gibbs_mole() const;
186 
187  //! Return the molar const pressure heat capacity in units of J kmol-1 K-1
188  /*!
189  * Returns the species standard state Cp in J kmol-1 K-1 at the
190  * current temperature and pressure.
191  *
192  * @return returns the species standard state Cp in J kmol-1 K-1
193  */
194  virtual doublereal cp_mole() const;
195 
196  //! Return the molar const volume heat capacity in units of J kmol-1 K-1
197  /*!
198  * Returns the species standard state Cv in J kmol-1 K-1 at the
199  * current temperature and pressure.
200  *
201  * @return returns the species standard state Cv in J kmol-1 K-1
202  */
203  virtual doublereal cv_mole() const;
204 
205  //! Return the molar volume at standard state
206  /*!
207  * Returns the species standard state molar volume at the
208  * current temperature and pressure
209  *
210  * @return returns the standard state molar volume divided by R
211  * units are m**3 kmol-1.
212  */
213  virtual doublereal molarVolume() const;
214 
215  //! Return the standard state density at standard state
216  /*!
217  * Returns the species standard state density at the
218  * current temperature and pressure
219  *
220  * @return returns the standard state density
221  * units are kg m-3
222  */
223  virtual doublereal density() const;
224 
225  /**
226  * @}
227  * @name Properties of the Reference State of the Species
228  * in the Solution
229  * @{
230  */
231 
232  //! Returns a reference pressure value that can be safely calculated by the
233  //! underlying real equation of state for water
234  /*!
235  * Note, this function is needed because trying to calculate a one atm
236  * value around the critical point will cause a crash
237  *
238  * @param temp Temperature (Kelvin)
239  */
240  doublereal pref_safe(doublereal temp) const;
241 
242 
243  //! Return the molar gibbs free energy divided by RT at reference pressure
244  /*!
245  * Returns the species reference state gibbs free energy divided by RT at the
246  * current temperature.
247  *
248  * @return returns the reference state gibbs free energy divided by RT
249  */
250  virtual doublereal gibbs_RT_ref() const;
251 
252  //! Return the molar enthalpy divided by RT at reference pressure
253  /*!
254  * Returns the species reference state enthalpy divided by RT at the
255  * current temperature.
256  *
257  * @return returns the reference state enthalpy divided by RT
258  */
259  virtual doublereal enthalpy_RT_ref() const;
260 
261  //! Return the molar entropy divided by R at reference pressure
262  /*!
263  * Returns the species reference state entropy divided by R at the
264  * current temperature.
265  *
266  * @return returns the reference state entropy divided by R
267  */
268  virtual doublereal entropy_R_ref() const;
269 
270  //! Return the molar heat capacity divided by R at reference pressure
271  /*!
272  * Returns the species reference state heat capacity divided by R at the
273  * current temperature.
274  *
275  * @return returns the reference state heat capacity divided by R
276  */
277  virtual doublereal cp_R_ref() const;
278 
279  //! Return the molar volume at reference pressure
280  /*!
281  * Returns the species reference state molar volume at the
282  * current temperature.
283  *
284  * @return returns the reference state molar volume divided by R
285  * units are m**3 kmol-1.
286  */
287  virtual doublereal molarVolume_ref() const;
288  \
289 
290  /**
291  * @}
292  * @name Mechanical Equation of State Properties
293  * @{
294  */
295 
296 
297  //! Report the current pressure used in the object
298  /*!
299  * @return Returns the pressure (Pascal)
300  */
301  virtual doublereal pressure() const;
302 
303  //! Set the pressure internally
304  /*!
305  * @param pres Value of the pressure (Pascals)
306  */
307  virtual void setPressure(doublereal pres);
308 
309  //! Set the internal temperature
310  /*!
311  * @param temp Temperature (Kelvin)
312  */
313  virtual void setTemperature(doublereal temp);
314 
315  //! Set the temperature and pressure in the object
316  /*!
317  * @param temp Temperature (Kelvin)
318  * @param pres Pressure (Pascal)
319  */
320  virtual void setState_TP(doublereal temp, doublereal pres);
321 
322 
323  //! Set the temperature and density in the object
324  /*!
325  * @param temp Temperature (Kelvin)
326  * @param rho Density (kg/m3)
327  */
328  virtual void setState_TR(doublereal temp, doublereal rho);
329 
330  //! Set the density of the water phase
331  /*!
332  * This is a non-virtual function because it specific
333  * to this object.
334  *
335  * @param dens Density of the water (kg/m3)
336  */
337  void setDensity(doublereal dens);
338 
339 
340  //! Return the volumetric thermal expansion coefficient. Units: 1/K.
341  /*!
342  * The thermal expansion coefficient is defined as
343  * \f[
344  * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P
345  * \f]
346  */
347  virtual doublereal thermalExpansionCoeff() const;
348 
349  //! Return the derivative of the volumetric thermal expansion coefficient. Units: 1/K2.
350  /*!
351  * The thermal expansion coefficient is defined as
352  * \f[
353  * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P
354  * \f]
355  */
356  virtual doublereal dthermalExpansionCoeffdT() const;
357 
358  //! Returns the isothermal compressibility. Units: 1/Pa.
359  /*!
360  * The isothermal compressibility is defined as
361  * \f[
362  * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T
363  * \f]
364  * or
365  * \f[
366  * \kappa_T = \frac{1}{\rho}\left(\frac{\partial \rho}{\partial P}\right)_T
367  * \f]
368  */
369  virtual doublereal isothermalCompressibility() const;
370 
371  /**
372  * @}
373  * @name Miscellaneous properties of the standard state
374  * @{
375  */
376 
377  //! critical temperature
378  virtual doublereal critTemperature() const;
379 
380  //! critical pressure
381  virtual doublereal critPressure() const;
382 
383  //! critical density
384  virtual doublereal critDensity() const;
385 
386  //! Return the saturation pressure at a given temperature
387  /*!
388  * @param t Temperature (Kelvin)
389  */
390  virtual doublereal satPressure(doublereal t);
391 
392  //! Get a pointer to a changeable WaterPropsIAPWS object
394  return m_sub;
395  }
396 
397  //! Get a pointer to a changeable WaterPropsIAPWS object
399  return m_waterProps;
400  }
401 
402  /**
403  * @}
404  * @name Initialization of the Object
405  * @{
406  */
407 
408  //! Internal routine that initializes the underlying water model
409  /*!
410  * This routine is not virtual
411  */
412  void constructSet();
413 
414  //! Initialization of a PDSS object using an
415  //! input XML file.
416  /*!
417  * This routine is a precursor to constructPDSSXML(XML_Node*)
418  * routine, which does most of the work.
419  *
420  * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object
421  * This object must have already been malloced.
422  *
423  * @param spindex Species index within the phase
424  *
425  * @param inputFile XML file containing the description of the
426  * phase
427  *
428  * @param id Optional parameter identifying the name of the
429  * phase. If none is given, the first XML
430  * phase element will be used.
431  */
432  void constructPDSSFile(VPStandardStateTP* vptp_ptr, int spindex,
433  std::string inputFile, std::string id);
434 
435  //!Initialization of a PDSS object using an xml tree
436  /*!
437  * This routine is a driver for the initialization of the
438  * object.
439  *
440  * basic logic:
441  * initThermo() (cascade)
442  * getStuff from species Part of XML file
443  * initThermoXML(phaseNode) (cascade)
444  *
445  * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object
446  * This object must have already been malloced.
447  *
448  * @param spindex Species index within the phase
449  *
450  * @param phaseNode Reference to the phase Information for the phase
451  * that owns this species.
452  *
453  * @param id Optional parameter identifying the name of the
454  * phase. If none is given, the first XML
455  * phase element will be used.
456  */
457  void constructPDSSXML(VPStandardStateTP* vptp_ptr, int spindex,
458  const XML_Node& phaseNode, std::string id);
459 
460  //! Initialization routine for all of the shallow pointers
461  /*!
462  * This is a cascading call, where each level should call the
463  * the parent level.
464  *
465  * The initThermo() routines get called before the initThermoXML() routines
466  * from the constructPDSSXML() routine.
467  *
468  *
469  * Calls initPtrs();
470  */
471  virtual void initThermo();
472 
473  //! Initialization routine for the PDSS object based on the phaseNode
474  /*!
475  * This is a cascading call, where each level should call the
476  * the parent level.
477  *
478  * @param phaseNode Reference to the phase Information for the phase
479  * that owns this species.
480  *
481  * @param id Optional parameter identifying the name of the
482  * phase. If none is given, the first XML
483  * phase element will be used.
484  */
485  virtual void initThermoXML(const XML_Node& phaseNode, std::string& id);
486 
487  //@}
488 
489 protected:
490 
491 
492 private:
493 
494  //! Pointer to the WaterPropsIAPWS object, which does the actual calculations
495  //! for the real equation of state
496  /*!
497  * This object owns m_sub
498  */
500 
501  //! Pointer to the WaterProps object
502  /*!
503  * This class is used to house several approximation
504  * routines for properties of water.
505  *
506  * This object owns m_waterProps, and the WaterPropsIAPWS object used by
507  * WaterProps is m_sub, which is defined above.
508  */
510 
511  //! State of the system - density
512  /*!
513  * Density is the independent variable here, but it's hidden behind the
514  * object's interface.
515  */
516  doublereal m_dens;
517 
518  //! state of the fluid
519  /*!
520  * 0 WATER_GAS 0
521  * 1 WATER_LIQUID 1
522  * 2 WATER_SUPERCRIT 2
523  * 3 WATER_UNSTABLELIQUID 3
524  * 4 WATER_UNSTABLEGAS
525  */
526  int m_iState;
527 
528  /**
529  * Offset constants used to obtain consistency with the NIST database.
530  * This is added to all internal energy and enthalpy results.
531  * units = J kmol-1.
532  */
533  doublereal EW_Offset;
534 
535  /**
536  * Offset constant used to obtain consistency with NIST convention.
537  * This is added to all internal entropy results.
538  * units = J kmol-1 K-1.
539  */
540  doublereal SW_Offset;
541 
542  //! Verbose flag - used?
543  bool m_verbose;
544 
545 public:
546  /**
547  * Since this phase represents a liquid phase, it's an error to
548  * return a gas-phase answer. However, if the below is true, then
549  * a gas-phase answer is allowed. This is used to check the thermodynamic
550  * consistency with ideal-gas thermo functions for example.
551  */
553 };
554 
555 }
556 
557 #endif