diff --git a/test/data/simplephases.cti b/test/data/simplephases.cti new file mode 100644 index 000000000..2289cdb25 --- /dev/null +++ b/test/data/simplephases.cti @@ -0,0 +1,36 @@ +units(length="m", time="s", quantity="mol", energy="J") + +ideal_gas(name="simple1", + elements = "H O C", + species = " O2 H2 H2O ") + +ideal_gas(name="nasa1", + elements = "H O C", + species = "gri30: O2 H2 H2O ") + +ideal_gas(name="shomate1", + elements = "H O C", + species = "CO CO2") + +species(name="O2", atoms="O:2", + thermo=const_cp(h0=0.0, s0=205.152, cp0=29.39)) +species(name="H2", atoms="H:2", + thermo=const_cp(h0=0.0, s0=130.680, cp0=28.85)) +species(name="H2O", atoms="H:2 O:1", + thermo=const_cp(h0=-241826.0, s0=188.84, cp0=35.22)) + +species(name="CO", atoms="C:1 O:1", + thermo=(Shomate([298, 1300], + [25.56759, 6.096130, 4.054656, -2.671301, + 0.131021, -118.0089, 227.3665]), + Shomate([1300, 6000], + [35.15070, 1.300095, -0.205921, 0.013550, + -3.282780, -127.8375, 231.7120]))) + +species(name="CO2", atoms="C:1 O:2", + thermo=(Shomate([298, 1200], + [24.99735, 55.18696, -33.69137, 7.948387, + -0.136638, -403.6075, 228.2431]), + Shomate([1200, 6000], + [58.16639, 2.720074,-0.492289, 0.038844, + -6.447293,-425.9186, 263.6125]))) diff --git a/test/thermo/thermoParameterizations.cpp b/test/thermo/thermoParameterizations.cpp new file mode 100644 index 000000000..b10e2a77f --- /dev/null +++ b/test/thermo/thermoParameterizations.cpp @@ -0,0 +1,127 @@ +#include "gtest/gtest.h" +#include "cantera/thermo/speciesThermoTypes.h" +#include "cantera/thermo/SimpleThermo.h" +#include "cantera/thermo/IdealGasPhase.h" +#include "cantera/thermo/ConstCpPoly.h" +#include "cantera/thermo/GeneralSpeciesThermo.h" +#include "cantera/thermo/NasaPoly2.h" +#include "cantera/thermo/ShomatePoly.h" +#include "thermo_data.h" + +using namespace Cantera; + +class SpeciesThermoInterpTypeTest : public testing::Test +{ +public: + void makePhase0() { + p.addElement("H"); + p.addElement("O"); + p.addElement("C"); + st = new GeneralSpeciesThermo(); + p.setSpeciesThermo(st); + } + + void makePhase1() { + makePhase0(); + p.addSpecies("O2", o2_comp); + p.addSpecies("H2", h2_comp); + p.addSpecies("H2O", h2o_comp); + } + + void makePhase2() { + makePhase0(); + p.addSpecies("CO", co_comp); + p.addSpecies("CO2", co2_comp); + } + + IdealGasPhase p; + SpeciesThermo* st; +}; + +// {T0, h0, s0, cp0} (in J/kmol) +double c_o2[] = {298.15, 0.0, 2.05152e5, 2.939e4}; +double c_h2[] = {298.15, 0.0, 1.3068e5, 2.885e4}; +double c_h2o[] = {298.15, -2.41826e8, 1.8884e5, 3.522e4}; +double c_co2[] = {298.15, -3.9351e8, 2.13785e5, 3.712e4}; + +TEST_F(SpeciesThermoInterpTypeTest, install_const_cp) +{ + // Compare against instantiation from CTI file + IdealGasPhase p2("../data/simplephases.cti", "simple1"); + makePhase1(); + SpeciesThermoInterpType* stit_o2 = new ConstCpPoly(0, 200, 5000, 101325, c_o2); + SpeciesThermoInterpType* stit_h2 = new ConstCpPoly(1, 200, 5000, 101325, c_h2); + SpeciesThermoInterpType* stit_h2o = new ConstCpPoly(2, 200, 5000, 101325, c_h2o); + st->install_STIT(stit_o2); + st->install_STIT(stit_h2); + st->install_STIT(stit_h2o); + p.initThermo(); + p2.setState_TPX(298.15, 101325, "H2:0.2, O2:0.7, H2O:0.1"); + p.setState_TPX(298.15, 101325, "H2:0.2, O2:0.7, H2O:0.1"); + EXPECT_FLOAT_EQ(p2.meanMolecularWeight(), p.meanMolecularWeight()); + EXPECT_FLOAT_EQ(p2.enthalpy_mass(), p.enthalpy_mass()); + EXPECT_FLOAT_EQ(p2.entropy_mass(), p.entropy_mass()); + EXPECT_FLOAT_EQ(p2.cp_mass(), p.cp_mass()); +} + +TEST_F(SpeciesThermoInterpTypeTest, missing_species) +{ + makePhase1(); + SpeciesThermoInterpType* stit_o2 = new ConstCpPoly(0, 200, 5000, 101325, c_o2); + SpeciesThermoInterpType* stit_h2 = new ConstCpPoly(1, 200, 5000, 101325, c_h2); + st->install_STIT(stit_o2); + st->install_STIT(stit_h2); + // Thermo data for H2O not given + EXPECT_THROW(p.initThermo(), CanteraError); +} + +TEST_F(SpeciesThermoInterpTypeTest, install_bad_pref) +{ + makePhase1(); + SpeciesThermoInterpType* stit_o2 = new ConstCpPoly(0, 200, 5000, 101325, c_o2); + SpeciesThermoInterpType* stit_h2 = new ConstCpPoly(1, 200, 5000, 100000, c_h2); + st->install_STIT(stit_o2); + // Pref does not match + ASSERT_THROW(st->install_STIT(stit_h2), CanteraError); + delete stit_h2; +} + +TEST_F(SpeciesThermoInterpTypeTest, install_nasa) +{ + // Compare against instantiation from CTI file + IdealGasPhase p2("../data/simplephases.cti", "nasa1"); + makePhase1(); + SpeciesThermoInterpType* stit_o2 = new NasaPoly2(0, 200, 3500, 101325, o2_nasa_coeffs); + SpeciesThermoInterpType* stit_h2 = new NasaPoly2(1, 200, 3500, 101325, h2_nasa_coeffs); + SpeciesThermoInterpType* stit_h2o = new NasaPoly2(2, 200, 3500, 101325, h2o_nasa_coeffs); + st->install_STIT(stit_o2); + st->install_STIT(stit_h2); + st->install_STIT(stit_h2o); + p.initThermo(); + p2.setState_TPX(900, 101325, "H2:0.2, O2:0.7, H2O:0.1"); + p.setState_TPX(900, 101325, "H2:0.2, O2:0.7, H2O:0.1"); + EXPECT_FLOAT_EQ(p2.meanMolecularWeight(), p.meanMolecularWeight()); + EXPECT_FLOAT_EQ(p2.enthalpy_mass(), p.enthalpy_mass()); + EXPECT_FLOAT_EQ(p2.entropy_mass(), p.entropy_mass()); + EXPECT_FLOAT_EQ(p2.cp_mass(), p.cp_mass()); +} + +TEST_F(SpeciesThermoInterpTypeTest, install_shomate) +{ + // Compare against instantiation from CTI file + IdealGasPhase p2("../data/simplephases.cti", "shomate1"); + makePhase2(); + SpeciesThermo* st = new GeneralSpeciesThermo(); + p.setSpeciesThermo(st); + SpeciesThermoInterpType* stit_co = new ShomatePoly2(0, 200, 6000, 101325, co_shomate_coeffs); + SpeciesThermoInterpType* stit_co2 = new ShomatePoly2(1, 200, 6000, 101325, co2_shomate_coeffs); + st->install_STIT(stit_co); + st->install_STIT(stit_co2); + p.initThermo(); + p2.setState_TPX(900, 101325, "CO:0.2, CO2:0.8"); + p.setState_TPX(900, 101325, "CO:0.2, CO2:0.8"); + EXPECT_FLOAT_EQ(p2.meanMolecularWeight(), p.meanMolecularWeight()); + EXPECT_FLOAT_EQ(p2.enthalpy_mass(), p.enthalpy_mass()); + EXPECT_FLOAT_EQ(p2.entropy_mass(), p.entropy_mass()); + EXPECT_FLOAT_EQ(p2.cp_mass(), p.cp_mass()); +} diff --git a/test/thermo/thermo_data.h b/test/thermo/thermo_data.h new file mode 100644 index 000000000..3fed38c2c --- /dev/null +++ b/test/thermo/thermo_data.h @@ -0,0 +1,44 @@ +namespace { + +// 2-region NASA coefficients; Order is significantly different from the +// standard NASA format. +const double h2o_nasa_coeffs[] = { + 1000.0, -3.029372670E+04, -8.490322080E-01, 4.198640560E+00, + -2.036434100E-03, 6.520402110E-06, -5.487970620E-09, 1.771978170E-12, + -3.000429710E+04, 4.966770100E+00, 3.033992490E+00, 2.176918040E-03, + -1.640725180E-07, -9.704198700E-11, 1.682009920E-14}; +const double h2o_comp[] = {2.0, 1.0, 0.0}; + +const double h2_nasa_coeffs[] = { + 1000.0, -9.17935173E+02, 6.83010238E-01, 2.34433112E+00, + 7.98052075E-03, -1.94781510E-05, 2.01572094E-08, -7.37611761E-12, + -9.50158922E+02, -3.20502331E+00, 3.33727920E+00, -4.94024731E-05, + 4.99456778E-07, -1.79566394E-10, 2.00255376E-14}; +const double h2_comp[] = {2.0, 0.0, 0.0}; + +const double o2_nasa_coeffs[] = { + 1000.0, -1.063943560E+03, 3.657675730E+00, 3.782456360E+00, + -2.996734160E-03, 9.847302010E-06, -9.681295090E-09, 3.243728370E-12, + -1.088457720E+03, 5.453231290E+00, 3.282537840E+00, 1.483087540E-03, + -7.579666690E-07, 2.094705550E-10, -2.167177940E-14}; +const double o2_comp[] = {0.0, 2.0, 0.0}; + +const double oh_nasa_coeffs[] = { + 1000.0, 3.615080560E+03, -1.039254580E-01, 3.992015430E+00, + -2.401317520E-03, 4.617938410E-06, -3.881133330E-09, 1.364114700E-12, + 3.858657000E+03, 4.476696100E+00, 3.092887670E+00, 5.484297160E-04, + 1.265052280E-07, -8.794615560E-11, 1.174123760E-14}; +const double oh_comp[] = {1.0, 1.0, 0.0}; + +// 2-region Shomate coefficients (from NIST Chemistry WebBook) +const double co2_shomate_coeffs[] = { + 1200.0, 24.99735, 55.18696, -33.69137, 7.948387, -0.136638, -403.6075, 228.2431, + 58.16639, 2.720074, -0.492289, 0.038844, -6.447293, -425.9186, 263.6125}; +const double co2_comp[] = {0.0, 2.0, 1.0}; + +const double co_shomate_coeffs[] = { + 1300.0, 25.56759, 6.096130, 4.054656, -2.671301, 0.131021, -118.0089, 227.3665, + 35.15070, 1.300095, -0.205921, 0.013550, -3.282780, -127.8375, 231.7120}; +const double co_comp[] = {0.0, 1.0, 1.0}; + +}