diff --git a/Cantera/src/thermo/PDSS_Water.cpp b/Cantera/src/thermo/PDSS_Water.cpp index dca0edb76..60b1ce3d9 100644 --- a/Cantera/src/thermo/PDSS_Water.cpp +++ b/Cantera/src/thermo/PDSS_Water.cpp @@ -435,16 +435,22 @@ namespace Cantera { * \f] */ doublereal PDSS_Water::thermalExpansionCoeff() const { - doublereal pres = pressure(); - doublereal val = m_sub->coeffThermExp(m_temp, pres); + doublereal val = m_sub->coeffThermExp(); return val; } doublereal PDSS_Water::dthermalExpansionCoeffdT() const { doublereal pres = pressure(); + doublereal dens_save = m_dens; double tt = m_temp - 0.04; - doublereal vald = m_sub->coeffThermExp(tt, pres); - doublereal val2 = m_sub->coeffThermExp(m_temp, pres); + doublereal dd = m_sub->density(tt, pres, m_iState, m_dens); + if (dd < 0.0) { + throw CanteraError("PDSS_Water::dthermalExpansionCoeffdT", + "unable to solve for the density at T = " + fp2str(tt) + ", P = " + fp2str(pres)); + } + doublereal vald = m_sub->coeffThermExp(); + m_sub->setState_TR(m_temp, dens_save); + doublereal val2 = m_sub->coeffThermExp(); doublereal val = (val2 - vald) / 0.04; return val; } diff --git a/Cantera/src/thermo/WaterProps.cpp b/Cantera/src/thermo/WaterProps.cpp index 2eac58007..5099a467e 100644 --- a/Cantera/src/thermo/WaterProps.cpp +++ b/Cantera/src/thermo/WaterProps.cpp @@ -442,14 +442,21 @@ namespace Cantera { } double WaterProps::coeffThermalExp_IAPWS(double temp, double press) { - - double cte; - cte = m_waterIAPWS->coeffThermExp(temp, press); + double dens = m_waterIAPWS->density(temp, press, WATER_LIQUID); + if (dens < 0.0) { + throw CanteraError("WaterProps::coeffThermalExp_IAPWS", + "Unable to solve for density at T = " + fp2str(temp) + " and P = " + fp2str(press)); + } + double cte = m_waterIAPWS->coeffThermExp(); return cte; } double WaterProps::isothermalCompressibility_IAPWS(double temp, double press) { - m_waterIAPWS->density(temp, press, WATER_LIQUID); + double dens = m_waterIAPWS->density(temp, press, WATER_LIQUID); + if (dens < 0.0) { + throw CanteraError("WaterProps::isothermalCompressibility_IAPWS", + "Unable to solve for density at T = " + fp2str(temp) + " and P = " + fp2str(press)); + } double kappa = m_waterIAPWS->isothermalCompressibility(); return kappa; } diff --git a/Cantera/src/thermo/WaterPropsIAPWS.cpp b/Cantera/src/thermo/WaterPropsIAPWS.cpp index 03a16c036..dfe15bcc9 100644 --- a/Cantera/src/thermo/WaterPropsIAPWS.cpp +++ b/Cantera/src/thermo/WaterPropsIAPWS.cpp @@ -257,45 +257,6 @@ double WaterPropsIAPWS::psat_est(double temperature) { return ps; } -/* - * Returns the coefficient of thermal expansion as a function - * of temperature and pressure. - * alpha = d (ln V) / dT at constant P. - * - * Currently this function is calculated using a differencing scheme. - */ -double WaterPropsIAPWS::coeffThermExp(double temperature, double pressure) { - - double deltaT = 0.01; - double psat_at=0.0; - double rhoguess = -1; - int phase = -1; - if (temperature > T_c) { - rhoguess = pressure * M_water / (Rgas * temperature); - } else { - psat_at = psat(temperature); - if (pressure >= psat_at) { - phase = WATER_LIQUID; - deltaT = -0.01; - } else - phase = WATER_GAS; - } - - double dens_base = density(temperature, pressure, phase, rhoguess); - - if (dens_base == -1.0) { - printf("problems\n"); - exit(-1); - } - double temp_del = temperature + deltaT; - - double dens_del = density(temp_del, pressure, phase, dens_base); - - double Vavg = 0.5 * (1./dens_del + 1./dens_base); - double retn = 1.0 / Vavg * (1./dens_del - 1.0/dens_base)/deltaT; - return retn; -} - /* * Returns the coefficient of isothermal compressibility * of temperature and pressure. @@ -315,6 +276,13 @@ double WaterPropsIAPWS:: coeffPresExp() const { return (retn); } +double WaterPropsIAPWS:: coeffThermExp() const { + double kappa = isothermalCompressibility(); + double beta = coeffPresExp(); + double dens = delta * Rho_c; + return (kappa * dens * Rgas * beta / M_water); +} + /* * Calculate the Gibbs free energy in mks units of * J kmol-1 K-1. diff --git a/Cantera/src/thermo/WaterPropsIAPWS.h b/Cantera/src/thermo/WaterPropsIAPWS.h index 62bd6a85b..7c7f64119 100644 --- a/Cantera/src/thermo/WaterPropsIAPWS.h +++ b/Cantera/src/thermo/WaterPropsIAPWS.h @@ -307,7 +307,7 @@ public: */ double density() const; - //! Returns the coefficient of thermal expansion as a function of temperature and pressure. + //! Returns the coefficient of thermal expansion. /*! * alpha = d (ln V) / dT at constant P. * @@ -316,7 +316,7 @@ public: * @return * Returns the coefficient of thermal expansion */ - double coeffThermExp(double temperature, double pressure); + double coeffThermExp() const; //! Returns the isochoric pressure-temperature coefficient /*! diff --git a/Cantera/src/thermo/WaterSSTP.cpp b/Cantera/src/thermo/WaterSSTP.cpp index 41ca96a5e..bac7f80e8 100644 --- a/Cantera/src/thermo/WaterSSTP.cpp +++ b/Cantera/src/thermo/WaterSSTP.cpp @@ -508,18 +508,23 @@ namespace Cantera { * \f] */ doublereal WaterSSTP::thermalExpansionCoeff() const { - doublereal pres = pressure(); - double T = temperature(); - doublereal val = m_sub->coeffThermExp(T, pres); + doublereal val = m_sub->coeffThermExp(); return val; } doublereal WaterSSTP::dthermalExpansionCoeffdT() const { doublereal pres = pressure(); + doublereal dens_save = density(); double T = temperature(); double tt = T - 0.04; - doublereal vald = m_sub->coeffThermExp(tt, pres); - doublereal val2 = m_sub->coeffThermExp(T, pres); + doublereal dd = m_sub->density(tt, pres, WATER_LIQUID, dens_save); + if (dd < 0.0) { + throw CanteraError("WaterSSTP::dthermalExpansionCoeffdT", + "Unable to solve for the density at T = " + fp2str(tt) + ", P = " + fp2str(pres)); + } + doublereal vald = m_sub->coeffThermExp(); + m_sub->setState_TR(T, dens_save); + doublereal val2 = m_sub->coeffThermExp(); doublereal val = (val2 - vald) / 0.04; return val; }