Cantera  3.0.0
Loading...
Searching...
No Matches
WaterPropsIAPWS.h
Go to the documentation of this file.
1/**
2 * @file WaterPropsIAPWS.h
3 * Headers for a class for calculating the equation of state of water
4 * from the IAPWS 1995 Formulation based on the steam tables thermodynamic
5 * basis (See class @link Cantera::WaterPropsIAPWS WaterPropsIAPWS@endlink).
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11#ifndef WATERPROPSIAPWS_H
12#define WATERPROPSIAPWS_H
13
14#include "WaterPropsIAPWSphi.h"
15
16namespace Cantera
17{
18//! @name Names for the phase regions
19//!
20//! These constants are defined and used in the interface to describe the
21//! location of where we are in (T,rho) space.
22//!
23//! WATER_UNSTABLELIQUID indicates that we are in the unstable region, inside the
24//! spinodal curve where dpdrho < 0.0 amongst other properties. The difference
25//! between WATER_UNSTABLELIQUID and WATER_UNSTABLEGAS is that
26//! for WATER_UNSTABLELIQUID d2pdrho2 > 0 and dpdrho < 0.0
27//! for WATER_UNSTABLEGAS d2pdrho2 < 0 and dpdrho < 0.0
28//@{
29
30#define WATER_GAS 0
31#define WATER_LIQUID 1
32#define WATER_SUPERCRIT 2
33#define WATER_UNSTABLELIQUID 3
34#define WATER_UNSTABLEGAS 4
35//@}
36
37//! Class for calculating the equation of state of water.
38/*!
39 * This is a helper class for WaterSSTP and PDSS_Water and does not constitute
40 * a complete implementation of a thermo phase by itself (see @ref thermoprops
41 * and classes @link Cantera::WaterSSTP WaterSSTP@endlink and
42 * @link Cantera::PDSS_Water PDSS_Water@endlink).
43 *
44 * The reference is W. Wagner, A. Pruss, "The IAPWS Formulation 1995 for the
45 * Thermodynamic Properties of Ordinary Water Substance for General and
46 * Scientific Use," J. Phys. Chem. Ref. Dat, 31, 387, 2002.
47 *
48 * This class provides a very complicated polynomial for the specific
49 * Helmholtz free energy of water, as a function of temperature and density.
50 *
51 * @f[
52 * \frac{M\hat{f}(\rho,T)}{R T} = \phi(\delta, \tau) =
53 * \phi^o(\delta, \tau) + \phi^r(\delta, \tau)
54 * @f]
55 *
56 * where
57 *
58 * @f[
59 * \delta = \rho / \rho_c \quad \mathrm{and} \quad \tau = T_c / T
60 * @f]
61 *
62 * The following constants are assumed
63 *
64 * @f[
65 * T_c = 647.096\mathrm{\;K}
66 * @f]
67 * @f[
68 * \rho_c = 322 \mathrm{\;kg\,m^{-3}}
69 * @f]
70 * @f[
71 * R/M = 0.46151805 \mathrm{\;kJ\,kg^{-1}\,K^{-1}}
72 * @f]
73 *
74 * The free energy is a unique single-valued function of the temperature and
75 * density over its entire range.
76 *
77 * Note, the base thermodynamic state for this class is the one used in the
78 * steam tables, such that the liquid at the triple point for water has the
79 * following properties:
80 *
81 * - u(273.16, rho) = 0.0
82 * - s(273.16, rho) = 0.0
83 * - psat(273.16) = 611.655 Pascal
84 * - rho(273.16, psat) = 999.793 kg m-3
85 *
86 * Therefore, to use this class within %Cantera, offsets to u() and s() must
87 * be used to put the water class onto the same basis as other thermodynamic
88 * quantities. For example, in the WaterSSTP class, these offsets are
89 * calculated in the following way. The thermodynamic base state for water is
90 * set to the NIST basis here by specifying constants EW_Offset and SW_Offset.
91 * These offsets are calculated on the fly so that the following properties
92 * hold:
93 *
94 * - Delta_Hfo_idealGas(298.15, 1bar) = -241.826 kJ/gmol
95 * - So_idealGas(298.15, 1bar) = 188.835 J/gmolK
96 *
97 * The offsets are calculated by actually computing the above quantities and
98 * then calculating the correction factor.
99 *
100 * This class provides an interface to the WaterPropsIAPWSphi class, which
101 * actually calculates the @f$ \phi^o(\delta, \tau) @f$ and the
102 * @f$ \phi^r(\delta, \tau) @f$ polynomials in dimensionless form.
103 *
104 * All thermodynamic results from this class are returned in dimensional form.
105 * This is because the gas constant (and molecular weight) used within this
106 * class is allowed to be potentially different than that used elsewhere in
107 * %Cantera. Therefore, everything has to be in dimensional units. Note,
108 * however, the thermodynamic basis is set to that used in the steam tables.
109 * (u = s = 0 for liquid water at the triple point).
110 *
111 * This class is not a ThermoPhase. However, it does maintain an internal
112 * state of the object that is dependent on temperature and density. The
113 * internal state is characterized by an internally stored @f$ \tau @f$ and a
114 * @f$ \delta @f$ value, and an iState value, which indicates whether the
115 * point is a liquid, a gas, or a supercritical fluid. Along with that the
116 * @f$ \tau @f$ and a @f$ \delta @f$ values are polynomials of @f$ \tau @f$ and
117 * a @f$ \delta @f$ that are kept by the WaterPropsIAPWSphi class. Therefore,
118 * whenever @f$ \tau @f$ or @f$ \delta @f$ is changed, the function setState()
119 * must be called in order for the internal state to be kept up to date.
120 *
121 * The class is pretty straightforward. However, one function deserves
122 * mention. The density() function calculates the density that is consistent
123 * with a particular value of the temperature and pressure. It may therefore
124 * be multivalued or potentially there may be no answer from this function. It
125 * therefore takes a phase guess and a density guess as optional parameters.
126 * If no guesses are supplied to density(), a gas phase guess is assumed. This
127 * may or may not be what is wanted. Therefore, density() should usually at
128 * least be supplied with a phase guess so that it may manufacture an
129 * appropriate density guess. density() manufactures the initial density
130 * guess, nondimensionalizes everything, and then calls
131 * WaterPropsIAPWSphi::dfind(), which does the iterative calculation to find
132 * the density condition that matches the desired input pressure.
133 *
134 * The phase guess defines are located in the .h file. they are
135 *
136 * - WATER_GAS
137 * - WATER_LIQUID
138 * - WATER_SUPERCRIT
139 *
140 * There are only three functions which actually change the value of the
141 * internal state of this object after it's been instantiated
142 *
143 * - setState_TD(temperature, rho)
144 * - density(temperature, pressure, phase, rhoguess)
145 * - psat(temperature, waterState);
146 *
147 * The setState_TD() is the main function that sets the temperature and rho
148 * value. The density() function serves as a setState_TP() function, in that
149 * it sets internal state to a temperature and pressure. However, note that
150 * this is potentially multivalued. Therefore, we need to supply in addition a
151 * phase guess and a rho guess to the input temperature and pressure. The
152 * psat() function sets the internal state to the saturated liquid or
153 * saturated gas state, depending on the waterState parameter.
154 *
155 * Because the underlying object WaterPropsIAPWSphi is privately held, you can
156 * be sure that the underlying state of this object doesn't change except due
157 * to the three function calls listed above.
158 *
159 * @ingroup thermoprops
160 */
162{
163public:
164 //! Base constructor
165 WaterPropsIAPWS() = default;
166
167 WaterPropsIAPWS(const WaterPropsIAPWS& right) = delete;
168 WaterPropsIAPWS& operator=(const WaterPropsIAPWS& right) = delete;
169
170 //! Set the internal state of the object wrt temperature and density
171 /*!
172 * @param temperature temperature (kelvin)
173 * @param rho density (kg m-3)
174 * @deprecated To be removed after %Cantera 3.0; renamed to setState_TD()
175 */
176 void setState_TR(double temperature, double rho);
177
178 //! Set the internal state of the object wrt temperature and density
179 /*!
180 * @param temperature temperature (kelvin)
181 * @param rho density (kg m-3)
182 * @since New in %Cantera 3.0.
183 */
184 void setState_TD(double temperature, double rho);
185
186 //! Get the Gibbs free energy (J/kg) at the current temperature and density
187 double gibbs_mass() const;
188
189 //! Get the enthalpy (J/kg) at the current temperature and density
190 double enthalpy_mass() const;
191
192 //! Get the internal energy (J/kg) at the current temperature and density
193 double intEnergy_mass() const;
194
195 //! Get the entropy (J/kg/K) at the current temperature and density
196 double entropy_mass() const;
197
198 //! Get the constant volume heat capacity (J/kg/K) at the current temperature and
199 //! density
200 double cv_mass() const;
201
202 //! Get the constant pressure heat capacity (J/kg/K) at the current temperature and
203 //! density
204 double cp_mass() const;
205
206 //! Calculate the Helmholtz free energy in mks units of J kmol-1 K-1,
207 //! using the last temperature and density
208 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
209 //! values only.
210 double helmholtzFE() const;
211
212 //! Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
213 //! using the last temperature and density
214 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
215 //! values only.
216 double Gibbs() const;
217
218 //! Calculate the enthalpy in mks units of J kmol-1
219 //! using the last temperature and density
220 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
221 //! values only.
222 double enthalpy() const;
223
224 //! Calculate the internal energy in mks units of J kmol-1
225 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
226 //! values only.
227 double intEnergy() const;
228
229 //! Calculate the entropy in mks units of J kmol-1 K-1
230 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
231 //! values only.
232 double entropy() const;
233
234 //! Calculate the constant volume heat capacity in mks units of J kmol-1 K-1
235 //! at the last temperature and density
236 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
237 //! values only.
238 double cv() const;
239
240 //! Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1
241 //! at the last temperature and density
242 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
243 //! values only.
244 double cp() const;
245
246 //! Calculate the molar volume (kmol m-3) at the last temperature and
247 //! density
248 //! @deprecated To be removed after %Cantera 3.0. This class provides mass-based
249 //! values only.
250 double molarVolume() const;
251
252 //! Calculates the pressure (Pascals), given the current value of the
253 //! temperature and density.
254 /*!
255 * The density is an independent variable in the underlying equation of state
256 *
257 * @returns the pressure (Pascal)
258 */
259 double pressure() const;
260
261 //! Calculates the density given the temperature and the pressure,
262 //! and a guess at the density. Sets the internal state.
263 /*!
264 * Note, below T_c, this is a multivalued function.
265 *
266 * The density() function calculates the density that is consistent with
267 * a particular value of the temperature and pressure. It may therefore be
268 * multivalued or potentially there may be no answer from this function.
269 * It therefore takes a phase guess and a density guess as optional
270 * parameters. If no guesses are supplied to density(), a gas phase guess
271 * is assumed. This may or may not be what is wanted. Therefore, density()
272 * should usually at least be supplied with a phase guess so that it may
273 * manufacture an appropriate density guess. density() manufactures the
274 * initial density guess, nondimensionalizes everything, and then calls
275 * WaterPropsIAPWSphi::dfind(), which does the iterative calculation to
276 * find the density condition that matches the desired input pressure.
277 *
278 * @param temperature Kelvin
279 * @param pressure Pressure in Pascals (Newton/m**2)
280 * @param phase guessed phase of water; -1: no guessed phase
281 * @param rhoguess guessed density of the water; -1.0 no guessed density
282 * @returns the density. If an error is encountered in the calculation the
283 * value of -1.0 is returned.
284 */
285 double density(double temperature, double pressure,
286 int phase = -1, double rhoguess = -1.0);
287
288 //! Calculates the density given the temperature and the pressure,
289 //! and a guess at the density, while not changing the internal state
290 /*!
291 * Note, below T_c, this is a multivalued function.
292 *
293 * The density() function calculates the density that is consistent with a
294 * particular value of the temperature and pressure. It may therefore be
295 * multivalued or potentially there may be no answer from this function.
296 * It therefore takes a phase guess and a density guess as optional
297 * parameters. If no guesses are supplied to density(), a gas phase guess
298 * is assumed. This may or may not be what is wanted. Therefore, density()
299 * should usually at least be supplied with a phase guess so that it may
300 * manufacture an appropriate density guess. density() manufactures the
301 * initial density guess, nondimensionalizes everything, and then calls
302 * WaterPropsIAPWSphi::dfind(), which does the iterative calculation to
303 * find the density condition that matches the desired input pressure.
304 *
305 * @param pressure Pressure in Pascals (Newton/m**2)
306 * @param phase guessed phase of water; -1: no guessed phase
307 * @param rhoguess guessed density of the water; -1.0: no guessed density
308 * @returns the density. If an error is encountered in the calculation the
309 * value of -1.0 is returned.
310 */
311 double density_const(double pressure, int phase = -1, double rhoguess = -1.0) const;
312
313 //! Returns the density (kg m-3)
314 /*!
315 * The density is an independent variable in the underlying equation of state
316 *
317 * @returns the density (kg m-3)
318 */
319 double density() const;
320
321 //! Returns the temperature (Kelvin)
322 /*!
323 * @return s the internally stored temperature
324 */
325 double temperature() const;
326
327 //! Returns the coefficient of thermal expansion.
328 /*!
329 * alpha = d (ln V) / dT at constant P.
330 *
331 * @returns the coefficient of thermal expansion
332 */
333 double coeffThermExp() const;
334
335 //! Returns the isochoric pressure derivative wrt temperature
336 /*!
337 * beta = M / (rho * Rgas) (d (pressure) / dT) at constant rho
338 *
339 * Note for ideal gases this is equal to one.
340 *
341 * beta = delta (phi0_d() + phiR_d()) - tau delta (phi0_dt() + phiR_dt())
342 */
343 double coeffPresExp() const;
344
345 //! Returns the coefficient of isothermal compressibility for the state of
346 //! the object
347 /*!
348 * kappa = - d (ln V) / dP at constant T.
349 *
350 * units - 1/Pascal
351 *
352 * @returns the isothermal compressibility
353 */
354 double isothermalCompressibility() const;
355
356 //! Returns the value of dp / drho at constant T for the state of the object
357 /*!
358 * units - Joules / kg
359 *
360 * @returns dpdrho
361 */
362 double dpdrho() const;
363
364 //! This function returns an estimated value for the saturation pressure.
365 /*!
366 * It does this via a polynomial fit of the vapor pressure curve.
367 * units = (Pascals)
368 *
369 * @param temperature Input temperature (Kelvin)
370 *
371 * @returns the estimated saturation pressure
372 */
373 double psat_est(double temperature) const;
374
375 //! This function returns the saturation pressure given the temperature as
376 //! an input parameter, and sets the internal state to the saturated
377 //! conditions.
378 /*!
379 * Note this function will return the saturation pressure, given the
380 * temperature. It will then set the state of the system to the saturation
381 * condition. The input parameter waterState is used to either specify the
382 * liquid state or the gas state at the desired temperature and saturated
383 * pressure.
384 *
385 * If the input temperature, T, is above T_c, this routine will set the
386 * internal state to T and the pressure to P_c. Then, return P_c.
387 *
388 * @param temperature input temperature (kelvin)
389 * @param waterState integer specifying the water state
390 * @returns the saturation pressure. units = Pascal
391 */
392 double psat(double temperature, int waterState = WATER_LIQUID);
393
394 //! Return the value of the density at the water spinodal point (on the
395 //! liquid side) for the current temperature.
396 /*!
397 * @returns the density with units of kg m-3
398 */
399 double densSpinodalWater() const;
400
401 //! Return the value of the density at the water spinodal point (on the gas
402 //! side) for the current temperature.
403 /*!
404 * @returns the density with units of kg m-3
405 */
406 double densSpinodalSteam() const;
407
408 //! Returns the Phase State flag for the current state of the object
409 /*!
410 * @param checkState If true, this function does a complete check to see
411 * where in parameters space we are
412 *
413 * There are three values:
414 * - WATER_GAS below the critical temperature but below the critical density
415 * - WATER_LIQUID below the critical temperature but above the critical density
416 * - WATER_SUPERCRIT above the critical temperature
417 */
418 int phaseState(bool checkState = false) const;
419
420 //! Returns the critical temperature of water (Kelvin)
421 /*!
422 * This is hard coded to the value 647.096 Kelvin
423 */
424 double Tcrit() const {
425 return 647.096;
426 }
427
428 //! Returns the critical pressure of water (22.064E6 Pa)
429 /*!
430 * This is hard coded to the value of 22.064E6 pascals
431 */
432 double Pcrit() const {
433 return 22.064E6;
434 }
435
436 //! Return the critical density of water (kg m-3)
437 /*!
438 * This is equal to 322 kg m-3.
439 */
440 double Rhocrit() const {
441 return 322.;
442 }
443
444private:
445 //! Calculate the dimensionless temp and rho and store internally.
446 /*!
447 * @param temperature input temperature (kelvin)
448 * @param rho density in kg m-3
449 */
450 void calcDim(double temperature, double rho);
451
452 //! Utility routine in the calculation of the saturation pressure
453 /*!
454 * Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
455 *
456 * @param temperature temperature (kelvin)
457 * @param pressure pressure (Pascal)
458 * @param densLiq Output density of liquid
459 * @param densGas output Density of gas
460 * @param delGRT output delGRT
461 */
462 void corr(double temperature, double pressure, double& densLiq,
463 double& densGas, double& delGRT);
464
465 //! Utility routine in the calculation of the saturation pressure
466 /*!
467 * @param temperature temperature (kelvin)
468 * @param pressure pressure (Pascal)
469 * @param densLiq Output density of liquid
470 * @param densGas output Density of gas
471 * @param pcorr output corrected pressure
472 */
473 void corr1(double temperature, double pressure, double& densLiq,
474 double& densGas, double& pcorr);
475
476 //! pointer to the underlying object that does the calculations.
478
479 //! Dimensionless temperature, tau = T_C / T
480 double tau = -1.0;
481
482 //! Dimensionless density, delta = rho / rho_c
483 mutable double delta = -1.0;
484
485 //! Current state of the system
486 mutable int iState = -30000;
487};
488
489}
490#endif
Header for Lowest level of the classes which support a real water model (see class WaterPropsIAPWS an...
Class for calculating the equation of state of water.
double cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
double coeffThermExp() const
Returns the coefficient of thermal expansion.
void setState_TR(double temperature, double rho)
Set the internal state of the object wrt temperature and density.
double densSpinodalSteam() const
Return the value of the density at the water spinodal point (on the gas side) for the current tempera...
double density() const
Returns the density (kg m-3)
void corr(double temperature, double pressure, double &densLiq, double &densGas, double &delGRT)
Utility routine in the calculation of the saturation pressure.
double enthalpy() const
Calculate the enthalpy in mks units of J kmol-1 using the last temperature and density.
double pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density.
void corr1(double temperature, double pressure, double &densLiq, double &densGas, double &pcorr)
Utility routine in the calculation of the saturation pressure.
double helmholtzFE() const
Calculate the Helmholtz free energy in mks units of J kmol-1 K-1, using the last temperature and dens...
double gibbs_mass() const
Get the Gibbs free energy (J/kg) at the current temperature and density.
double isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
double psat(double temperature, int waterState=WATER_LIQUID)
This function returns the saturation pressure given the temperature as an input parameter,...
double entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
double temperature() const
Returns the temperature (Kelvin)
double Pcrit() const
Returns the critical pressure of water (22.064E6 Pa)
double cv_mass() const
Get the constant volume heat capacity (J/kg/K) at the current temperature and density.
double entropy_mass() const
Get the entropy (J/kg/K) at the current temperature and density.
double Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
double Rhocrit() const
Return the critical density of water (kg m-3)
double densSpinodalWater() const
Return the value of the density at the water spinodal point (on the liquid side) for the current temp...
double delta
Dimensionless density, delta = rho / rho_c.
double Tcrit() const
Returns the critical temperature of water (Kelvin)
double cp_mass() const
Get the constant pressure heat capacity (J/kg/K) at the current temperature and density.
double intEnergy_mass() const
Get the internal energy (J/kg) at the current temperature and density.
double coeffPresExp() const
Returns the isochoric pressure derivative wrt temperature.
int iState
Current state of the system.
double cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
void setState_TD(double temperature, double rho)
Set the internal state of the object wrt temperature and density.
double molarVolume() const
Calculate the molar volume (kmol m-3) at the last temperature and density.
double tau
Dimensionless temperature, tau = T_C / T.
WaterPropsIAPWSphi m_phi
pointer to the underlying object that does the calculations.
double intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
double density_const(double pressure, int phase=-1, double rhoguess=-1.0) const
Calculates the density given the temperature and the pressure, and a guess at the density,...
void calcDim(double temperature, double rho)
Calculate the dimensionless temp and rho and store internally.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
WaterPropsIAPWS()=default
Base constructor.
double dpdrho() const
Returns the value of dp / drho at constant T for the state of the object.
double psat_est(double temperature) const
This function returns an estimated value for the saturation pressure.
double enthalpy_mass() const
Get the enthalpy (J/kg) at the current temperature and density.
Low level class for the real description of water.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564