21const double T_c = 647.096;
23static const double P_c = 22.064E6;
27static const double R_water = 461.51805;
55 int phase,
double rhoguess)
63 double deltaGuess = 0.0;
64 if (rhoguess == -1.0) {
69 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
71 }
else if (phase == WATER_LIQUID) {
75 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
77 "Unstable Branch finder is untested");
80 "unknown state: {}", phase);
90 deltaGuess = rhoguess /
Rho_c;
93 if (delta_retn <= 0) {
99 if (delta_retn > 0.0) {
103 density_retn = delta_retn *
Rho_c;
117 "To be removed after Cantera 3.1.");
119 double deltaGuess = 0.0;
120 double deltaSave =
delta;
121 if (rhoguess == -1.0) {
126 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
128 }
else if (phase == WATER_LIQUID) {
132 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
134 "Unstable Branch finder is untested");
137 "unknown state: {}", phase);
147 deltaGuess = rhoguess /
Rho_c;
154 if (delta_retn > 0.0) {
158 density_retn = delta_retn *
Rho_c;
185 static const double A[8] = {
202 double w = fabs(1.0-v);
204 for (
int i = 0; i < 8; i++) {
206 b += A[i] * pow(w, ((z+1.0)/2.0));
219 double dpdrho_val =
dpdrho();
221 return 1.0 / (dens * dpdrho_val);
241 return kappa * dens * R_water * beta;
245 double& densLiq,
double& densGas,
double& delGRT)
248 if (densLiq <= 0.0) {
250 "Error occurred trying to find liquid density at (T,P) = {} {}",
257 if (densGas <= 0.0) {
259 "Error occurred trying to find gas density at (T,P) = {} {}",
265 delGRT = gibbsLiqRT - gibbsGasRT;
270 double densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
277 for (
int i = 0; i < 30; i++) {
279 double delV = 1.0/densLiq - 1.0/densGas;
281 if (delGRT < 1.0E-8) {
286 if (waterState == WATER_LIQUID) {
288 }
else if (waterState == WATER_GAS) {
292 "unknown water state input: {}", waterState);
305 double rhoMidAtm = 0.5 * (
OneAtm / (R_water * 373.15) + 1.0E3);
307 int iStateGuess = WATER_LIQUID;
309 iStateGuess = WATER_GAS;
316 double rhoDel = rho * 1.000001;
317 double deltaSave =
delta;
318 double deltaDel = rhoDel /
Rho_c;
323 double d2rhodp2 = (rhoDel * kappaDel - rho * kappa) / (rhoDel - rho);
324 if (d2rhodp2 > 0.0) {
325 iState = WATER_UNSTABLELIQUID;
327 iState = WATER_UNSTABLEGAS;
340 "To be removed after Cantera 3.1.");
342 double delta_save =
delta;
350 double rho_low = 0.0;
351 double rho_high = 1000;
353 double dens_old = densSatLiq;
356 double dpdrho_old =
dpdrho();
357 if (dpdrho_old > 0.0) {
358 rho_high = std::min(dens_old, rho_high);
360 rho_low = std::max(rho_low, dens_old);
362 double dens_new = densSatLiq* (1.0001);
365 double dpdrho_new =
dpdrho();
366 if (dpdrho_new > 0.0) {
367 rho_high = std::min(dens_new, rho_high);
369 rho_low = std::max(rho_low, dens_new);
373 for (
int it = 0; it < 50; it++) {
374 double slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
376 slope = std::max(slope, dpdrho_new *5.0/ dens_new);
381 double delta_rho = - dpdrho_new / slope;
382 if (delta_rho > 0.0) {
383 delta_rho = std::min(delta_rho, dens_new * 0.1);
385 delta_rho = std::max(delta_rho, - dens_new * 0.1);
387 double dens_est = dens_new + delta_rho;
388 if (dens_est < rho_low) {
389 dens_est = 0.5 * (rho_low + dens_new);
391 if (dens_est > rho_high) {
392 dens_est = 0.5 * (rho_high + dens_new);
396 dpdrho_old = dpdrho_new;
402 if (dpdrho_new > 0.0) {
403 rho_high = std::min(dens_new, rho_high);
404 }
else if (dpdrho_new < 0.0) {
405 rho_low = std::max(rho_low, dens_new);
411 if (fabs(dpdrho_new) < 1.0E-5) {
418 throw CanteraError(
"WaterPropsIAPWS::densSpinodalWater",
419 "convergence failure");
430 "To be removed after Cantera 3.1.");
432 double delta_save =
delta;
440 double rho_low = 0.0;
441 double rho_high = 1000;
443 double dens_old = densSatGas;
446 double dpdrho_old =
dpdrho();
447 if (dpdrho_old < 0.0) {
448 rho_high = std::min(dens_old, rho_high);
450 rho_low = std::max(rho_low, dens_old);
452 double dens_new = densSatGas * (0.99);
455 double dpdrho_new =
dpdrho();
456 if (dpdrho_new < 0.0) {
457 rho_high = std::min(dens_new, rho_high);
459 rho_low = std::max(rho_low, dens_new);
462 for (
int it = 0; it < 50; it++) {
463 double slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
468 slope = std::min(slope, dpdrho_new *5.0 / dens_new);
471 double delta_rho = - dpdrho_new / slope;
472 if (delta_rho > 0.0) {
473 delta_rho = std::min(delta_rho, dens_new * 0.1);
475 delta_rho = std::max(delta_rho, - dens_new * 0.1);
477 double dens_est = dens_new + delta_rho;
478 if (dens_est < rho_low) {
479 dens_est = 0.5 * (rho_low + dens_new);
481 if (dens_est > rho_high) {
482 dens_est = 0.5 * (rho_high + dens_new);
486 dpdrho_old = dpdrho_new;
491 if (dpdrho_new < 0.0) {
492 rho_high = std::min(dens_new, rho_high);
493 }
else if (dpdrho_new > 0.0) {
494 rho_low = std::max(rho_low, dens_new);
500 if (fabs(dpdrho_new) < 1.0E-5) {
507 throw CanteraError(
"WaterPropsIAPWS::densSpinodalSteam",
508 "convergence failure");
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...
Base class for exceptions thrown by Cantera classes.
double coeffThermExp() const
Returns the coefficient of thermal expansion.
double densSpinodalSteam() const
Return the value of the density at the water spinodal point (on the gas side) for the current tempera...
double density() const
Returns the density (kg m-3)
void corr(double temperature, double pressure, double &densLiq, double &densGas, double &delGRT)
Utility routine in the calculation of the saturation pressure.
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 temperature() const
Returns the temperature (Kelvin)
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 densSpinodalWater() const
Return the value of the density at the water spinodal point (on the liquid side) for the current temp...
double delta
Dimensionless density, delta = rho / rho_c.
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.
double coeffPresExp() const
Returns the isochoric pressure derivative wrt temperature.
int iState
Current state of the system.
void setState_TD(double temperature, double rho)
Set the internal state of the object wrt temperature and density.
double tau
Dimensionless temperature, tau = T_C / T.
WaterPropsIAPWSphi m_phi
pointer to the underlying object that does the calculations.
double density_const(double pressure, int phase=-1, double rhoguess=-1.0) const
Calculates the density given the temperature and the pressure, and a guess at the density,...
void calcDim(double temperature, double rho)
Calculate the dimensionless temp and rho and store internally.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
double dpdrho() const
Returns the value of dp / drho at constant T for the state of the object.
double psat_est(double temperature) const
This function returns an estimated value for the saturation pressure.
double enthalpy_mass() const
Get the enthalpy (J/kg) at the current temperature and density.
double gibbs_RT() const
Calculate the dimensionless Gibbs free energy.
double cv_R() const
Calculate the dimensionless constant volume heat capacity, Cv/R.
double intEnergy_RT() const
Calculate the dimensionless internal energy, u/RT.
double enthalpy_RT() const
Calculate the dimensionless enthalpy, h/RT.
double entropy_R() const
Calculate the dimensionless entropy, s/R.
double pressureM_rhoRT(double tau, double delta)
Calculate the dimensionless pressure at tau and delta;.
double dimdpdrho(double tau, double delta)
Dimensionless derivative of p wrt rho at constant T.
double dfind(double p_red, double tau, double deltaGuess)
This function computes the reduced density, given the reduced pressure and the reduced temperature,...
double dimdpdT(double tau, double delta)
Dimensionless derivative of p wrt T at constant rho.
double cp_R() const
Calculate the dimensionless constant pressure heat capacity, Cv/R.
void tdpolycalc(double tau, double delta)
Calculates internal polynomials in tau and delta.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
const double OneAtm
One atmosphere [Pa].
Namespace for the Cantera kernel.
const double Rho_c
Value of the Density at the critical point (kg m-3)
const double T_c
Critical Temperature value (kelvin)
static const double P_c
Critical Pressure (Pascals)
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Contains declarations for string manipulation functions within Cantera.