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 double deltaGuess = 0.0;
118 double deltaSave =
delta;
119 if (rhoguess == -1.0) {
124 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
126 }
else if (phase == WATER_LIQUID) {
130 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
132 "Unstable Branch finder is untested");
135 "unknown state: {}", phase);
145 deltaGuess = rhoguess /
Rho_c;
152 if (delta_retn > 0.0) {
156 density_retn = delta_retn *
Rho_c;
183 static const double A[8] = {
200 double w = fabs(1.0-v);
202 for (
int i = 0; i < 8; i++) {
204 b += A[i] * pow(w, ((z+1.0)/2.0));
217 double dpdrho_val =
dpdrho();
219 return 1.0 / (dens * dpdrho_val);
239 return kappa * dens * R_water * beta;
243 double& densLiq,
double& densGas,
double& delGRT)
246 if (densLiq <= 0.0) {
248 "Error occurred trying to find liquid density at (T,P) = {} {}",
255 if (densGas <= 0.0) {
257 "Error occurred trying to find gas density at (T,P) = {} {}",
263 delGRT = gibbsLiqRT - gibbsGasRT;
267 double& densLiq,
double& densGas,
double& pcorr)
270 if (densLiq <= 0.0) {
272 "Error occurred trying to find liquid density at (T,P) = {} {}",
279 if (densGas <= 0.0) {
281 "Error occurred trying to find gas density at (T,P) = {} {}",
286 double rhs = (prL - prG) + log(densLiq/densGas);
287 rhs /= (1.0/densGas - 1.0/densLiq);
293 static int method = 1;
294 double densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
302 for (
int i = 0; i < 30; i++) {
305 double delV = 1.0/densLiq - 1.0/densGas;
313 if ((method == 1) && delGRT < 1.0E-8) {
316 if (fabs(dp/p) < 1.0E-9) {
322 if (waterState == WATER_LIQUID) {
324 }
else if (waterState == WATER_GAS) {
328 "unknown water state input: {}", waterState);
341 double rhoMidAtm = 0.5 * (
OneAtm / (R_water * 373.15) + 1.0E3);
343 int iStateGuess = WATER_LIQUID;
345 iStateGuess = WATER_GAS;
352 double rhoDel = rho * 1.000001;
353 double deltaSave =
delta;
354 double deltaDel = rhoDel /
Rho_c;
359 double d2rhodp2 = (rhoDel * kappaDel - rho * kappa) / (rhoDel - rho);
360 if (d2rhodp2 > 0.0) {
361 iState = WATER_UNSTABLELIQUID;
363 iState = WATER_UNSTABLEGAS;
376 double delta_save =
delta;
384 double rho_low = 0.0;
385 double rho_high = 1000;
387 double dens_old = densSatLiq;
390 double dpdrho_old =
dpdrho();
391 if (dpdrho_old > 0.0) {
392 rho_high = std::min(dens_old, rho_high);
394 rho_low = std::max(rho_low, dens_old);
396 double dens_new = densSatLiq* (1.0001);
399 double dpdrho_new =
dpdrho();
400 if (dpdrho_new > 0.0) {
401 rho_high = std::min(dens_new, rho_high);
403 rho_low = std::max(rho_low, dens_new);
407 for (
int it = 0; it < 50; it++) {
408 double slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
410 slope = std::max(slope, dpdrho_new *5.0/ dens_new);
415 double delta_rho = - dpdrho_new / slope;
416 if (delta_rho > 0.0) {
417 delta_rho = std::min(delta_rho, dens_new * 0.1);
419 delta_rho = std::max(delta_rho, - dens_new * 0.1);
421 double dens_est = dens_new + delta_rho;
422 if (dens_est < rho_low) {
423 dens_est = 0.5 * (rho_low + dens_new);
425 if (dens_est > rho_high) {
426 dens_est = 0.5 * (rho_high + dens_new);
430 dpdrho_old = dpdrho_new;
436 if (dpdrho_new > 0.0) {
437 rho_high = std::min(dens_new, rho_high);
438 }
else if (dpdrho_new < 0.0) {
439 rho_low = std::max(rho_low, dens_new);
445 if (fabs(dpdrho_new) < 1.0E-5) {
452 throw CanteraError(
"WaterPropsIAPWS::densSpinodalWater",
453 "convergence failure");
464 double delta_save =
delta;
472 double rho_low = 0.0;
473 double rho_high = 1000;
475 double dens_old = densSatGas;
478 double dpdrho_old =
dpdrho();
479 if (dpdrho_old < 0.0) {
480 rho_high = std::min(dens_old, rho_high);
482 rho_low = std::max(rho_low, dens_old);
484 double dens_new = densSatGas * (0.99);
487 double dpdrho_new =
dpdrho();
488 if (dpdrho_new < 0.0) {
489 rho_high = std::min(dens_new, rho_high);
491 rho_low = std::max(rho_low, dens_new);
494 for (
int it = 0; it < 50; it++) {
495 double slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
500 slope = std::min(slope, dpdrho_new *5.0 / dens_new);
503 double delta_rho = - dpdrho_new / slope;
504 if (delta_rho > 0.0) {
505 delta_rho = std::min(delta_rho, dens_new * 0.1);
507 delta_rho = std::max(delta_rho, - dens_new * 0.1);
509 double dens_est = dens_new + delta_rho;
510 if (dens_est < rho_low) {
511 dens_est = 0.5 * (rho_low + dens_new);
513 if (dens_est > rho_high) {
514 dens_est = 0.5 * (rho_high + dens_new);
518 dpdrho_old = dpdrho_new;
523 if (dpdrho_new < 0.0) {
524 rho_high = std::min(dens_new, rho_high);
525 }
else if (dpdrho_new > 0.0) {
526 rho_low = std::max(rho_low, dens_new);
532 if (fabs(dpdrho_new) < 1.0E-5) {
539 throw CanteraError(
"WaterPropsIAPWS::densSpinodalSteam",
540 "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.
void corr1(double temperature, double pressure, double &densLiq, double &densGas, double &pcorr)
Utility routine in the calculation of the saturation pressure.
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 phiR() const
Calculate Equation 6.6 for phiR, the residual part of the dimensionless Helmholtz free energy.
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)
Contains declarations for string manipulation functions within Cantera.