Cantera  3.1.0a1
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");
38 if (nH == npos) {
39 throw CanteraError("WaterSSTP::initThermo",
40 "H not an element");
41 }
42 double mw_H = atomicWeight(nH);
43 size_t nO = elementIndex("O");
44 if (nO == npos) {
45 throw CanteraError("WaterSSTP::initThermo",
46 "O not an element");
47 }
48 double mw_O = atomicWeight(nO);
49 m_mw = 2.0 * mw_H + mw_O;
51
52 // Set the baseline
53 double T = 298.15;
54 Phase::setDensity(7.0E-8);
56
57 double presLow = 1.0E-2;
58 double oneBar = 1.0E5;
59 double dd = m_sub.density(T, presLow, WATER_GAS, 7.0E-8);
60 setDensity(dd);
62 SW_Offset = 0.0;
63 double s = entropy_mole();
64 s -= GasConstant * log(oneBar/presLow);
65 if (s != 188.835E3) {
66 SW_Offset = 188.835E3 - s;
67 }
68 s = entropy_mole();
69 s -= GasConstant * log(oneBar/presLow);
70
71 double h = enthalpy_mole();
72 if (h != -241.826E6) {
73 EW_Offset = -241.826E6 - h;
74 }
75 h = enthalpy_mole();
76
77 // Set the initial state of the system to 298.15 K and 1 bar.
78 setTemperature(298.15);
79 double rho0 = m_sub.density(298.15, OneAtm, WATER_LIQUID);
80 setDensity(rho0);
81
82 m_waterProps = make_unique<WaterProps>(&m_sub);
83
84 // Set the flag to say we are ready to calculate stuff
85 m_ready = true;
86}
87
88void WaterSSTP::getEnthalpy_RT(double* hrt) const
89{
90 *hrt = (m_sub.enthalpy_mass() * m_mw + EW_Offset) / RT();
91}
92
93void WaterSSTP::getIntEnergy_RT(double* ubar) const
94{
95 *ubar = (m_sub.intEnergy_mass() * m_mw + EW_Offset)/ RT();
96}
97
98void WaterSSTP::getEntropy_R(double* sr) const
99{
100 sr[0] = (m_sub.entropy_mass() * m_mw + SW_Offset) / GasConstant;
101}
102
103void WaterSSTP::getGibbs_RT(double* grt) const
104{
105 *grt = (m_sub.gibbs_mass() * m_mw + EW_Offset) / RT()
107 if (!m_ready) {
108 throw CanteraError("waterSSTP::getGibbs_RT", "Phase not ready");
109 }
110}
111
113{
115 if (!m_ready) {
116 throw CanteraError("waterSSTP::getStandardChemPotentials",
117 "Phase not ready");
118 }
119}
120
121void WaterSSTP::getCp_R(double* cpr) const
122{
123 cpr[0] = m_sub.cp_mass() * m_mw / GasConstant;
124}
125
126double WaterSSTP::cv_mole() const
127{
128 return m_sub.cv_mass() * m_mw;
129}
130
131void WaterSSTP::getEnthalpy_RT_ref(double* hrt) const
132{
133 double p = pressure();
134 double T = temperature();
135 double dens = density();
136 int waterState = WATER_GAS;
137 double rc = m_sub.Rhocrit();
138 if (dens > rc) {
139 waterState = WATER_LIQUID;
140 }
141 double dd = m_sub.density(T, OneAtm, waterState, dens);
142 if (dd <= 0.0) {
143 throw CanteraError("WaterSSTP::getEnthalpy_RT_ref", "error");
144 }
145 double h = m_sub.enthalpy_mass() * m_mw;
146 *hrt = (h + EW_Offset) / RT();
147 dd = m_sub.density(T, p, waterState, dens);
148}
149
150void WaterSSTP::getGibbs_RT_ref(double* grt) const
151{
152 double p = pressure();
153 double T = temperature();
154 double dens = density();
155 int waterState = WATER_GAS;
156 double rc = m_sub.Rhocrit();
157 if (dens > rc) {
158 waterState = WATER_LIQUID;
159 }
160 double dd = m_sub.density(T, OneAtm, waterState, dens);
161 if (dd <= 0.0) {
162 throw CanteraError("WaterSSTP::getGibbs_RT_ref", "error");
163 }
164 m_sub.setState_TD(T, dd);
165 double g = m_sub.gibbs_mass() * m_mw;
166 *grt = (g + EW_Offset - SW_Offset*T)/ RT();
167 dd = m_sub.density(T, p, waterState, dens);
168}
169
170void WaterSSTP::getGibbs_ref(double* g) const
171{
173 for (size_t k = 0; k < m_kk; k++) {
174 g[k] *= RT();
175 }
176}
177
178void WaterSSTP::getEntropy_R_ref(double* sr) const
179{
180 double p = pressure();
181 double T = temperature();
182 double dens = density();
183 int waterState = WATER_GAS;
184 double rc = m_sub.Rhocrit();
185 if (dens > rc) {
186 waterState = WATER_LIQUID;
187 }
188 double dd = m_sub.density(T, OneAtm, waterState, dens);
189
190 if (dd <= 0.0) {
191 throw CanteraError("WaterSSTP::getEntropy_R_ref", "error");
192 }
193 m_sub.setState_TD(T, dd);
194
195 double s = m_sub.entropy_mass() * m_mw;
196 *sr = (s + SW_Offset)/ GasConstant;
197 dd = m_sub.density(T, p, waterState, dens);
198}
199
200void WaterSSTP::getCp_R_ref(double* cpr) const
201{
202 double p = pressure();
203 double T = temperature();
204 double dens = density();
205 int waterState = WATER_GAS;
206 double rc = m_sub.Rhocrit();
207 if (dens > rc) {
208 waterState = WATER_LIQUID;
209 }
210 double dd = m_sub.density(T, OneAtm, waterState, dens);
211 m_sub.setState_TD(T, dd);
212 if (dd <= 0.0) {
213 throw CanteraError("WaterSSTP::getCp_R_ref", "error");
214 }
215 double cp = m_sub.cp_mass() * m_mw;
216 *cpr = cp / GasConstant;
217 dd = m_sub.density(T, p, waterState, dens);
218}
219
221{
222 double p = pressure();
223 double T = temperature();
224 double dens = density();
225 int waterState = WATER_GAS;
226 double rc = m_sub.Rhocrit();
227 if (dens > rc) {
228 waterState = WATER_LIQUID;
229 }
230 double dd = m_sub.density(T, OneAtm, waterState, dens);
231 if (dd <= 0.0) {
232 throw CanteraError("WaterSSTP::getStandardVolumes_ref", "error");
233 }
234 *vol = meanMolecularWeight() /dd;
235 dd = m_sub.density(T, p, waterState, dens);
236}
237
239{
240 return m_sub.pressure();
241}
242
244{
245 double T = temperature();
246 double dens = density();
247 double pp = m_sub.psat(T);
248 int waterState = WATER_SUPERCRIT;
249 if (T < m_sub.Tcrit()) {
250 if (p >= pp) {
251 waterState = WATER_LIQUID;
252 dens = 1000.;
253 } else if (!m_allowGasPhase) {
254 throw CanteraError("WaterSSTP::setPressure",
255 "Model assumes liquid phase; pressure p = {} lies below\n"
256 "the saturation pressure (P_sat = {}).", p, pp);
257 }
258 }
259
260 double dd = m_sub.density(T, p, waterState, dens);
261 if (dd <= 0.0) {
262 throw CanteraError("WaterSSTP::setPressure", "Error");
263 }
264 setDensity(dd);
265}
266
268{
270}
271
273{
274 return m_sub.coeffThermExp();
275}
276
278{
279 double pres = pressure();
280 double dens_save = density();
281 double T = temperature();
282 double tt = T - 0.04;
283 double dd = m_sub.density(tt, pres, WATER_LIQUID, dens_save);
284 if (dd < 0.0) {
285 throw CanteraError("WaterSSTP::dthermalExpansionCoeffdT",
286 "Unable to solve for the density at T = {}, P = {}", tt, pres);
287 }
288 double vald = m_sub.coeffThermExp();
289 m_sub.setState_TD(T, dens_save);
290 double val2 = m_sub.coeffThermExp();
291 return (val2 - vald) / 0.04;
292}
293
295{
296 return m_sub.Tcrit();
297}
298
300{
301 return m_sub.Pcrit();
302}
303
305{
306 return m_sub.Rhocrit();
307}
308
309void WaterSSTP::setTemperature(const double temp)
310{
311 if (temp < 273.16) {
312 throw CanteraError("WaterSSTP::setTemperature",
313 "Model assumes liquid phase; temperature T = {} lies below\n"
314 "the triple point temperature (T_triple = 273.16).", temp);
315 }
317 m_sub.setState_TD(temp, density());
318}
319
320void WaterSSTP::setDensity(const double dens)
321{
322 Phase::setDensity(dens);
324}
325
326double WaterSSTP::satPressure(double t) {
327 double tsave = temperature();
328 double dsave = density();
329 double pp = m_sub.psat(t);
330 m_sub.setState_TD(tsave, dsave);
331 return pp;
332}
333
335{
336 if (temperature() >= m_sub.Tcrit()) {
337 double dens = density();
338 if (dens >= m_sub.Rhocrit()) {
339 return 0.0;
340 }
341 return 1.0;
342 }
343 // If below tcrit we always return 0 from this class
344 return 0.0;
345}
346
347}
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:842
double temperature() const
Temperature (K).
Definition Phase.h:562
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:655
size_t elementIndex(const string &name) const
Return the index of element named 'name'.
Definition Phase.cpp:55
double atomicWeight(size_t m) const
Atomic weight of element m.
Definition Phase.cpp:70
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition Phase.cpp:586
virtual double density() const
Density (kg/m^3).
Definition Phase.h:587
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:623
void setMolecularWeight(const int k, const double mw)
Set the molecular weight of a single species to a given value.
Definition Phase.cpp:895
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:98
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. Units: 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:88
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 ...
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:93
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:564
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:180
Contains declarations for string manipulation functions within Cantera.