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;
53 WaterPropsIAPWS& WaterPropsIAPWS::operator=(
const WaterPropsIAPWS& b)
99 int phase, doublereal rhoguess)
101 doublereal deltaGuess = 0.0;
102 if (rhoguess == -1.0) {
107 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
109 }
else if (phase == WATER_LIQUID) {
113 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
115 "Unstable Branch finder is untested");
118 "unknown state: {}", phase);
128 deltaGuess = rhoguess /
Rho_c;
131 doublereal density_retn;
132 if (delta_retn >0.0) {
136 density_retn = delta_retn *
Rho_c;
148 int phase, doublereal rhoguess)
const 151 doublereal deltaGuess = 0.0;
152 doublereal deltaSave =
delta;
153 if (rhoguess == -1.0) {
158 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
160 }
else if (phase == WATER_LIQUID) {
164 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
166 "Unstable Branch finder is untested");
169 "unknown state: {}", phase);
179 deltaGuess = rhoguess /
Rho_c;
185 doublereal density_retn;
186 if (delta_retn > 0.0) {
190 density_retn = delta_retn *
Rho_c;
217 static const doublereal A[8] = {
229 doublereal pl = 6.3573118E0 - 8858.843E0 /
temperature 234 doublereal w = fabs(1.0-v);
236 for (
int i = 0; i < 8; i++) {
237 doublereal z = i + 1;
238 b += A[i] * pow(w, ((z+1.0)/2.0));
240 doublereal q = b / v;
251 doublereal dpdrho_val =
dpdrho();
253 return 1.0 / (dens * dpdrho_val);
284 doublereal& densLiq, doublereal& densGas, doublereal& delGRT)
287 if (densLiq <= 0.0) {
289 "Error occurred trying to find liquid density at (T,P) = {} {}",
296 if (densGas <= 0.0) {
298 "Error occurred trying to find gas density at (T,P) = {} {}",
304 delGRT = gibbsLiqRT - gibbsGasRT;
308 doublereal& densLiq, doublereal& densGas, doublereal& pcorr)
311 if (densLiq <= 0.0) {
313 "Error occurred trying to find liquid density at (T,P) = {} {}",
320 if (densGas <= 0.0) {
322 "Error occurred trying to find gas density at (T,P) = {} {}",
327 doublereal rhs = (prL - prG) + log(densLiq/densGas);
328 rhs /= (1.0/densGas - 1.0/densLiq);
334 static int method = 1;
335 doublereal densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
336 doublereal dp, pcorr;
343 for (
int i = 0; i < 30; i++) {
346 doublereal delV =
M_water * (1.0/densLiq - 1.0/densGas);
354 if ((method == 1) && delGRT < 1.0E-8) {
357 if (fabs(dp/p) < 1.0E-9) {
363 if (waterState == WATER_LIQUID) {
365 }
else if (waterState == WATER_GAS) {
369 "unknown water state input: {}", waterState);
383 doublereal rhoMid =
Rho_c + (T -
T_c) * (
Rho_c - rhoMidAtm) / (
T_c - 373.15);
384 int iStateGuess = WATER_LIQUID;
386 iStateGuess = WATER_GAS;
393 doublereal rhoDel = rho * 1.000001;
394 doublereal deltaSave =
delta;
395 doublereal deltaDel = rhoDel /
Rho_c;
400 doublereal d2rhodp2 = (rhoDel * kappaDel - rho * kappa) / (rhoDel - rho);
401 if (d2rhodp2 > 0.0) {
402 iState = WATER_UNSTABLELIQUID;
404 iState = WATER_UNSTABLEGAS;
417 doublereal delta_save =
delta;
425 doublereal rho_low = 0.0;
426 doublereal rho_high = 1000;
428 doublereal dens_old = densSatLiq;
431 doublereal dpdrho_old =
dpdrho();
432 if (dpdrho_old > 0.0) {
433 rho_high = std::min(dens_old, rho_high);
435 rho_low = std::max(rho_low, dens_old);
437 doublereal dens_new = densSatLiq* (1.0001);
440 doublereal dpdrho_new =
dpdrho();
441 if (dpdrho_new > 0.0) {
442 rho_high = std::min(dens_new, rho_high);
444 rho_low = std::max(rho_low, dens_new);
448 for (
int it = 0; it < 50; it++) {
449 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
451 slope = std::max(slope, dpdrho_new *5.0/ dens_new);
456 doublereal delta_rho = - dpdrho_new / slope;
457 if (delta_rho > 0.0) {
458 delta_rho = std::min(delta_rho, dens_new * 0.1);
460 delta_rho = std::max(delta_rho, - dens_new * 0.1);
462 doublereal dens_est = dens_new + delta_rho;
463 if (dens_est < rho_low) {
464 dens_est = 0.5 * (rho_low + dens_new);
466 if (dens_est > rho_high) {
467 dens_est = 0.5 * (rho_high + dens_new);
471 dpdrho_old = dpdrho_new;
477 if (dpdrho_new > 0.0) {
478 rho_high = std::min(dens_new, rho_high);
479 }
else if (dpdrho_new < 0.0) {
480 rho_low = std::max(rho_low, dens_new);
486 if (fabs(dpdrho_new) < 1.0E-5) {
493 throw CanteraError(
"WaterPropsIAPWS::densSpinodalWater()",
494 "convergence failure");
505 doublereal delta_save =
delta;
513 doublereal rho_low = 0.0;
514 doublereal rho_high = 1000;
516 doublereal dens_old = densSatGas;
519 doublereal dpdrho_old =
dpdrho();
520 if (dpdrho_old < 0.0) {
521 rho_high = std::min(dens_old, rho_high);
523 rho_low = std::max(rho_low, dens_old);
525 doublereal dens_new = densSatGas * (0.99);
528 doublereal dpdrho_new =
dpdrho();
529 if (dpdrho_new < 0.0) {
530 rho_high = std::min(dens_new, rho_high);
532 rho_low = std::max(rho_low, dens_new);
535 for (
int it = 0; it < 50; it++) {
536 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
541 slope = std::min(slope, dpdrho_new *5.0 / dens_new);
544 doublereal delta_rho = - dpdrho_new / slope;
545 if (delta_rho > 0.0) {
546 delta_rho = std::min(delta_rho, dens_new * 0.1);
548 delta_rho = std::max(delta_rho, - dens_new * 0.1);
550 doublereal dens_est = dens_new + delta_rho;
551 if (dens_est < rho_low) {
552 dens_est = 0.5 * (rho_low + dens_new);
554 if (dens_est > rho_high) {
555 dens_est = 0.5 * (rho_high + dens_new);
559 dpdrho_old = dpdrho_new;
564 if (dpdrho_new < 0.0) {
565 rho_high = std::min(dens_new, rho_high);
566 }
else if (dpdrho_new > 0.0) {
567 rho_low = std::max(rho_low, dens_new);
573 if (fabs(dpdrho_new) < 1.0E-5) {
580 throw CanteraError(
"WaterPropsIAPWS::densSpinodalSteam()",
581 "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.
Class for calculating the equation of state of water.
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...