Cantera  3.2.0b1
Loading...
Searching...
No Matches
WaterSSTP.cpp
Go to the documentation of this file.
1/**
2 * @file WaterSSTP.cpp
3 * Definitions for a ThermoPhase class consisting of pure water (see @ref thermoprops
4 * and class @link Cantera::WaterSSTP WaterSSTP@endlink).
5 */
6
7// This file is part of Cantera. See License.txt in the top-level directory or
8// at https://cantera.org/license.txt for license and copyright information.
9
13
14namespace Cantera
15{
16WaterSSTP::WaterSSTP(const string& inputFile, const string& id)
17{
18 initThermoFile(inputFile, id);
19}
20
22 const vector<string> phases = {
23 "gas", "liquid", "supercritical", "unstable-liquid", "unstable-gas"
24 };
25 return phases[m_sub.phaseState()];
26}
27
29{
31
32 // Calculate the molecular weight. Note while there may be a very good
33 // calculated weight in the steam table class, using this weight may lead to
34 // codes exhibiting mass loss issues. We need to grab the elemental atomic
35 // weights used in the Element class and calculate a consistent H2O
36 // molecular weight based on that.
37 size_t nH = elementIndex("H", true);
38 double mw_H = atomicWeight(nH);
39 size_t nO = elementIndex("O", true);
40 double mw_O = atomicWeight(nO);
41 m_mw = 2.0 * mw_H + mw_O;
43
44 // Set the baseline
45 double T = 298.15;
46 Phase::setDensity(7.0E-8);
48
49 double presLow = 1.0E-2;
50 double oneBar = 1.0E5;
51 double dd = m_sub.density(T, presLow, WATER_GAS, 7.0E-8);
52 setDensity(dd);
54 SW_Offset = 0.0;
55 double s = entropy_mole();
56 s -= GasConstant * log(oneBar/presLow);
57 if (s != 188.835E3) {
58 SW_Offset = 188.835E3 - s;
59 }
60 s = entropy_mole();
61 s -= GasConstant * log(oneBar/presLow);
62
63 double h = enthalpy_mole();
64 if (h != -241.826E6) {
65 EW_Offset = -241.826E6 - h;
66 }
67 h = enthalpy_mole();
68
69 // Set the initial state of the system to 298.15 K and 1 bar.
70 setTemperature(298.15);
71 double rho0 = m_sub.density(298.15, OneAtm, WATER_LIQUID);
72 setDensity(rho0);
73
74 m_waterProps = make_unique<WaterProps>(&m_sub);
75
76 // Set the flag to say we are ready to calculate stuff
77 m_ready = true;
78}
79
80void WaterSSTP::getEnthalpy_RT(double* hrt) const
81{
82 *hrt = (m_sub.enthalpy_mass() * m_mw + EW_Offset) / RT();
83}
84
85void WaterSSTP::getIntEnergy_RT(double* ubar) const
86{
87 *ubar = (m_sub.intEnergy_mass() * m_mw + EW_Offset)/ RT();
88}
89
90void WaterSSTP::getEntropy_R(double* sr) const
91{
93}
94
95void WaterSSTP::getGibbs_RT(double* grt) const
96{
97 *grt = (m_sub.gibbs_mass() * m_mw + EW_Offset) / RT()
99 if (!m_ready) {
100 throw CanteraError("waterSSTP::getGibbs_RT", "Phase not ready");
101 }
102}
103
105{
107 if (!m_ready) {
108 throw CanteraError("waterSSTP::getStandardChemPotentials",
109 "Phase not ready");
110 }
111}
112
113void WaterSSTP::getCp_R(double* cpr) const
114{
115 cpr[0] = m_sub.cp_mass() * m_mw / GasConstant;
116}
117
118double WaterSSTP::cv_mole() const
119{
120 return m_sub.cv_mass() * m_mw;
121}
122
123void WaterSSTP::getEnthalpy_RT_ref(double* hrt) const
124{
125 double p = pressure();
126 double T = temperature();
127 double dens = density();
128 int waterState = WATER_GAS;
129 double rc = m_sub.Rhocrit();
130 if (dens > rc) {
131 waterState = WATER_LIQUID;
132 }
133 double dd = m_sub.density(T, OneAtm, waterState, dens);
134 if (dd <= 0.0) {
135 throw CanteraError("WaterSSTP::getEnthalpy_RT_ref", "error");
136 }
137 double h = m_sub.enthalpy_mass() * m_mw;
138 *hrt = (h + EW_Offset) / RT();
139 dd = m_sub.density(T, p, waterState, dens);
140}
141
142void WaterSSTP::getGibbs_RT_ref(double* grt) const
143{
144 double p = pressure();
145 double T = temperature();
146 double dens = density();
147 int waterState = WATER_GAS;
148 double rc = m_sub.Rhocrit();
149 if (dens > rc) {
150 waterState = WATER_LIQUID;
151 }
152 double dd = m_sub.density(T, OneAtm, waterState, dens);
153 if (dd <= 0.0) {
154 throw CanteraError("WaterSSTP::getGibbs_RT_ref", "error");
155 }
156 m_sub.setState_TD(T, dd);
157 double g = m_sub.gibbs_mass() * m_mw;
158 *grt = (g + EW_Offset - SW_Offset*T)/ RT();
159 dd = m_sub.density(T, p, waterState, dens);
160}
161
162void WaterSSTP::getGibbs_ref(double* g) const
163{
165 for (size_t k = 0; k < m_kk; k++) {
166 g[k] *= RT();
167 }
168}
169
170void WaterSSTP::getEntropy_R_ref(double* sr) const
171{
172 double p = pressure();
173 double T = temperature();
174 double dens = density();
175 int waterState = WATER_GAS;
176 double rc = m_sub.Rhocrit();
177 if (dens > rc) {
178 waterState = WATER_LIQUID;
179 }
180 double dd = m_sub.density(T, OneAtm, waterState, dens);
181
182 if (dd <= 0.0) {
183 throw CanteraError("WaterSSTP::getEntropy_R_ref", "error");
184 }
185 m_sub.setState_TD(T, dd);
186
187 double s = m_sub.entropy_mass() * m_mw;
188 *sr = (s + SW_Offset)/ GasConstant;
189 dd = m_sub.density(T, p, waterState, dens);
190}
191
192void WaterSSTP::getCp_R_ref(double* cpr) const
193{
194 double p = pressure();
195 double T = temperature();
196 double dens = density();
197 int waterState = WATER_GAS;
198 double rc = m_sub.Rhocrit();
199 if (dens > rc) {
200 waterState = WATER_LIQUID;
201 }
202 double dd = m_sub.density(T, OneAtm, waterState, dens);
203 m_sub.setState_TD(T, dd);
204 if (dd <= 0.0) {
205 throw CanteraError("WaterSSTP::getCp_R_ref", "error");
206 }
207 double cp = m_sub.cp_mass() * m_mw;
208 *cpr = cp / GasConstant;
209 dd = m_sub.density(T, p, waterState, dens);
210}
211
213{
214 double p = pressure();
215 double T = temperature();
216 double dens = density();
217 int waterState = WATER_GAS;
218 double rc = m_sub.Rhocrit();
219 if (dens > rc) {
220 waterState = WATER_LIQUID;
221 }
222 double dd = m_sub.density(T, OneAtm, waterState, dens);
223 if (dd <= 0.0) {
224 throw CanteraError("WaterSSTP::getStandardVolumes_ref", "error");
225 }
226 *vol = meanMolecularWeight() /dd;
227 dd = m_sub.density(T, p, waterState, dens);
228}
229
231{
232 return m_sub.pressure();
233}
234
236{
237 double T = temperature();
238 double dens = density();
239 double pp = m_sub.psat(T);
240 int waterState = WATER_SUPERCRIT;
241 if (T < m_sub.Tcrit()) {
242 if (p >= pp) {
243 waterState = WATER_LIQUID;
244 dens = 1000.;
245 } else if (!m_allowGasPhase) {
246 throw CanteraError("WaterSSTP::setPressure",
247 "Model assumes liquid phase; pressure p = {} lies below\n"
248 "the saturation pressure (P_sat = {}).", p, pp);
249 }
250 }
251
252 double dd = m_sub.density(T, p, waterState, dens);
253 if (dd <= 0.0) {
254 throw CanteraError("WaterSSTP::setPressure", "Error");
255 }
256 setDensity(dd);
257}
258
260{
262}
263
265{
266 return m_sub.coeffThermExp();
267}
268
270{
271 double pres = pressure();
272 double dens_save = density();
273 double T = temperature();
274 double tt = T - 0.04;
275 double dd = m_sub.density(tt, pres, WATER_LIQUID, dens_save);
276 if (dd < 0.0) {
277 throw CanteraError("WaterSSTP::dthermalExpansionCoeffdT",
278 "Unable to solve for the density at T = {}, P = {}", tt, pres);
279 }
280 double vald = m_sub.coeffThermExp();
281 m_sub.setState_TD(T, dens_save);
282 double val2 = m_sub.coeffThermExp();
283 return (val2 - vald) / 0.04;
284}
285
287{
288 return m_sub.Tcrit();
289}
290
292{
293 return m_sub.Pcrit();
294}
295
297{
298 return m_sub.Rhocrit();
299}
300
301void WaterSSTP::setTemperature(const double temp)
302{
303 if (temp < 273.16) {
304 throw CanteraError("WaterSSTP::setTemperature",
305 "Model assumes liquid phase; temperature T = {} lies below\n"
306 "the triple point temperature (T_triple = 273.16).", temp);
307 }
309 m_sub.setState_TD(temp, density());
310}
311
312void WaterSSTP::setDensity(const double dens)
313{
314 Phase::setDensity(dens);
316}
317
318double WaterSSTP::satPressure(double t) {
319 double tsave = temperature();
320 double dsave = density();
321 double pp = m_sub.psat(t);
322 m_sub.setState_TD(tsave, dsave);
323 return pp;
324}
325
327{
328 if (temperature() >= m_sub.Tcrit()) {
329 double dens = density();
330 if (dens >= m_sub.Rhocrit()) {
331 return 0.0;
332 }
333 return 1.0;
334 }
335 // If below tcrit we always return 0 from this class
336 return 0.0;
337}
338
339}
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Declares a ThermoPhase class consisting of pure water (see Thermodynamic Properties and class WaterSS...
Base class for exceptions thrown by Cantera classes.
size_t m_kk
Number of species in the phase.
Definition Phase.h:921
double temperature() const
Temperature (K).
Definition Phase.h:629
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:722
size_t elementIndex(const string &name) const
Return the index of element named 'name'.
Definition Phase.cpp:60
double atomicWeight(size_t m) const
Atomic weight of element m.
Definition Phase.cpp:89
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition Phase.cpp:649
virtual double density() const
Density (kg/m^3).
Definition Phase.h:654
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:690
void setMolecularWeight(const int k, const double mw)
Set the molecular weight of a single species to a given value.
Definition Phase.cpp:971
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
double RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
double coeffThermExp() const
Returns the coefficient of thermal expansion.
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.
double pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density.
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 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 Rhocrit() const
Return the critical density of water (kg m-3)
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.
void setState_TD(double temperature, double 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.
double enthalpy_mass() const
Get the enthalpy (J/kg) at the current temperature and density.
void setDensity(const double dens) override
Set the density of the phase.
unique_ptr< WaterProps > m_waterProps
Pointer to the WaterProps object.
Definition WaterSSTP.h:200
double thermalExpansionCoeff() const override
Return the volumetric thermal expansion coefficient. Units: 1/K.
WaterPropsIAPWS m_sub
WaterPropsIAPWS that calculates the real properties of water.
Definition WaterSSTP.h:192
bool m_ready
Boolean is true if object has been properly initialized for calculation.
Definition WaterSSTP.h:220
double pressure() const override
Return the thermodynamic pressure (Pa).
double critPressure() const override
Critical pressure (Pa).
double SW_Offset
Offset constant used to obtain consistency with NIST convention.
Definition WaterSSTP.h:217
double critDensity() const override
Critical density (kg/m3).
void getEntropy_R(double *sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition WaterSSTP.cpp:90
void getGibbs_ref(double *g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
double critTemperature() const override
Critical temperature (K).
WaterSSTP(const string &inputFile="", const string &id="")
Full constructor for a water phase.
Definition WaterSSTP.cpp:16
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
Definition WaterSSTP.cpp:28
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
void getStandardVolumes_ref(double *vol) const override
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
double vaporFraction() const override
Return the fraction of vapor at the current conditions.
double dthermalExpansionCoeffdT() const
Return the derivative of the volumetric thermal expansion coefficient.
double cv_mole() const override
Molar heat capacity at constant volume and composition [J/kmol/K].
double EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition WaterSSTP.h:210
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition WaterSSTP.cpp:80
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
void setTemperature(const double temp) override
Set the temperature of the phase.
double isothermalCompressibility() const override
Returns the isothermal compressibility. Units: 1/Pa.
void getGibbs_RT(double *grt) const override
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition WaterSSTP.cpp:95
void getStandardChemPotentials(double *gss) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getCp_R_ref(double *cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition WaterSSTP.cpp:85
double m_mw
Molecular weight of Water -> Cantera assumption.
Definition WaterSSTP.h:203
bool m_allowGasPhase
Since this phase represents a liquid (or supercritical) phase, it is an error to return a gas-phase a...
Definition WaterSSTP.h:228
void getGibbs_RT_ref(double *grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
string phaseOfMatter() const override
String indicating the mechanical phase of the matter in this Phase.
Definition WaterSSTP.cpp:21
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
double satPressure(double t) override
Return the saturation pressure given the temperature.
const double OneAtm
One atmosphere [Pa].
Definition ct_defs.h:96
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
Contains declarations for string manipulation functions within Cantera.