| Cantera 3.0.0

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