diff --git a/test/equil/equil_gas.cpp b/test/equil/equil_gas.cpp index 2b8864419..600400497 100644 --- a/test/equil/equil_gas.cpp +++ b/test/equil/equil_gas.cpp @@ -100,10 +100,10 @@ TEST_F(OverconstrainedEquil, DISABLED_BasisOptimize2) ASSERT_EQ(1, (int) nc); } -class GriMatrix : public testing::Test +class GriEquilibriumTest : public testing::Test { public: - GriMatrix() : gas("gri30.xml", "gri30") { + GriEquilibriumTest() : gas("gri30.xml", "gri30") { X.resize(gas.nSpecies()); Yelem.resize(gas.nElements()); }; @@ -114,12 +114,9 @@ public: } } - void check(double T, double P) { - EXPECT_CLOSE(gas.temperature(), T, 1e-9); - EXPECT_CLOSE(gas.pressure(), P, 1e-9); - + void check(double tol=1e-8) { for (size_t i = 0; i < gas.nElements(); i++) { - EXPECT_CLOSE(Yelem[i], gas.elementalMassFraction(i), 1e-8); + EXPECT_CLOSE(Yelem[i], gas.elementalMassFraction(i), tol); } vector_fp mu(gas.nSpecies()); @@ -145,13 +142,27 @@ public: } } + IdealGasPhase gas; + vector_fp X; + vector_fp Yelem; +}; + +class GriMatrix : public GriEquilibriumTest +{ +public: + void check_TP(double T, double P) { + EXPECT_CLOSE(gas.temperature(), T, 1e-9); + EXPECT_CLOSE(gas.pressure(), P, 1e-9); + check(); + } + void check_CH4_N2(const std::string& solver) { for (int i = 0; i < 5; i++) { double T = 500 + 300 * i; gas.setState_TPX(T, OneAtm, "CH4:3, N2:2"); save_elemental_mole_fractions(); gas.equilibrate("TP", solver); - check(T, OneAtm); + check_TP(T, OneAtm); } } @@ -161,7 +172,7 @@ public: gas.setState_TPX(T, OneAtm, "O2:3, N2:2"); save_elemental_mole_fractions(); gas.equilibrate("TP", solver); - check(T, OneAtm); + check_TP(T, OneAtm); } } @@ -171,7 +182,7 @@ public: gas.setState_TPX(T, OneAtm, "CH4:3, O2:3, N2:4"); save_elemental_mole_fractions(); gas.equilibrate("TP", solver); - check(T, OneAtm); + check_TP(T, OneAtm); } } @@ -188,15 +199,11 @@ public: gas.setState_TPX(T, P, "CH4:1, O2:1"); save_elemental_mole_fractions(); gas.equilibrate("TP", solver); - check(T, P); + check_TP(T, P); } } } } - - IdealGasPhase gas; - vector_fp X; - vector_fp Yelem; }; TEST_F(GriMatrix, ChemEquil_CH4_N2) { check_CH4_N2("element_potential"); } @@ -212,6 +219,82 @@ TEST_F(GriMatrix, VcsNonideal_O2_N2) { check_O2_N2("vcs"); } TEST_F(GriMatrix, VcsNonideal_CH4_O2_N2) { check_CH4_O2_N2("vcs"); } TEST_F(GriMatrix, VcsNonideal_CH4_O2) { check_CH4_O2("vcs"); } +// Test for equilibrium at property pairs other than T and P, which require +// nested iterations. +class PropertyPairs : public GriEquilibriumTest +{ +public: + void check_HP(const std::string& solver) { + gas.setState_TPX(500, 1e5, "CH4:0.3, O2:0.3, N2:0.4"); + double h0 = gas.enthalpy_mass(); + save_elemental_mole_fractions(); + gas.equilibrate("HP", solver); + EXPECT_NEAR(h0, gas.enthalpy_mass(), 1e-3); + EXPECT_NEAR(1e5, gas.pressure(), 1e-3); + check(); + } + + void check_SP(const std::string& solver) { + gas.setState_TPX(500, 3e5, "CH4:0.3, O2:0.3, N2:0.4"); + double s0 = gas.entropy_mass(); + save_elemental_mole_fractions(); + gas.equilibrate("SP", solver); + EXPECT_NEAR(s0, gas.entropy_mass(), 1e-4); + EXPECT_NEAR(3e5, gas.pressure(), 1e-3); + check(); + } + + void check_SV(const std::string& solver) { + gas.setState_TPX(500, 3e5, "CH4:0.3, O2:0.3, N2:0.4"); + double s0 = gas.entropy_mass(); + double rho0 = gas.density(); + save_elemental_mole_fractions(); + gas.equilibrate("SV", solver); + EXPECT_NEAR(s0, gas.entropy_mass(), 1e-4); + EXPECT_NEAR(rho0, gas.density(), 1e-5); + check(); + } + + void check_TV(const std::string& solver) { + gas.setState_TPX(500, 3e5, "CH4:0.3, O2:0.3, N2:0.4"); + double rho0 = gas.density(); + save_elemental_mole_fractions(); + gas.equilibrate("TV", solver, 1e-11); + EXPECT_NEAR(rho0, gas.density(), 1e-5); + EXPECT_NEAR(500, gas.temperature(), 1e-4); + // @todo Figure out why looser tolerances are required for MultiPhase + // solver + check(5e-8); + } + + void check_UV(const std::string& solver) { + gas.setState_TPX(500, 3e5, "CH4:0.3, O2:0.3, N2:0.4"); + double u0 = gas.intEnergy_mass(); + double rho0 = gas.density(); + save_elemental_mole_fractions(); + gas.equilibrate("UV", solver); + EXPECT_NEAR(u0, gas.intEnergy_mass(), 1e-4); + EXPECT_NEAR(rho0, gas.density(), 1e-5); + check(); + } +}; + +TEST_F(PropertyPairs, ChemEquil_HP) { check_HP("element_potential"); } +TEST_F(PropertyPairs, MultiPhase_HP) { check_HP("gibbs"); } +TEST_F(PropertyPairs, VcsNonideal_HP) { check_HP("vcs"); } +TEST_F(PropertyPairs, ChemEquil_SP) { check_SP("element_potential"); } +TEST_F(PropertyPairs, MultiPhase_SP) { check_SP("gibbs"); } +TEST_F(PropertyPairs, VcsNonideal_SP) { check_SP("vcs"); } +TEST_F(PropertyPairs, ChemEquil_SV) { check_SV("element_potential"); } +// TEST_F(PropertyPairs, MultiPhase_SV) { check_SV("gibbs"); } // not implemented +TEST_F(PropertyPairs, VcsNonideal_SV) { check_SV("vcs"); } +TEST_F(PropertyPairs, ChemEquil_TV) { check_TV("element_potential"); } +TEST_F(PropertyPairs, MultiPhase_TV) { check_TV("gibbs"); } +TEST_F(PropertyPairs, VcsNonideal_TV) { check_TV("vcs"); } +TEST_F(PropertyPairs, ChemEquil_UV) { check_UV("element_potential"); } +// TEST_F(PropertyPairs, MultiPhase_UV) { check_UV("gibbs"); } // not implemented +TEST_F(PropertyPairs, VcsNonideal_UV) { check_UV("vcs"); } + int main(int argc, char** argv) { printf("Running main() from equil_gas.cpp\n"); diff --git a/test_problems/ChemEquil_gri_pairs/gri_pairs.cpp b/test_problems/ChemEquil_gri_pairs/gri_pairs.cpp deleted file mode 100644 index 38a9d5c18..000000000 --- a/test_problems/ChemEquil_gri_pairs/gri_pairs.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2002 California Institute of Technology - */ - -#include "cantera/IdealGasMix.h" - -#include - -using namespace std; -using namespace Cantera; - -int main(int argc, char** argv) -{ -#ifdef _MSC_VER - _set_output_format(_TWO_DIGIT_EXPONENT); -#endif - try { - IdealGasMix g("gri30.xml", "gri30_mix"); - double pres = 1.0E5; - g.setState_TPX(1500.0, pres, "CH4:0.3, O2:0.3, N2:0.4"); - g.equilibrate("TP", "auto"); - //cout << g; - double enth = g.enthalpy_mass(); - printf(" enth = %g\n", enth); - enth -= 1.0E5; - printf("attempted equil at (H,P) = %10.5g, %10.5g\n", enth, pres); - g.setState_HP(enth, pres); - g.equilibrate("HP", "auto"); - //cout << g; - - double entrop = g.entropy_mass(); - printf(" entropy = %g\n", entrop); - entrop += 1.0E2; - printf("attempted equil at (S,P) = %10.5g, %10.5g\n", entrop, pres); - g.setState_SP(entrop, pres); - g.equilibrate("SP", "auto"); - //cout << g; - - double dens = g.density(); - printf(" dens = %g\n", dens); - dens *= 0.9; - double vol = 1.0/dens; - printf("attempted equil at (S,V,dens) = %10.5g, %10.5g, %10.5g\n", entrop, vol, 1.0/vol); - g.setState_SV(entrop, vol); - g.equilibrate("SV", "auto"); - //cout << g; - - double temp = 1800.; - printf("attempted equil at (T,V, dens) = %10.5g, %10.5g, %10.5g\n", temp, vol, 1.0/vol); - g.setTemperature(temp); - g.equilibrate("TV", "auto"); - //cout << g; - - double inte = g.intEnergy_mass(); - printf(" inte = %g\n", inte); - inte -= 1.0E5; - printf("attempted equil at (U,V,dens) = %10.5g, %10.5g, %10.5g\n", inte, vol, 1.0/vol); - g.setState_UV(inte, vol); - g.equilibrate("UV", "auto"); - //cout << g; - - - - return 0; - } catch (CanteraError& err) { - std::cerr << err.what() << std::endl; - cerr << "program terminating." << endl; - return -1; - } -} diff --git a/test_problems/ChemEquil_gri_pairs/output_blessed.txt b/test_problems/ChemEquil_gri_pairs/output_blessed.txt deleted file mode 100644 index a7314066c..000000000 --- a/test_problems/ChemEquil_gri_pairs/output_blessed.txt +++ /dev/null @@ -1,9 +0,0 @@ - enth = -2.1541e+06 -attempted equil at (H,P) = -2.2541e+06, 1e+05 - entropy = 12212 -attempted equil at (S,P) = 12312, 1e+05 - dens = 0.155457 -attempted equil at (S,V,dens) = 12312, 7.1474, 0.13991 -attempted equil at (T,V, dens) = 1800, 7.1474, 0.13991 - inte = -2.31473e+06 -attempted equil at (U,V,dens) = -2.4147e+06, 7.1474, 0.13991 diff --git a/test_problems/ChemEquil_gri_pairs/runtest b/test_problems/ChemEquil_gri_pairs/runtest deleted file mode 100755 index bf30f8fa3..000000000 --- a/test_problems/ChemEquil_gri_pairs/runtest +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# -# -temp_success="1" -/bin/rm -f output.txt outputa.txt - -################################################################# -# -################################################################# -CANTERA_DATA=${CANTERA_DATA:=../../data/inputs}; export CANTERA_DATA - -CANTERA_BIN=${CANTERA_BIN:=../../bin} -./gri_pairs > output.txt -retnStat=$? -if [ $retnStat != "0" ] -then - temp_success="0" - echo "gri_pairs returned with bad status, $retnStat, check output" -fi - -../../bin/exp3to2.sh output.txt > outputa.txt -diff -w outputa.txt output_blessed.txt > diff_test.out -retnStat=$? -if [ $retnStat = "0" ] -then - echo "successful diff comparison on ChemEquil_gri_pairs test" - return 0 -else - echo "unsuccessful diff comparison on ChemEquil_gri_pairs test" - echo "FAILED" > csvCode.txt - temp_success="0" - return 1 -fi - diff --git a/test_problems/SConscript b/test_problems/SConscript index e4924f45e..d2ccaac55 100644 --- a/test_problems/SConscript +++ b/test_problems/SConscript @@ -220,8 +220,6 @@ CompileAndTest('ISSPTester2', 'cathermo/VPissp', 'ISSPTester2', 'output_blessed.txt') CompileAndTest('wtWater', 'cathermo/wtWater', 'wtWater', 'output_blessed.txt') -CompileAndTest('ChemEquil_gri_pairs', - 'ChemEquil_gri_pairs', 'gri_pairs', 'output_blessed.txt') CompileAndTest('ChemEquil_ionizedGas', 'ChemEquil_ionizedGas', 'ionizedGasEquil', 'output_blessed.txt',