From 296e2912e5aa9ab98e99e83a3901e61854598cb0 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Sat, 29 Jun 2019 13:14:12 -0400 Subject: [PATCH] [Test] Update to not use deprecated PureFluid.h Update test_problems for rankine and pureFluid to avoid using the deprecated PureFluid.h convenience wrapper classes. Update the rankine.cpp test problem to match the rankine.cpp sample. Switch both test_problems updated here to use writelog instead of printf/cout. --- test_problems/pureFluidTest/testPureWater.cpp | 64 +++++++++---------- .../rankine_democxx/output_blessed.txt | 12 ++-- test_problems/rankine_democxx/rankine.cpp | 41 ++++++------ 3 files changed, 54 insertions(+), 63 deletions(-) diff --git a/test_problems/pureFluidTest/testPureWater.cpp b/test_problems/pureFluidTest/testPureWater.cpp index 95c38d094..e255e5d1e 100644 --- a/test_problems/pureFluidTest/testPureWater.cpp +++ b/test_problems/pureFluidTest/testPureWater.cpp @@ -1,4 +1,4 @@ -#include "cantera/PureFluid.h" +#include "cantera/thermo/PureFluidPhase.h" #include "cantera/thermo.h" #include @@ -24,32 +24,29 @@ int main() double pres; try { - XML_Node* xc = get_XML_File("liquidvapor.xml"); - XML_Node* const xs = xc->findNameID("phase", "water"); - ThermoPhase* water_tp = newPhase(*xs); - PureFluidPhase* w = dynamic_cast (water_tp); + unique_ptr w(newPhase("liquidvapor.yaml", "water")); /* * Print out the triple point conditions */ double temp = 273.16; pres = w->satPressure(temp); - printf("psat(%g) = %.4g\n", temp, pres); + writelog("psat({:g}) = {:.4g}\n", temp, pres); double presLow = 1.0E-2; temp = 298.15; double oneBar = 1.0E5; - printf("Comparisons to NIST: (see http://webbook.nist.gov):\n\n"); + writelog("Comparisons to NIST: (see http://webbook.nist.gov):\n\n"); w->setDensity(1.0E-8); w->setState_TP(temp, presLow); double h = w->enthalpy_mole(); - printf("H0(298.15) = %g J/kmol\n", h); + writelog("H0(298.15) = {:g} J/kmol\n", h); double h298 = h; double s = w->entropy_mole(); s -= GasConstant * log(oneBar/presLow); - printf("S0(298.15) = %g J/kmolK\n", s); + writelog("S0(298.15) = {:g} J/kmolK\n", s); double T[20]; @@ -60,10 +57,10 @@ int main() double Cp0, delh0, delg0, g; - printf("\nIdeal Gas Standard State:\n"); - printf(" T Cp0 S0 " + writelog("\nIdeal Gas Standard State:\n"); + writelog(" T Cp0 S0 " " -(G0-H298)/T H0-H298\n"); - printf(" (K) (J/molK) (J/molK) " + writelog(" (K) (J/molK) (J/molK) " " (J/molK) (kJ/mol)\n"); for (int i = 0; i < 4; i++) { temp = T[i]; @@ -75,19 +72,19 @@ int main() Cp0 = w->cp_mole(); s = w->entropy_mole(); s -= GasConstant * log(oneBar/presLow); - printf("%10g %10g %13.4g %13.4g %13.4g\n", temp, Cp0*1.0E-3, s*1.0E-3, + writelog("{:10g} {:10g} {:13.4g} {:13.4g} {:13.4g}\n", temp, Cp0*1.0E-3, s*1.0E-3, -delg0*1.0E-3, delh0*1.0E-6); } - printf("\n\n"); + writelog("\n\n"); temp = 298.15; w->setDensity(1000.); w->setState_TP(temp, oneBar); h = w->enthalpy_mole(); - printf("H_liq(298.15, onebar) = %g J/kmol\n", h); + writelog("H_liq(298.15, onebar) = {:g} J/kmol\n", h); double h298l = h; s = w->entropy_mole(); - printf("S_liq(298.15, onebar) = %g J/kmolK\n", s); + writelog("S_liq(298.15, onebar) = {:g} J/kmolK\n", s); T[0] = 273.19; @@ -96,10 +93,10 @@ int main() T[3] = 373.15; T[4] = 400.; T[5] = 500.; - printf("\nLiquid 1bar or psat Standard State\n"); - printf(" T press psat Cp0 S0 " + writelog("\nLiquid 1bar or psat Standard State\n"); + writelog(" T press psat Cp0 S0 " " -(G0-H298)/T H0-H298\n"); - printf(" (K) (bar) (bar) (J/molK) (J/molK)" + writelog(" (K) (bar) (bar) (J/molK) (J/molK)" " (J/molK) (kJ/mol)\n"); for (int i = 0; i < 6; i++) { @@ -116,16 +113,16 @@ int main() delg0 = (g - h298l)/temp; Cp0 = w->cp_mole(); s = w->entropy_mole(); - printf("%10g %10g %12g %13.4g %13.4g %13.4g %13.4g\n", temp, press*1.0E-5, + writelog("{:10g} {:10g} {:12g} {:13.4g} {:13.4g} {:13.4g} {:13.4g}\n", temp, press*1.0E-5, psat*1.0E-5, Cp0*1.0E-3, s*1.0E-3, -delg0*1.0E-3, delh0*1.0E-6); } - printf("\nLiquid Densities:\n"); - printf(" T press psat Density molarVol " + writelog("\nLiquid Densities:\n"); + writelog(" T press psat Density molarVol " "\n"); - printf(" (K) (bar) (bar) (kg/m3) (m3/kmol)" + writelog(" (K) (bar) (bar) (kg/m3) (m3/kmol)" "\n"); for (int i = 0; i < 6; i++) { temp = T[i]; @@ -138,14 +135,14 @@ int main() double d = w->density(); double mw = w->molecularWeight(0); double vbar = mw/d; - printf("%10g %10g %12g %13.4g %13.4g\n", temp, press*1.0E-5, + writelog("{:10g} {:10g} {:12g} {:13.4g} {:13.4g}\n", temp, press*1.0E-5, psat*1.0E-5, d, vbar); } - printf("\n\nTable of increasing Enthalpy at 1 atm\n\n"); + writelog("\n\nTable of increasing Enthalpy at 1 atm\n\n"); double dens; - printf(" Enthalpy, Temperature, x_Vapor, Density, Entropy_mass, Gibbs_mass\n"); + writelog(" Enthalpy, Temperature, x_Vapor, Density, Entropy_mass, Gibbs_mass\n"); w->setState_TP(298., OneAtm); double Hset = w->enthalpy_mass(); double vapFrac = w->vaporFraction(); @@ -153,14 +150,14 @@ int main() double Scalc = w->entropy_mass(); double Gcalc = w->gibbs_mass(); dens = w->density(); - printf(" %10g, %10g, %10g, %11.5g, %11.5g, %11.5g\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc); + writelog(" {:10g}, {:10g}, {:10g}, {:11.5g}, {:11.5g}, {:11.5g}\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc); w->setState_HP(Hset, OneAtm); vapFrac = w->vaporFraction(); Tcalc = w->temperature(); dens = w->density(); Scalc = w->entropy_mass(); Gcalc = w->gibbs_mass(); - printf(" %10g, %10g, %10g, %11.5g, %11.5g, %11.5g\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc); + writelog(" {:10g}, {:10g}, {:10g}, {:11.5g}, {:11.5g}, {:11.5g}\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc); double deltaH = 100000.; for (int i = 0; i < 40; i++) { @@ -171,17 +168,16 @@ int main() dens = w->density(); Scalc = w->entropy_mass(); Gcalc = w->gibbs_mass(); - printf(" %10g, %10g, %10g, %11.5g, %11.5g, %11.5g\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc); + writelog(" {:10g}, {:10g}, {:10g}, {:11.5g}, {:11.5g}, {:11.5g}\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc); } - printf("Critical Temp = %10.3g K\n", w->critTemperature()); - printf("Critical Pressure = %10.3g atm\n", w->critPressure()/OneAtm); - printf("Critical Dens = %10.3g kg/m3\n", w->critDensity()); + writelog("Critical Temp = {:10.3g} K\n", w->critTemperature()); + writelog("Critical Pressure = {:10.3g} atm\n", w->critPressure()/OneAtm); + writelog("Critical Dens = {:10.3g} kg/m3\n", w->critDensity()); - delete w; } catch (CanteraError& err) { - std::cout << err.what() << std::endl; + writelog(err.what()); Cantera::appdelete(); return -1; } diff --git a/test_problems/rankine_democxx/output_blessed.txt b/test_problems/rankine_democxx/output_blessed.txt index 05a5f0f18..10c3ada83 100644 --- a/test_problems/rankine_democxx/output_blessed.txt +++ b/test_problems/rankine_democxx/output_blessed.txt @@ -1,7 +1,7 @@ - 1 300 101325 -1.58581e+07 3913.2 0 - 2s 300.014 800000 -1.58574e+07 3913.2 0 - 2 300.126 800000 -1.58569e+07 3914.73 0 - 3 443.624 800000 -1.32016e+07 10183 1 - 4s 373.177 101325 -1.3553e+07 10183 0.89 - 4 373.177 101325 -1.34827e+07 10371.3 0.92 + 1 300 101325 -1.58581e+07 3913.17 0 + 2s 300.014 800000 -1.58574e+07 3913.17 0 + 2 300.126 800000 -1.58569e+07 3914.73 0 + 3 443.624 800000 -1.32016e+07 10182.9 1 + 4s 373.177 101325 -1.3553e+07 10182.9 0.89 + 4 373.177 101325 -1.34827e+07 10371.3 0.92 efficiency = 0.105873 diff --git a/test_problems/rankine_democxx/rankine.cpp b/test_problems/rankine_democxx/rankine.cpp index a47bd5fbd..f019c3c8a 100644 --- a/test_problems/rankine_democxx/rankine.cpp +++ b/test_problems/rankine_democxx/rankine.cpp @@ -1,20 +1,14 @@ // An open Rankine cycle -#include "cantera/PureFluid.h" // defines class Water -#include +#include "cantera/thermo/PureFluidPhase.h" using namespace Cantera; -using namespace std; -map h; -map s; -map T; -map P; -map x; -vector states; +std::map h, s, T, P, x; +std::vector states; template -void saveState(F& fluid, string name) +void saveState(F& fluid, std::string name) { h[name] = fluid.enthalpy_mass(); s[name] = fluid.entropy_mass(); @@ -26,21 +20,22 @@ void saveState(F& fluid, string name) void printStates() { - size_t nStates = states.size(); - for (size_t n = 0; n < nStates; n++) { - string name = states[n]; - printf(" %5s %10.6g %10.6g %12.6g %12.6g %5.2g \n", - name.c_str(), T[name], P[name], h[name], s[name], x[name]); + int nStates = states.size(); + for (int n = 0; n < nStates; n++) { + std::string name = states[n]; + writelog(" {:5s} {:10.6g} {:10.6g} {:12.6g} {:12.6g} {:5.2g}\n", + name, T[name], P[name], h[name], s[name], x[name]); } } -int openRankine(int np, void* p) +int openRankine() { - double etap = 0.6; // pump isentropic efficiency - double etat = 0.8; // turbine isentropic efficiency - double phigh = 8.0e5; // high pressure + double etap = 0.6; // pump isentropic efficiency + double etat = 0.8; // turbine isentropic efficiency + double phigh = 8.0e5; // high pressure - Water w; + PureFluidPhase w; + w.initThermoFile("liquidvapor.yaml", "water"); // begin with water at 300 K, 1 atm w.setState_TP(300.0, OneAtm); @@ -70,7 +65,7 @@ int openRankine(int np, void* p) double heat_in = h["3"] - h["2"]; double efficiency = work/heat_in; - cout << "efficiency = " << efficiency << endl; + writelog("efficiency = {:8.6g}", efficiency); return 0; } @@ -80,9 +75,9 @@ int main() _set_output_format(_TWO_DIGIT_EXPONENT); #endif try { - return openRankine(0, 0); + return openRankine(); } catch (CanteraError& err) { - std::cout << err.what() << std::endl; + writelog(err.what()); return -1; } }