1 /**
2  * @file WaterPropsIAPWSphi.h
3  * Header for Lowest level of the classes which support a real water model
4  * (see class \link Cantera::WaterPropsIAPWS WaterPropsIAPWS\endlink and class
5  * \link Cantera::WaterPropsIAPWSphi WaterPropsIAPWSphi\endlink).
6  *
7  * This class calculates dimensionless quantities.
8  */
9 
10 // This file is part of Cantera. See License.txt in the top-level directory or
11 // at https://cantera.org/license.txt for license and copyright information.
12 
13 #ifndef WATERPROPSIAPWSPHI_H
14 #define WATERPROPSIAPWSPHI_H
15 
16 #include "cantera/base/config.h"
17 
18 namespace Cantera
19 {
20 
21 //! Low level class for the real description of water.
22 /*!
23  * This is a helper class for WaterSSTP and PDSS_Water and does not constitute
24  * a complete implementation of a thermo phase by itself (see \ref thermoprops
25  * and classes \link Cantera::WaterSSTP WaterSSTP\endlink and
26  * \link Cantera::PDSS_Water PDSS_Water\endlink).
27  *
28  * The reference is W. Wagner, A. Pruss, "The IAPWS Formulation 1995 for the
29  * Thermodynamic Properties of Ordinary Water Substance for General and
30  * Scientific Use," J. Phys. Chem. Ref. Dat, 31, 387, 2002.
31  *
32  * Units Note: This class works with reduced units exclusively.
33  */
34 class WaterPropsIAPWSphi
35 {
36 public:
37     //! Base constructor
38     WaterPropsIAPWSphi();
39 
40     //! Calculate the Phi function, which is the base function
41     /*!
42      * The phi function is basically the Helmholtz free energy Eqn. (6.4) All
43      * internal polynomials are recalculated.
44      *
45      * @param tau     Dimensionless temperature = T_c/T
46      * @param delta   Dimensionless density =  delta = rho / Rho_c
47      */
48     doublereal phi(doublereal tau, doublereal delta);
49 
50     //! Calculate derivative of phi wrt delta
51     /*!
52      * @param tau     Dimensionless temperature = T_c/T
53      * @param delta   Dimensionless density =  delta = rho / Rho_c
54      */
55     doublereal phi_d(doublereal tau, doublereal delta);
56 
57     //! 2nd derivative of phi wrt delta
58     /*!
59      * @param tau     Dimensionless temperature = T_c/T
60      * @param delta   Dimensionless density =  delta = rho / Rho_c
61      */
62     doublereal phi_dd(doublereal tau, doublereal delta);
63 
64     //! First derivative of phi wrt tau
65     /*!
66      * @param tau     Dimensionless temperature = T_c/T
67      * @param delta   Dimensionless density =  delta = rho / Rho_c
68      */
69     doublereal phi_t(doublereal tau, doublereal delta);
70 
71     //! Second derivative of phi wrt tau
72     /*!
73      * @param tau     Dimensionless temperature = T_c/T
74      * @param delta   Dimensionless density =  delta = rho / Rho_c
75      */
76     doublereal phi_tt(doublereal tau, doublereal delta);
77 
78     //! Calculate the dimensionless pressure at tau and delta;
79     /*!
80      *       pM/(rhoRT) = delta * phi_d() = 1.0 + delta phiR_d()
81      *
82      * @param tau     Dimensionless temperature = T_c/T
83      * @param delta   Dimensionless density =  delta = rho / Rho_c
84      *
85      * note: this is done so much, we have a separate routine.
86      */
87     doublereal pressureM_rhoRT(doublereal tau, doublereal delta);
88 
89     //! Dimensionless derivative of p wrt rho at constant T
90     /*!
91      *  dp/drho * 1/RT = (2. delta phi_d() + delta**2 phi_dd())
92      *                   (1.0 + 2. delta phiR_d() + delta**2 phiR_dd())
93      *
94      * @param tau     Dimensionless temperature = T_c/T
95      * @param delta   Dimensionless density =  delta = rho / Rho_c
96      */
97     doublereal dimdpdrho(doublereal tau, doublereal delta);
98 
99     //! Dimensionless derivative of p wrt T at constant rho
100     /*!
101      *  dp/dT * M/(Rho R) = (1.0 + delta phiR_d()
102      *                   -  tau delta (phiR_dt())
103      *
104      * @param tau     Dimensionless temperature = T_c/T
105      * @param delta   Dimensionless density =  delta = rho / Rho_c
106      */
107     doublereal dimdpdT(doublereal tau, doublereal delta);
108 
109     /**
110      * This function computes the reduced density, given the reduced pressure
111      * and the reduced temperature, tau. It takes an initial guess, deltaGuess.
112      * DeltaGuess is important as this is a multivalued function below the
113      * critical point.
114      *
115      * @param p_red       Value of the dimensionless pressure
116      * @param tau         Dimensionless temperature = T_c/T
117      * @param deltaGuess  Initial guess for the dimensionless density
118      *
119      * @returns the dimensionless density.
120      */
121     doublereal dfind(doublereal p_red, doublereal tau, doublereal deltaGuess);
122 
123     //! Calculate the dimensionless Gibbs free energy
124     doublereal gibbs_RT() const;
125 
126     //! Calculate the dimensionless enthalpy, h/RT
127     doublereal enthalpy_RT() const;
128 
129     //! Calculate the dimensionless entropy, s/R
130     doublereal entropy_R() const;
131 
132     //! Calculate the dimensionless internal energy, u/RT
133     doublereal intEnergy_RT() const;
134 
135     //! Calculate the dimensionless constant volume heat capacity, Cv/R
136     doublereal cv_R() const;
137 
138     //! Calculate the dimensionless constant pressure heat capacity, Cv/R
139     doublereal cp_R() const;
140 
141     //! Calculates internal polynomials in tau and delta.
142     /*!
143      * This routine is used to store the internal state of tau and delta
144      * for later use by the other routines in the class.
145      *
146      * @param tau     Dimensionless temperature = T_c/T
147      * @param delta   Dimensionless density =  delta = rho / Rho_c
148      */
149     void tdpolycalc(doublereal tau, doublereal delta);
150 
151     /*!
152      * Calculate Equation 6.6 for phiR, the residual part of the
153      * dimensionless Helmholtz free energy.
154      */
155     doublereal phiR() const;
156 
157 protected:
158     //! Calculate Equation 6.5 for phi0, the ideal gas part of the
159     //! dimensionless Helmholtz free energy.
160     doublereal phi0() const;
161     //! Calculate d_phiR_d(delta), the first derivative of phiR wrt delta
162     doublereal phiR_d() const;
163     //! Calculate d_phi0_d(delta), the first derivative of phi0 wrt delta
164     doublereal phi0_d() const;
165     //! Calculate d2_phiR_dd(delta), the second derivative of phiR wrt delta
166     doublereal phiR_dd() const;
167     //! Calculate d2_phi0_dd(delta), the second derivative of phi0 wrt delta
168     doublereal phi0_dd() const;
169     //! Calculate d_phi0/d(tau)
170     doublereal phi0_t() const;
171     //! Calculate Equation 6.6 for dphiRdtau, the derivative residual part of
172     //! the dimensionless Helmholtz free energy wrt temperature
173     doublereal phiR_t() const;
174     //! Calculate Equation 6.6 for dphiRdtau, the second derivative residual
175     //! part of the dimensionless Helmholtz free energy wrt temperature
176     doublereal phiR_tt() const;
177     //! Calculate d2_phi0/dtau2
178     doublereal phi0_tt() const;
179     //! Calculate the mixed derivative d2_phiR/(dtau ddelta)
180     doublereal phiR_dt() const;
181     //! Calculate the mixed derivative d2_phi0/(dtau ddelta)
182     doublereal phi0_dt() const;
183 
184     //! Value of internally calculated polynomials of powers of TAU
185     doublereal TAUp[52];
186 
187     //! Value of internally calculated polynomials of powers of delta
188     doublereal DELTAp[16];
189 
190     //! Last tau that was used to calculate polynomials
191     doublereal TAUsave;
192 
193     //! sqrt of TAU
194     doublereal TAUsqrt;
195 
196     //! Last delta that was used to calculate polynomials
197     doublereal DELTAsave;
198 };
199 
200 } // namespace Cantera
201 #endif
202