Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
7
8#include "cantera/base/ctml.h"
13
14namespace Cantera
15{
17 m_waterProps(&m_sub),
18 m_dens(1000.0),
19 m_iState(WATER_LIQUID),
20 EW_Offset(0.0),
21 SW_Offset(0.0),
22 m_allowGasPhase(false)
23{
24 m_minTemp = 200.;
25 m_maxTemp = 10000.;
27
28 // Set the baseline
29 doublereal T = 298.15;
30 m_p0 = OneAtm;
31 doublereal presLow = 1.0E-2;
32 doublereal oneBar = 1.0E5;
33 doublereal dens = 1.0E-9;
34 m_dens = m_sub.density(T, presLow, WATER_GAS, dens);
35 m_pres = presLow;
36 SW_Offset = 0.0;
37 doublereal s = entropy_mole();
38 s -= GasConstant * log(oneBar/presLow);
39 if (s != 188.835E3) {
40 SW_Offset = 188.835E3 - s;
41 }
42 s = entropy_mole();
43 s -= GasConstant * log(oneBar/presLow);
44
45 doublereal h = enthalpy_mole();
46 if (h != -241.826E6) {
47 EW_Offset = -241.826E6 - h;
48 }
49 h = enthalpy_mole();
50
51 // Set the initial state of the system to 298.15 K and 1 bar.
52 setTemperature(298.15);
53 m_dens = m_sub.density(298.15, OneAtm, WATER_LIQUID);
54 m_pres = OneAtm;
55}
56
57doublereal PDSS_Water::enthalpy_mole() const
58{
59 return m_sub.enthalpy() + EW_Offset;
60}
61
63{
64 return m_sub.intEnergy() + EW_Offset;
65}
66
67doublereal PDSS_Water::entropy_mole() const
68{
69 return m_sub.entropy() + SW_Offset;
70}
71
72doublereal PDSS_Water::gibbs_mole() const
73{
75}
76
77doublereal PDSS_Water::cp_mole() const
78{
79 return m_sub.cp();
80}
81
82doublereal PDSS_Water::cv_mole() const
83{
84 return m_sub.cv();
85}
86
87doublereal PDSS_Water::molarVolume() const
88{
89 return m_sub.molarVolume();
90}
91
92doublereal PDSS_Water::gibbs_RT_ref() const
93{
94 doublereal T = m_temp;
96 doublereal h = m_sub.enthalpy();
98 return (h + EW_Offset - SW_Offset*T)/(T * GasConstant);
99}
100
102{
103 doublereal T = m_temp;
105 doublereal h = m_sub.enthalpy();
107 return (h + EW_Offset)/(T * GasConstant);
108}
109
111{
112 doublereal T = m_temp;
114 doublereal s = m_sub.entropy();
116 return (s + SW_Offset)/GasConstant;
117}
118
119doublereal PDSS_Water::cp_R_ref() const
120{
121 doublereal T = m_temp;
123 doublereal cp = m_sub.cp();
125 return cp/GasConstant;
126}
127
129{
130 doublereal T = m_temp;
132 doublereal mv = m_sub.molarVolume();
134 return mv;
135}
136
137doublereal PDSS_Water::pressure() const
138{
140 return m_pres;
141}
142
143void PDSS_Water::setPressure(doublereal p)
144{
145 // In this routine we must be sure to only find the water branch of the
146 // curve and not the gas branch
147 doublereal T = m_temp;
148 doublereal dens = m_dens;
149 int waterState = WATER_LIQUID;
150 if (T > m_sub.Tcrit()) {
151 waterState = WATER_SUPERCRIT;
152 }
153
154 doublereal dd = m_sub.density(T, p, waterState, dens);
155 if (dd <= 0.0) {
156 throw CanteraError("PDSS_Water:setPressure",
157 "Failed to set water SS state: T = {} K and p = {} Pa", T, p);
158 }
159 m_dens = dd;
160 m_pres = p;
161
162 // We are only putting the phase check here because of speed considerations.
163 m_iState = m_sub.phaseState(true);
164 if (!m_allowGasPhase && m_iState != WATER_SUPERCRIT && m_iState != WATER_LIQUID && m_iState != WATER_UNSTABLELIQUID) {
165 throw CanteraError("PDSS_Water::setPressure",
166 "Water State isn't liquid or crit");
167 }
168}
169
171{
172 return m_sub.coeffThermExp();
173}
174
176{
177 doublereal pres = pressure();
178 doublereal dens_save = m_dens;
179 doublereal tt = m_temp - 0.04;
180 doublereal dd = m_sub.density(tt, pres, m_iState, m_dens);
181 if (dd < 0.0) {
182 throw CanteraError("PDSS_Water::dthermalExpansionCoeffdT",
183 "unable to solve for the density at T = {}, P = {}", tt, pres);
184 }
185 doublereal vald = m_sub.coeffThermExp();
186 m_sub.setState_TR(m_temp, dens_save);
187 doublereal val2 = m_sub.coeffThermExp();
188 return (val2 - vald) / 0.04;
189}
190
192{
194}
195
197{
198 return m_sub.Tcrit();
199}
200
201doublereal PDSS_Water::critPressure() const
202{
203 return m_sub.Pcrit();
204}
205
206doublereal PDSS_Water::critDensity() const
207{
208 return m_sub.Rhocrit();
209}
210
211void PDSS_Water::setDensity(doublereal dens)
212{
213 m_dens = dens;
215}
216
217doublereal PDSS_Water::density() const
218{
219 return m_dens;
220}
221
222void PDSS_Water::setTemperature(doublereal temp)
223{
224 m_temp = temp;
225 m_sub.setState_TR(temp, m_dens);
226}
227
228void PDSS_Water::setState_TP(doublereal temp, doublereal pres)
229{
230 m_temp = temp;
231 setPressure(pres);
232}
233
234void PDSS_Water::setState_TR(doublereal temp, doublereal dens)
235{
236 m_temp = temp;
237 m_dens = dens;
239}
240
241doublereal PDSS_Water::pref_safe(doublereal temp) const
242{
243 if (temp < m_sub.Tcrit()) {
244 doublereal pp = m_sub.psat_est(temp);
245 if (pp > OneAtm) {
246 return pp;
247 }
248 } else {
249 return m_sub.Pcrit();
250 }
251 return OneAtm;
252}
253
254doublereal PDSS_Water::satPressure(doublereal t)
255{
256 doublereal pp = m_sub.psat(t, WATER_LIQUID);
257 m_dens = m_sub.density();
258 m_temp = t;
259 return pp;
260}
261
263{
264 eosNode["model"] = "liquid-water-IAPWS95";
265}
266
267}
Contains the getElementWeight function and the definitions of element constraint types.
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS_Water.cpp:262
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_Water.cpp:119
WaterPropsIAPWS m_sub
Pointer to the WaterPropsIAPWS object, which does the actual calculations for the real equation of st...
Definition: PDSS_Water.h:161
virtual doublereal pressure() const
Returns the pressure (Pa)
Definition: PDSS_Water.cpp:137
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:77
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:241
virtual doublereal critPressure() const
critical pressure
Definition: PDSS_Water.cpp:201
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:57
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_Water.cpp:143
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:228
doublereal EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition: PDSS_Water.h:197
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:82
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: PDSS_Water.cpp:170
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_Water.cpp:222
virtual doublereal dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient.
Definition: PDSS_Water.cpp:175
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:67
void setDensity(doublereal dens)
Set the density of the water phase.
Definition: PDSS_Water.cpp:211
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_Water.cpp:128
virtual doublereal critTemperature() const
critical temperature
Definition: PDSS_Water.cpp:196
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_Water.cpp:87
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_Water.cpp:72
int m_iState
state of the fluid
Definition: PDSS_Water.h:190
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:101
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_Water.cpp:234
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:217
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_Water.cpp:110
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_Water.cpp:254
doublereal m_dens
State of the system - density.
Definition: PDSS_Water.h:178
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
Definition: PDSS_Water.cpp:92
doublereal SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition: PDSS_Water.h:204
bool m_allowGasPhase
Since this phase represents a liquid phase, it's an error to return a gas-phase answer.
Definition: PDSS_Water.h:213
virtual doublereal critDensity() const
critical density
Definition: PDSS_Water.cpp:206
PDSS_Water()
Default constructor.
Definition: PDSS_Water.cpp:16
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_Water.cpp:62
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: PDSS_Water.cpp:191
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:458
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:455
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:467
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:461
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:470
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:464
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 coeffThermExp() const
Returns the coefficient of thermal expansion.
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density.
doublereal enthalpy() const
Calculate the enthalpy in mks units of J kmol-1 using the last temperature and density.
doublereal Tcrit() const
Returns the critical temperature of water (Kelvin)
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
doublereal molarVolume() const
Calculate the molar volume (kmol m-3) at the last temperature and density.
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
doublereal Rhocrit() const
Return the critical density of water (kg m-3)
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
doublereal psat_est(doublereal temperature) const
This function returns an estimated value for the saturation pressure.
doublereal psat(doublereal temperature, int waterState=WATER_LIQUID)
This function returns the saturation pressure given the temperature as an input parameter,...
void setState_TR(doublereal temperature, doublereal rho)
Set the internal state of the object wrt temperature and density.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
doublereal isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
doublereal Pcrit() const
Returns the critical pressure of water (22.064E6 Pa)
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:81
double getElementWeight(const std::string &ename)
Get the atomic weight of an element.
Definition: Elements.cpp:207
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Contains declarations for string manipulation functions within Cantera.