Cantera  4.0.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", 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(span<double> hrt) const
81{
82 checkArraySize("WaterSSTP::getEnthalpy_RT", hrt.size(), 1);
83 hrt[0] = (m_sub.enthalpy_mass() * m_mw + EW_Offset) / RT();
84}
85
86void WaterSSTP::getIntEnergy_RT(span<double> ubar) const
87{
88 checkArraySize("WaterSSTP::getIntEnergy_RT", ubar.size(), 1);
89 ubar[0] = (m_sub.intEnergy_mass() * m_mw + EW_Offset)/ RT();
90}
91
92void WaterSSTP::getEntropy_R(span<double> sr) const
93{
94 checkArraySize("WaterSSTP::getEntropy_R", sr.size(), 1);
96}
97
98void WaterSSTP::getGibbs_RT(span<double> grt) const
99{
100 checkArraySize("WaterSSTP::getGibbs_RT", grt.size(), 1);
101 grt[0] = (m_sub.gibbs_mass() * m_mw + EW_Offset) / RT()
103 if (!m_ready) {
104 throw CanteraError("waterSSTP::getGibbs_RT", "Phase not ready");
105 }
106}
107
108void WaterSSTP::getStandardChemPotentials(span<double> gss) const
109{
110 checkArraySize("WaterSSTP::getStandardChemPotentials", gss.size(), 1);
111 gss[0] = (m_sub.gibbs_mass() * m_mw + EW_Offset - SW_Offset*temperature());
112 if (!m_ready) {
113 throw CanteraError("waterSSTP::getStandardChemPotentials",
114 "Phase not ready");
115 }
116}
117
118void WaterSSTP::getCp_R(span<double> cpr) const
119{
120 checkArraySize("WaterSSTP::getCp_R", cpr.size(), 1);
121 cpr[0] = m_sub.cp_mass() * m_mw / GasConstant;
122}
123
124double WaterSSTP::cv_mole() const
125{
126 return m_sub.cv_mass() * m_mw;
127}
128
129void WaterSSTP::getEnthalpy_RT_ref(span<double> hrt) const
130{
131 checkArraySize("WaterSSTP::getEnthalpy_RT_ref", hrt.size(), 1);
132 double p = pressure();
133 double T = temperature();
134 double dens = density();
135 int waterState = WATER_GAS;
136 double rc = m_sub.Rhocrit();
137 if (dens > rc) {
138 waterState = WATER_LIQUID;
139 }
140 double dd = m_sub.density(T, OneAtm, waterState, dens);
141 if (dd <= 0.0) {
142 throw CanteraError("WaterSSTP::getEnthalpy_RT_ref", "error");
143 }
144 double h = m_sub.enthalpy_mass() * m_mw;
145 hrt[0] = (h + EW_Offset) / RT();
146 dd = m_sub.density(T, p, waterState, dens);
147}
148
149void WaterSSTP::getGibbs_RT_ref(span<double> grt) const
150{
151 checkArraySize("WaterSSTP::getGibbs_RT_ref", grt.size(), 1);
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[0] = (g + EW_Offset - SW_Offset*T) / RT();
167 dd = m_sub.density(T, p, waterState, dens);
168}
169
170void WaterSSTP::getGibbs_ref(span<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(span<double> sr) const
179{
180 checkArraySize("WaterSSTP::getEntropy_R_ref", sr.size(), 1);
181 double p = pressure();
182 double T = temperature();
183 double dens = density();
184 int waterState = WATER_GAS;
185 double rc = m_sub.Rhocrit();
186 if (dens > rc) {
187 waterState = WATER_LIQUID;
188 }
189 double dd = m_sub.density(T, OneAtm, waterState, dens);
190
191 if (dd <= 0.0) {
192 throw CanteraError("WaterSSTP::getEntropy_R_ref", "error");
193 }
194 m_sub.setState_TD(T, dd);
195
196 double s = m_sub.entropy_mass() * m_mw;
197 sr[0] = (s + SW_Offset) / GasConstant;
198 dd = m_sub.density(T, p, waterState, dens);
199}
200
201void WaterSSTP::getCp_R_ref(span<double> cpr) const
202{
203 checkArraySize("WaterSSTP::getCp_R_ref", cpr.size(), 1);
204 double p = pressure();
205 double T = temperature();
206 double dens = density();
207 int waterState = WATER_GAS;
208 double rc = m_sub.Rhocrit();
209 if (dens > rc) {
210 waterState = WATER_LIQUID;
211 }
212 double dd = m_sub.density(T, OneAtm, waterState, dens);
213 m_sub.setState_TD(T, dd);
214 if (dd <= 0.0) {
215 throw CanteraError("WaterSSTP::getCp_R_ref", "error");
216 }
217 double cp = m_sub.cp_mass() * m_mw;
218 cpr[0] = cp / GasConstant;
219 dd = m_sub.density(T, p, waterState, dens);
220}
221
222void WaterSSTP::getStandardVolumes_ref(span<double> vol) const
223{
224 checkArraySize("WaterSSTP::getStandardVolumes_ref", vol.size(), 1);
225 double p = pressure();
226 double T = temperature();
227 double dens = density();
228 int waterState = WATER_GAS;
229 double rc = m_sub.Rhocrit();
230 if (dens > rc) {
231 waterState = WATER_LIQUID;
232 }
233 double dd = m_sub.density(T, OneAtm, waterState, dens);
234 if (dd <= 0.0) {
235 throw CanteraError("WaterSSTP::getStandardVolumes_ref", "error");
236 }
237 vol[0] = meanMolecularWeight() / dd;
238 dd = m_sub.density(T, p, waterState, dens);
239}
240
242{
243 return m_sub.pressure();
244}
245
247{
248 double T = temperature();
249 double dens = density();
250 double pp = m_sub.psat(T);
251 int waterState = WATER_SUPERCRIT;
252 if (T < m_sub.Tcrit()) {
253 if (p >= pp) {
254 waterState = WATER_LIQUID;
255 dens = 1000.;
256 } else if (!m_allowGasPhase) {
257 throw CanteraError("WaterSSTP::setPressure",
258 "Model assumes liquid phase; pressure p = {} lies below\n"
259 "the saturation pressure (P_sat = {}).", p, pp);
260 }
261 }
262
263 double dd = m_sub.density(T, p, waterState, dens);
264 if (dd <= 0.0) {
265 throw CanteraError("WaterSSTP::setPressure", "Error");
266 }
267 setDensity(dd);
268}
269
271{
273}
274
276{
277 return m_sub.coeffThermExp();
278}
279
281{
282 double pres = pressure();
283 double dens_save = density();
284 double T = temperature();
285 double tt = T - 0.04;
286 double dd = m_sub.density(tt, pres, WATER_LIQUID, dens_save);
287 if (dd < 0.0) {
288 throw CanteraError("WaterSSTP::dthermalExpansionCoeffdT",
289 "Unable to solve for the density at T = {}, P = {}", tt, pres);
290 }
291 double vald = m_sub.coeffThermExp();
292 m_sub.setState_TD(T, dens_save);
293 double val2 = m_sub.coeffThermExp();
294 return (val2 - vald) / 0.04;
295}
296
298{
299 return m_sub.Tcrit();
300}
301
303{
304 return m_sub.Pcrit();
305}
306
308{
309 return m_sub.Rhocrit();
310}
311
312void WaterSSTP::setTemperature(const double temp)
313{
314 if (temp < 273.16) {
315 throw CanteraError("WaterSSTP::setTemperature",
316 "Model assumes liquid phase; temperature T = {} lies below\n"
317 "the triple point temperature (T_triple = 273.16).", temp);
318 }
320 m_sub.setState_TD(temp, density());
321}
322
323void WaterSSTP::setDensity(const double dens)
324{
325 Phase::setDensity(dens);
327}
328
329double WaterSSTP::satPressure(double t) {
330 double tsave = temperature();
331 double dsave = density();
332 double pp = m_sub.psat(t);
333 m_sub.setState_TD(tsave, dsave);
334 return pp;
335}
336
338{
339 if (temperature() >= m_sub.Tcrit()) {
340 double dens = density();
341 if (dens >= m_sub.Rhocrit()) {
342 return 0.0;
343 }
344 return 1.0;
345 }
346 // If below tcrit we always return 0 from this class
347 return 0.0;
348}
349
350}
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:875
double temperature() const
Temperature (K).
Definition Phase.h:585
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:676
double atomicWeight(size_t m) const
Atomic weight of element m.
Definition Phase.cpp:69
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition Phase.cpp:597
virtual double density() const
Density (kg/m^3).
Definition Phase.h:610
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:646
void setMolecularWeight(const int k, const double mw)
Set the molecular weight of a single species to a given value.
Definition Phase.cpp:915
size_t elementIndex(const string &name, bool raise=true) const
Return the index of element named 'name'.
Definition Phase.cpp:51
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.
void getGibbs_ref(span< double > g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
unique_ptr< WaterProps > m_waterProps
Pointer to the WaterProps object.
Definition WaterSSTP.h:200
void getCp_R(span< double > cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
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
void getEntropy_R_ref(span< double > er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
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).
void getIntEnergy_RT(span< double > urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition WaterSSTP.cpp:86
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).
double critTemperature() const override
Critical temperature (K).
void getGibbs_RT(span< double > grt) const override
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition WaterSSTP.cpp:98
void getCp_R_ref(span< double > cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
WaterSSTP(const string &inputFile="", const string &id="")
Full constructor for a water phase.
Definition WaterSSTP.cpp:16
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.
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.
void getEnthalpy_RT_ref(span< double > hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
double cv_mole() const override
Molar heat capacity at constant volume and composition [J/kmol/K].
void getEnthalpy_RT(span< 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(span< double > sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition WaterSSTP.cpp:92
double EW_Offset
Offset constants used to obtain consistency with the NIST database.
Definition WaterSSTP.h:210
void setTemperature(const double temp) override
Set the temperature of the phase.
double isothermalCompressibility() const override
Returns the isothermal compressibility. Units: 1/Pa.
void getStandardChemPotentials(span< double > gss) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getGibbs_RT_ref(span< double > grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
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 getStandardVolumes_ref(span< double > vol) const override
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
string phaseOfMatter() const override
String indicating the mechanical phase of the matter in this Phase.
Definition WaterSSTP.cpp:21
double satPressure(double t) override
Return the saturation pressure given the temperature.
const double OneAtm
One atmosphere [Pa].
Definition ct_defs.h:99
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:123
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Contains declarations for string manipulation functions within Cantera.