20const doublereal
T_c = 647.096;
22static const doublereal
P_c = 22.064E6;
26static const doublereal
M_water = 18.015268;
35static const doublereal
Rgas = 8.314371E3;
79 int phase, doublereal rhoguess)
87 doublereal deltaGuess = 0.0;
88 if (rhoguess == -1.0) {
93 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
95 }
else if (phase == WATER_LIQUID) {
99 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
101 "Unstable Branch finder is untested");
104 "unknown state: {}", phase);
114 deltaGuess = rhoguess /
Rho_c;
117 if (delta_retn <= 0) {
122 doublereal density_retn;
123 if (delta_retn > 0.0) {
127 density_retn = delta_retn *
Rho_c;
139 int phase, doublereal rhoguess)
const
142 doublereal deltaGuess = 0.0;
143 doublereal deltaSave =
delta;
144 if (rhoguess == -1.0) {
149 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
151 }
else if (phase == WATER_LIQUID) {
155 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
157 "Unstable Branch finder is untested");
160 "unknown state: {}", phase);
170 deltaGuess = rhoguess /
Rho_c;
176 doublereal density_retn;
177 if (delta_retn > 0.0) {
181 density_retn = delta_retn *
Rho_c;
208 static const doublereal A[8] = {
220 doublereal pl = 6.3573118E0 - 8858.843E0 /
temperature
225 doublereal w = fabs(1.0-v);
227 for (
int i = 0; i < 8; i++) {
228 doublereal z = i + 1;
229 b += A[i] * pow(w, ((z+1.0)/2.0));
231 doublereal q = b / v;
242 doublereal dpdrho_val =
dpdrho();
244 return 1.0 / (dens * dpdrho_val);
275 doublereal& densLiq, doublereal& densGas, doublereal& delGRT)
278 if (densLiq <= 0.0) {
280 "Error occurred trying to find liquid density at (T,P) = {} {}",
287 if (densGas <= 0.0) {
289 "Error occurred trying to find gas density at (T,P) = {} {}",
295 delGRT = gibbsLiqRT - gibbsGasRT;
299 doublereal& densLiq, doublereal& densGas, doublereal& pcorr)
302 if (densLiq <= 0.0) {
304 "Error occurred trying to find liquid density at (T,P) = {} {}",
311 if (densGas <= 0.0) {
313 "Error occurred trying to find gas density at (T,P) = {} {}",
318 doublereal rhs = (prL - prG) + log(densLiq/densGas);
319 rhs /= (1.0/densGas - 1.0/densLiq);
325 static int method = 1;
326 doublereal densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
327 doublereal dp, pcorr;
334 for (
int i = 0; i < 30; i++) {
337 doublereal delV =
M_water * (1.0/densLiq - 1.0/densGas);
345 if ((method == 1) && delGRT < 1.0E-8) {
348 if (fabs(dp/p) < 1.0E-9) {
354 if (waterState == WATER_LIQUID) {
356 }
else if (waterState == WATER_GAS) {
360 "unknown water state input: {}", waterState);
374 doublereal rhoMid =
Rho_c + (T -
T_c) * (
Rho_c - rhoMidAtm) / (
T_c - 373.15);
375 int iStateGuess = WATER_LIQUID;
377 iStateGuess = WATER_GAS;
384 doublereal rhoDel = rho * 1.000001;
385 doublereal deltaSave =
delta;
386 doublereal deltaDel = rhoDel /
Rho_c;
391 doublereal d2rhodp2 = (rhoDel * kappaDel - rho * kappa) / (rhoDel - rho);
392 if (d2rhodp2 > 0.0) {
393 iState = WATER_UNSTABLELIQUID;
395 iState = WATER_UNSTABLEGAS;
408 doublereal delta_save =
delta;
416 doublereal rho_low = 0.0;
417 doublereal rho_high = 1000;
419 doublereal dens_old = densSatLiq;
422 doublereal dpdrho_old =
dpdrho();
423 if (dpdrho_old > 0.0) {
424 rho_high = std::min(dens_old, rho_high);
426 rho_low = std::max(rho_low, dens_old);
428 doublereal dens_new = densSatLiq* (1.0001);
431 doublereal dpdrho_new =
dpdrho();
432 if (dpdrho_new > 0.0) {
433 rho_high = std::min(dens_new, rho_high);
435 rho_low = std::max(rho_low, dens_new);
439 for (
int it = 0; it < 50; it++) {
440 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
442 slope = std::max(slope, dpdrho_new *5.0/ dens_new);
447 doublereal delta_rho = - dpdrho_new / slope;
448 if (delta_rho > 0.0) {
449 delta_rho = std::min(delta_rho, dens_new * 0.1);
451 delta_rho = std::max(delta_rho, - dens_new * 0.1);
453 doublereal dens_est = dens_new + delta_rho;
454 if (dens_est < rho_low) {
455 dens_est = 0.5 * (rho_low + dens_new);
457 if (dens_est > rho_high) {
458 dens_est = 0.5 * (rho_high + dens_new);
462 dpdrho_old = dpdrho_new;
468 if (dpdrho_new > 0.0) {
469 rho_high = std::min(dens_new, rho_high);
470 }
else if (dpdrho_new < 0.0) {
471 rho_low = std::max(rho_low, dens_new);
477 if (fabs(dpdrho_new) < 1.0E-5) {
484 throw CanteraError(
"WaterPropsIAPWS::densSpinodalWater",
485 "convergence failure");
496 doublereal delta_save =
delta;
504 doublereal rho_low = 0.0;
505 doublereal rho_high = 1000;
507 doublereal dens_old = densSatGas;
510 doublereal dpdrho_old =
dpdrho();
511 if (dpdrho_old < 0.0) {
512 rho_high = std::min(dens_old, rho_high);
514 rho_low = std::max(rho_low, dens_old);
516 doublereal dens_new = densSatGas * (0.99);
519 doublereal dpdrho_new =
dpdrho();
520 if (dpdrho_new < 0.0) {
521 rho_high = std::min(dens_new, rho_high);
523 rho_low = std::max(rho_low, dens_new);
526 for (
int it = 0; it < 50; it++) {
527 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
532 slope = std::min(slope, dpdrho_new *5.0 / dens_new);
535 doublereal delta_rho = - dpdrho_new / slope;
536 if (delta_rho > 0.0) {
537 delta_rho = std::min(delta_rho, dens_new * 0.1);
539 delta_rho = std::max(delta_rho, - dens_new * 0.1);
541 doublereal dens_est = dens_new + delta_rho;
542 if (dens_est < rho_low) {
543 dens_est = 0.5 * (rho_low + dens_new);
545 if (dens_est > rho_high) {
546 dens_est = 0.5 * (rho_high + dens_new);
550 dpdrho_old = dpdrho_new;
555 if (dpdrho_new < 0.0) {
556 rho_high = std::min(dens_new, rho_high);
557 }
else if (dpdrho_new > 0.0) {
558 rho_low = std::max(rho_low, dens_new);
564 if (fabs(dpdrho_new) < 1.0E-5) {
571 throw CanteraError(
"WaterPropsIAPWS::densSpinodalSteam",
572 "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.
void corr(doublereal temperature, doublereal pressure, doublereal &densLiq, doublereal &densGas, doublereal &delGRT)
Utility routine in the calculation of the saturation pressure.
void corr1(doublereal temperature, doublereal pressure, doublereal &densLiq, doublereal &densGas, doublereal &pcorr)
Utility routine in the calculation of the saturation pressure.
void calcDim(doublereal temperature, doublereal rho)
Calculate the dimensionless temp and rho and store internally.
doublereal coeffThermExp() const
Returns the coefficient of thermal expansion.
doublereal densSpinodalWater() const
Return the value of the density at the water spinodal point (on the liquid side) for the current temp...
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
doublereal tau
Dimensionless temperature, tau = T_C / T.
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density.
doublereal enthalpy() const
Calculate the enthalpy in mks units of J kmol-1 using the last temperature and density.
doublereal density_const(doublereal pressure, int phase=-1, doublereal rhoguess=-1.0) const
Calculates the density given the temperature and the pressure, and a guess at the density,...
doublereal coeffPresExp() const
Returns the isochoric pressure derivative wrt temperature.
WaterPropsIAPWS()
Base constructor.
doublereal densSpinodalSteam() const
Return the value of the density at the water spinodal point (on the gas side) for the current tempera...
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
doublereal molarVolume() const
Calculate the molar volume (kmol m-3) at the last temperature and density.
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
doublereal density() const
Returns the density (kg m-3)
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
int iState
Current state of the system.
doublereal temperature() const
Returns the temperature (Kelvin)
doublereal helmholtzFE() const
Calculate the Helmholtz free energy in mks units of J kmol-1 K-1, using the last temperature and dens...
doublereal psat_est(doublereal temperature) const
This function returns an estimated value for the saturation pressure.
doublereal delta
Dimensionless density, delta = rho / rho_c.
doublereal psat(doublereal temperature, int waterState=WATER_LIQUID)
This function returns the saturation pressure given the temperature as an input parameter,...
void setState_TR(doublereal temperature, doublereal rho)
Set the internal state of the object wrt temperature and density.
WaterPropsIAPWSphi m_phi
pointer to the underlying object that does the calculations.
doublereal dpdrho() const
Returns the value of dp / drho at constant T for the state of the object.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
doublereal isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
doublereal dimdpdrho(doublereal tau, doublereal delta)
Dimensionless derivative of p wrt rho at constant T.
doublereal entropy_R() const
Calculate the dimensionless entropy, s/R.
doublereal enthalpy_RT() const
Calculate the dimensionless enthalpy, h/RT.
doublereal gibbs_RT() const
Calculate the dimensionless Gibbs free energy.
doublereal cv_R() const
Calculate the dimensionless constant volume heat capacity, Cv/R.
doublereal dfind(doublereal p_red, doublereal tau, doublereal deltaGuess)
This function computes the reduced density, given the reduced pressure and the reduced temperature,...
doublereal cp_R() const
Calculate the dimensionless constant pressure heat capacity, Cv/R.
doublereal phi(doublereal tau, doublereal delta)
Calculate the Phi function, which is the base function.
doublereal intEnergy_RT() const
Calculate the dimensionless internal energy, u/RT.
doublereal dimdpdT(doublereal tau, doublereal delta)
Dimensionless derivative of p wrt T at constant rho.
void tdpolycalc(doublereal tau, doublereal delta)
Calculates internal polynomials in tau and delta.
doublereal pressureM_rhoRT(doublereal tau, doublereal delta)
Calculate the dimensionless pressure at tau and delta;.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
const double OneAtm
One atmosphere [Pa].
const doublereal Rho_c
Value of the Density at the critical point (kg m-3)
static const doublereal P_c
Critical Pressure (Pascals)
const doublereal T_c
Critical Temperature value (kelvin)
static const doublereal M_water
Molecular Weight of water that is consistent with the paper (kg kmol-1)
static const doublereal Rgas
Gas constant that is quoted in the paper.
Contains declarations for string manipulation functions within Cantera.