25 const doublereal
T_c = 647.096;
27 static const doublereal
P_c = 22.064E6;
31 static const doublereal
M_water = 18.015268;
40 static const doublereal
Rgas = 8.314371E3;
104 if (temperature >
T_c) {
155 int phase, doublereal rhoguess)
158 doublereal deltaGuess = 0.0;
159 if (rhoguess == -1.0) {
161 if (temperature >
T_c) {
164 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
166 }
else if (phase == WATER_LIQUID) {
172 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
174 "Unstable Branch finder is untested");
190 deltaGuess = rhoguess /
Rho_c;
192 doublereal delta_retn =
m_phi->
dfind(p_red,
tau, deltaGuess);
193 doublereal density_retn;
194 if (delta_retn >0.0) {
200 density_retn = delta_retn *
Rho_c;
241 int phase, doublereal rhoguess)
const
244 doublereal deltaGuess = 0.0;
245 doublereal deltaSave =
delta;
246 if (rhoguess == -1.0) {
248 if (temperature >
T_c) {
251 if (phase == WATER_GAS || phase == WATER_SUPERCRIT) {
253 }
else if (phase == WATER_LIQUID) {
259 }
else if (phase == WATER_UNSTABLELIQUID || phase == WATER_UNSTABLEGAS) {
261 "Unstable Branch finder is untested");
277 deltaGuess = rhoguess /
Rho_c;
283 doublereal delta_retn =
m_phi->
dfind(p_red,
tau, deltaGuess);
284 doublereal density_retn;
285 if (delta_retn > 0.0) {
291 density_retn = delta_retn *
Rho_c;
336 static const doublereal A[8] = {
347 if (temperature < 314.) {
348 doublereal pl = 6.3573118E0 - 8858.843E0 / temperature
349 + 607.56335E0 * pow(temperature, -0.6);
352 doublereal v = temperature / 647.25;
353 doublereal w = fabs(1.0-v);
355 for (
int i = 0; i < 8; i++) {
356 doublereal z = i + 1;
357 b += A[i] * pow(w, ((z+1.0)/2.0));
359 doublereal q = b / v;
376 doublereal dpdrho_val =
dpdrho();
378 return (1.0 / (dens * dpdrho_val));
392 doublereal val = retn *
Rgas * temperature /
M_water;
431 return (gRT *
Rgas * temperature);
449 corr(doublereal temperature, doublereal pressure, doublereal& densLiq,
450 doublereal& densGas, doublereal& delGRT)
453 densLiq =
density(temperature, pressure, WATER_LIQUID, densLiq);
454 if (densLiq <= 0.0) {
456 "Error occurred trying to find liquid density at (T,P) = "
462 densGas =
density(temperature, pressure, WATER_GAS, densGas);
463 if (densGas <= 0.0) {
465 "Error occurred trying to find gas density at (T,P) = "
471 delGRT = gibbsLiqRT - gibbsGasRT;
485 corr1(doublereal temperature, doublereal pressure, doublereal& densLiq,
486 doublereal& densGas, doublereal& pcorr)
489 densLiq =
density(temperature, pressure, WATER_LIQUID, densLiq);
490 if (densLiq <= 0.0) {
492 "Error occurred trying to find liquid density at (T,P) = "
498 densGas =
density(temperature, pressure, WATER_GAS, densGas);
499 if (densGas <= 0.0) {
501 "Error occurred trying to find gas density at (T,P) = "
507 doublereal rhs = (prL - prG) + log(densLiq/densGas);
508 rhs /= (1.0/densGas - 1.0/densLiq);
534 static int method = 1;
535 doublereal densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
536 doublereal dp, pcorr;
537 if (temperature >=
T_c) {
538 densGas =
density(temperature,
P_c, WATER_SUPERCRIT);
542 doublereal p =
psat_est(temperature);
543 for (
int i = 0; i < 30; i++) {
545 corr(temperature, p, densLiq, densGas, delGRT);
546 doublereal delV =
M_water * (1.0/densLiq - 1.0/densGas);
547 dp = - delGRT *
Rgas * temperature / delV;
549 corr1(temperature, p, densLiq, densGas, pcorr);
554 if ((method == 1) && delGRT < 1.0E-8) {
557 if (fabs(dp/p) < 1.0E-9) {
563 if (waterState == WATER_LIQUID) {
565 }
else if (waterState == WATER_GAS) {
594 doublereal rhoMid = Rho_c + (T -
T_c) * (Rho_c - rhoMidAtm) / (
T_c - 373.15);
595 int iStateGuess = WATER_LIQUID;
597 iStateGuess = WATER_GAS;
604 doublereal rhoDel = rho * 1.000001;
607 doublereal deltaSave =
delta;
608 doublereal deltaDel = rhoDel /
Rho_c;
613 doublereal d2rhodp2 = (rhoDel * kappaDel - rho * kappa) / (rhoDel - rho);
614 if (d2rhodp2 > 0.0) {
615 iState = WATER_UNSTABLELIQUID;
617 iState = WATER_UNSTABLEGAS;
637 doublereal delta_save =
delta;
641 if (temperature >=
T_c - 0.001) {
644 doublereal p =
psat_est(temperature);
645 doublereal rho_low = 0.0;
646 doublereal rho_high = 1000;
649 doublereal dens_old = densSatLiq;
652 doublereal dpdrho_old =
dpdrho();
653 if (dpdrho_old > 0.0) {
654 rho_high =
std::min(dens_old, rho_high);
656 rho_low =
std::max(rho_low, dens_old);
658 doublereal dens_new = densSatLiq* (1.0001);
661 doublereal dpdrho_new =
dpdrho();
662 if (dpdrho_new > 0.0) {
663 rho_high =
std::min(dens_new, rho_high);
665 rho_low =
std::max(rho_low, dens_new);
669 for (
int it = 0; it < 50; it++) {
670 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
672 slope =
std::max(slope, dpdrho_new *5.0/ dens_new);
678 doublereal delta_rho = - dpdrho_new / slope;
679 if (delta_rho > 0.0) {
680 delta_rho =
std::min(delta_rho, dens_new * 0.1);
682 delta_rho =
std::max(delta_rho, - dens_new * 0.1);
684 doublereal dens_est = dens_new + delta_rho;
685 if (dens_est < rho_low) {
686 dens_est = 0.5 * (rho_low + dens_new);
688 if (dens_est > rho_high) {
689 dens_est = 0.5 * (rho_high + dens_new);
694 dpdrho_old = dpdrho_new;
700 if (dpdrho_new > 0.0) {
701 rho_high =
std::min(dens_new, rho_high);
702 }
else if (dpdrho_new < 0.0) {
703 rho_low =
std::max(rho_low, dens_new);
709 if (fabs(dpdrho_new) < 1.0E-5) {
717 " convergence failure");
734 doublereal delta_save =
delta;
738 if (temperature >=
T_c - 0.001) {
741 doublereal p =
psat_est(temperature);
742 doublereal rho_low = 0.0;
743 doublereal rho_high = 1000;
746 doublereal dens_old = densSatGas;
749 doublereal dpdrho_old =
dpdrho();
750 if (dpdrho_old < 0.0) {
751 rho_high =
std::min(dens_old, rho_high);
753 rho_low =
std::max(rho_low, dens_old);
755 doublereal dens_new = densSatGas * (0.99);
758 doublereal dpdrho_new =
dpdrho();
759 if (dpdrho_new < 0.0) {
760 rho_high =
std::min(dens_new, rho_high);
762 rho_low =
std::max(rho_low, dens_new);
766 for (
int it = 0; it < 50; it++) {
767 doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
774 slope =
std::min(slope, dpdrho_new *5.0 / dens_new);
777 doublereal delta_rho = - dpdrho_new / slope;
778 if (delta_rho > 0.0) {
779 delta_rho =
std::min(delta_rho, dens_new * 0.1);
781 delta_rho =
std::max(delta_rho, - dens_new * 0.1);
783 doublereal dens_est = dens_new + delta_rho;
784 if (dens_est < rho_low) {
785 dens_est = 0.5 * (rho_low + dens_new);
787 if (dens_est > rho_high) {
788 dens_est = 0.5 * (rho_high + dens_new);
793 dpdrho_old = dpdrho_new;
799 if (dpdrho_new < 0.0) {
800 rho_high =
std::min(dens_new, rho_high);
801 }
else if (dpdrho_new > 0.0) {
802 rho_low =
std::max(rho_low, dens_new);
808 if (fabs(dpdrho_new) < 1.0E-5) {
816 " convergence failure");
843 return (hRT *
Rgas * temperature);
854 return (uRT *
Rgas * temperature);