20 const doublereal
T_c = 647.096;
22 static const doublereal
P_c = 22.064E6;
26 static const doublereal
M_water = 18.015268;
35 static const doublereal
Rgas = 8.314371E3;
79 int phase, doublereal rhoguess)
81 doublereal deltaGuess = 0.0;
82 if (rhoguess == -1.0) {
87 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
89 }
else if (phase == WATER_LIQUID) {
93 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
95 "Unstable Branch finder is untested");
98 "unknown state: {}", phase);
108 deltaGuess = rhoguess /
Rho_c;
111 doublereal density_retn;
112 if (delta_retn >0.0) {
116 density_retn = delta_retn *
Rho_c;
128 int phase, doublereal rhoguess)
const 131 doublereal deltaGuess = 0.0;
132 doublereal deltaSave =
delta;
133 if (rhoguess == -1.0) {
138 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
140 }
else if (phase == WATER_LIQUID) {
144 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
146 "Unstable Branch finder is untested");
149 "unknown state: {}", phase);
159 deltaGuess = rhoguess /
Rho_c;
165 doublereal density_retn;
166 if (delta_retn > 0.0) {
170 density_retn = delta_retn *
Rho_c;
197 static const doublereal A[8] = {
209 doublereal pl = 6.3573118E0 - 8858.843E0 /
temperature 214 doublereal w = fabs(1.0-v);
216 for (
int i = 0; i < 8; i++) {
217 doublereal z = i + 1;
218 b += A[i] * pow(w, ((z+1.0)/2.0));
220 doublereal q = b / v;
231 doublereal dpdrho_val =
dpdrho();
233 return 1.0 / (dens * dpdrho_val);
264 doublereal& densLiq, doublereal& densGas, doublereal& delGRT)
267 if (densLiq <= 0.0) {
269 "Error occurred trying to find liquid density at (T,P) = {} {}",
276 if (densGas <= 0.0) {
278 "Error occurred trying to find gas density at (T,P) = {} {}",
284 delGRT = gibbsLiqRT - gibbsGasRT;
288 doublereal& densLiq, doublereal& densGas, doublereal& pcorr)
291 if (densLiq <= 0.0) {
293 "Error occurred trying to find liquid density at (T,P) = {} {}",
300 if (densGas <= 0.0) {
302 "Error occurred trying to find gas density at (T,P) = {} {}",
307 doublereal rhs = (prL - prG) + log(densLiq/densGas);
308 rhs /= (1.0/densGas - 1.0/densLiq);
314 static int method = 1;
315 doublereal densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
316 doublereal dp, pcorr;
323 for (
int i = 0; i < 30; i++) {
326 doublereal delV =
M_water * (1.0/densLiq - 1.0/densGas);
334 if ((method == 1) && delGRT < 1.0E-8) {
337 if (fabs(dp/p) < 1.0E-9) {
343 if (waterState == WATER_LIQUID) {
345 }
else if (waterState == WATER_GAS) {
349 "unknown water state input: {}", waterState);
363 doublereal rhoMid =
Rho_c + (T -
T_c) * (
Rho_c - rhoMidAtm) / (
T_c - 373.15);
364 int iStateGuess = WATER_LIQUID;
366 iStateGuess = WATER_GAS;
373 doublereal rhoDel = rho * 1.000001;
374 doublereal deltaSave =
delta;
375 doublereal deltaDel = rhoDel /
Rho_c;
380 doublereal d2rhodp2 = (rhoDel * kappaDel - rho * kappa) / (rhoDel - rho);
381 if (d2rhodp2 > 0.0) {
382 iState = WATER_UNSTABLELIQUID;
384 iState = WATER_UNSTABLEGAS;
397 doublereal delta_save =
delta;
405 doublereal rho_low = 0.0;
406 doublereal rho_high = 1000;
408 doublereal dens_old = densSatLiq;
411 doublereal dpdrho_old =
dpdrho();
412 if (dpdrho_old > 0.0) {
413 rho_high = std::min(dens_old, rho_high);
415 rho_low = std::max(rho_low, dens_old);
417 doublereal dens_new = densSatLiq* (1.0001);
420 doublereal dpdrho_new =
dpdrho();
421 if (dpdrho_new > 0.0) {
422 rho_high = std::min(dens_new, rho_high);
424 rho_low = std::max(rho_low, dens_new);
428 for (
int it = 0; it < 50; it++) {
429 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
431 slope = std::max(slope, dpdrho_new *5.0/ dens_new);
436 doublereal delta_rho = - dpdrho_new / slope;
437 if (delta_rho > 0.0) {
438 delta_rho = std::min(delta_rho, dens_new * 0.1);
440 delta_rho = std::max(delta_rho, - dens_new * 0.1);
442 doublereal dens_est = dens_new + delta_rho;
443 if (dens_est < rho_low) {
444 dens_est = 0.5 * (rho_low + dens_new);
446 if (dens_est > rho_high) {
447 dens_est = 0.5 * (rho_high + dens_new);
451 dpdrho_old = dpdrho_new;
457 if (dpdrho_new > 0.0) {
458 rho_high = std::min(dens_new, rho_high);
459 }
else if (dpdrho_new < 0.0) {
460 rho_low = std::max(rho_low, dens_new);
466 if (fabs(dpdrho_new) < 1.0E-5) {
473 throw CanteraError(
"WaterPropsIAPWS::densSpinodalWater()",
474 "convergence failure");
485 doublereal delta_save =
delta;
493 doublereal rho_low = 0.0;
494 doublereal rho_high = 1000;
496 doublereal dens_old = densSatGas;
499 doublereal dpdrho_old =
dpdrho();
500 if (dpdrho_old < 0.0) {
501 rho_high = std::min(dens_old, rho_high);
503 rho_low = std::max(rho_low, dens_old);
505 doublereal dens_new = densSatGas * (0.99);
508 doublereal dpdrho_new =
dpdrho();
509 if (dpdrho_new < 0.0) {
510 rho_high = std::min(dens_new, rho_high);
512 rho_low = std::max(rho_low, dens_new);
515 for (
int it = 0; it < 50; it++) {
516 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
521 slope = std::min(slope, dpdrho_new *5.0 / dens_new);
524 doublereal delta_rho = - dpdrho_new / slope;
525 if (delta_rho > 0.0) {
526 delta_rho = std::min(delta_rho, dens_new * 0.1);
528 delta_rho = std::max(delta_rho, - dens_new * 0.1);
530 doublereal dens_est = dens_new + delta_rho;
531 if (dens_est < rho_low) {
532 dens_est = 0.5 * (rho_low + dens_new);
534 if (dens_est > rho_high) {
535 dens_est = 0.5 * (rho_high + dens_new);
539 dpdrho_old = dpdrho_new;
544 if (dpdrho_new < 0.0) {
545 rho_high = std::min(dens_new, rho_high);
546 }
else if (dpdrho_new > 0.0) {
547 rho_low = std::max(rho_low, dens_new);
553 if (fabs(dpdrho_new) < 1.0E-5) {
560 throw CanteraError(
"WaterPropsIAPWS::densSpinodalSteam()",
561 "convergence failure");
doublereal psat_est(doublereal temperature) const
This function returns an estimated value for the saturation pressure.
doublereal dpdrho() const
Returns the value of dp / drho at constant T for the state of the object.
doublereal densSpinodalSteam() const
Return the value of the density at the water spinodal point (on the gas side) for the current tempera...
doublereal delta
Dimensionless density, delta = rho / rho_c.
const doublereal OneAtm
One atmosphere [Pa].
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...
void setState_TR(doublereal temperature, doublereal rho)
Set the internal state of the object wrt temperature and density.
doublereal intEnergy() const
Calculate the internal energy in mks units of J kmol-1.
doublereal entropy() const
Calculate the entropy in mks units of J kmol-1 K-1.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
WaterPropsIAPWS()
Base constructor.
const doublereal Rho_c
Value of the Density at the critical point (kg m-3)
doublereal molarVolume() const
Calculate the molar volume (kmol m-3) at the last temperature and density.
void corr(doublereal temperature, doublereal pressure, doublereal &densLiq, doublereal &densGas, doublereal &delGRT)
Utility routine in the calculation of the saturation pressure.
static const doublereal P_c
Critical Pressure (Pascals)
doublereal dfind(doublereal p_red, doublereal tau, doublereal deltaGuess)
This function computes the reduced density, given the reduced pressure and the reduced temperature...
doublereal gibbs_RT() const
Calculate the dimensionless Gibbs free energy.
doublereal temperature() const
Returns the temperature (Kelvin)
doublereal pressure() const
Calculates the pressure (Pascals), given the current value of the temperature and density...
void calcDim(doublereal temperature, doublereal rho)
Calculate the dimensionless temp and rho and store internally.
doublereal cp() const
Calculate the constant pressure heat capacity in mks units of J kmol-1 K-1 at the last temperature an...
doublereal pressureM_rhoRT(doublereal tau, doublereal delta)
Calculate the dimensionless pressure at tau and delta;.
doublereal density() const
Returns the density (kg m-3)
int iState
Current state of the system.
doublereal cp_R() const
Calculate the dimensionless constant pressure heat capacity, Cv/R.
doublereal isothermalCompressibility() const
Returns the coefficient of isothermal compressibility for the state of the object.
const doublereal T_c
Critical Temperature value (kelvin)
doublereal dimdpdrho(doublereal tau, doublereal delta)
Dimensionless derivative of p wrt rho at constant T.
doublereal dimdpdT(doublereal tau, doublereal delta)
Dimensionless derivative of p wrt T at constant rho.
doublereal helmholtzFE() const
Calculate the Helmholtz free energy in mks units of J kmol-1 K-1, using the last temperature and dens...
static const doublereal Rgas
Gas constant that is quoted in the paper.
doublereal cv_R() const
Calculate the dimensionless constant volume heat capacity, Cv/R.
void tdpolycalc(doublereal tau, doublereal delta)
Calculates internal polynomials in tau and delta.
Base class for exceptions thrown by Cantera classes.
doublereal tau
Dimensionless temperature, tau = T_C / T.
doublereal coeffThermExp() const
Returns the coefficient of thermal expansion.
doublereal coeffPresExp() const
Returns the isochoric pressure derivative wrt temperature.
doublereal intEnergy_RT() const
Calculate the dimensionless internal energy, u/RT.
void corr1(doublereal temperature, doublereal pressure, doublereal &densLiq, doublereal &densGas, doublereal &pcorr)
Utility routine in the calculation of the saturation pressure.
WaterPropsIAPWSphi m_phi
pointer to the underlying object that does the calculations.
static const doublereal M_water
Molecular Weight of water that is consistent with the paper (kg kmol-1)
Contains declarations for string manipulation functions within Cantera.
doublereal Gibbs() const
Calculate the Gibbs free energy in mks units of J kmol-1 K-1.
doublereal densSpinodalWater() const
Return the value of the density at the water spinodal point (on the liquid side) for the current temp...
doublereal cv() const
Calculate the constant volume heat capacity in mks units of J kmol-1 K-1 at the last temperature and ...
doublereal phi(doublereal tau, doublereal delta)
Calculate the Phi function, which is the base function.
Namespace for the Cantera kernel.
doublereal entropy_R() const
Calculate the dimensionless entropy, s/R.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
doublereal psat(doublereal temperature, int waterState=WATER_LIQUID)
This function returns the saturation pressure given the temperature as an input parameter, and sets the internal state to the saturated conditions.
doublereal enthalpy_RT() const
Calculate the dimensionless enthalpy, h/RT.
Headers for a class for calculating the equation of state of water from the IAPWS 1995 Formulation ba...