[Test] Move "ChemEquil_red1" to GTest suite
The old version of this test didn't actually check any meaninful results. The ChemEquil and VCS solvers are both able to solve this problem, but the MultiPhase solver currently fails. Also, the BasisOptimize function may fail depending on the order that the elements are specified in the input file.
This commit is contained in:
parent
e34b2739b2
commit
c2344377ac
7 changed files with 102 additions and 1496 deletions
|
|
@ -218,6 +218,7 @@ else:
|
||||||
# Instantiate tests
|
# Instantiate tests
|
||||||
addTestProgram('general', 'general', env_vars=python_env_vars)
|
addTestProgram('general', 'general', env_vars=python_env_vars)
|
||||||
addTestProgram('thermo', 'thermo', env_vars=python_env_vars)
|
addTestProgram('thermo', 'thermo', env_vars=python_env_vars)
|
||||||
|
addTestProgram('equil', 'equil', env_vars=python_env_vars)
|
||||||
addTestProgram('kinetics', 'kinetics', env_vars=python_env_vars)
|
addTestProgram('kinetics', 'kinetics', env_vars=python_env_vars)
|
||||||
addTestProgram('transport', 'transport', env_vars=python_env_vars)
|
addTestProgram('transport', 'transport', env_vars=python_env_vars)
|
||||||
|
|
||||||
|
|
|
||||||
101
test/equil/equil_gas.cpp
Normal file
101
test/equil/equil_gas.cpp
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "cantera/thermo/ThermoFactory.h"
|
||||||
|
#include "cantera/equil/MultiPhase.h"
|
||||||
|
#include "cantera/base/global.h"
|
||||||
|
|
||||||
|
using namespace Cantera;
|
||||||
|
|
||||||
|
class OverconstrainedEquil : public testing::Test
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OverconstrainedEquil() {}
|
||||||
|
void setup(const std::string& elements="H C O N Ar") {
|
||||||
|
XML_Node* phase = get_XML_from_string(
|
||||||
|
"ideal_gas(elements='" + elements + "', species='gri30: CH C2H2')");
|
||||||
|
gas.reset(newPhase(*phase->findByName("phase")));
|
||||||
|
gas->setState_TPX(1000, 1e5, "C2H2:0.9, CH:0.1");
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<ThermoPhase> gas;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(OverconstrainedEquil, ChemEquil)
|
||||||
|
{
|
||||||
|
setup();
|
||||||
|
gas->equilibrate("TP", "element_potential");
|
||||||
|
EXPECT_NEAR(gas->moleFraction("C2H2"), 1.0, 1e-10);
|
||||||
|
EXPECT_NEAR(gas->moleFraction("CH"), 0.0, 1e-10);
|
||||||
|
vector_fp mu(2);
|
||||||
|
gas->getChemPotentials(&mu[0]);
|
||||||
|
EXPECT_NEAR(2*mu[0], mu[1], 1e-7*std::abs(mu[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OverconstrainedEquil, VcsNonideal)
|
||||||
|
{
|
||||||
|
setup();
|
||||||
|
gas->equilibrate("TP", "vcs");
|
||||||
|
EXPECT_NEAR(gas->moleFraction("C2H2"), 1.0, 1e-10);
|
||||||
|
EXPECT_NEAR(gas->moleFraction("CH"), 0.0, 1e-10);
|
||||||
|
vector_fp mu(2);
|
||||||
|
gas->getChemPotentials(&mu[0]);
|
||||||
|
EXPECT_NEAR(2*mu[0], mu[1], 1e-7*std::abs(mu[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OverconstrainedEquil, DISABLED_MultiphaseEquil)
|
||||||
|
{
|
||||||
|
setup();
|
||||||
|
gas->equilibrate("TP", "gibbs");
|
||||||
|
EXPECT_NEAR(gas->moleFraction("C2H2"), 1.0, 1e-10);
|
||||||
|
EXPECT_NEAR(gas->moleFraction("CH"), 0.0, 1e-10);
|
||||||
|
vector_fp mu(2);
|
||||||
|
gas->getChemPotentials(&mu[0]);
|
||||||
|
EXPECT_NEAR(2*mu[0], mu[1], 1e-7*std::abs(mu[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OverconstrainedEquil, BasisOptimize)
|
||||||
|
{
|
||||||
|
setup();
|
||||||
|
MultiPhase mphase;
|
||||||
|
mphase.addPhase(gas.get(), 10.0);
|
||||||
|
mphase.init();
|
||||||
|
int usedZeroedSpecies = 0;
|
||||||
|
std::vector<size_t> orderVectorSpecies;
|
||||||
|
std::vector<size_t> orderVectorElements;
|
||||||
|
|
||||||
|
bool doFormMatrix = true;
|
||||||
|
vector_fp formRxnMatrix;
|
||||||
|
|
||||||
|
size_t nc = BasisOptimize(&usedZeroedSpecies, doFormMatrix, &mphase,
|
||||||
|
orderVectorSpecies, orderVectorElements,
|
||||||
|
formRxnMatrix);
|
||||||
|
ASSERT_EQ(1, (int) nc);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OverconstrainedEquil, DISABLED_BasisOptimize2)
|
||||||
|
{
|
||||||
|
setup("O H C N Ar");
|
||||||
|
MultiPhase mphase;
|
||||||
|
mphase.addPhase(gas.get(), 10.0);
|
||||||
|
mphase.init();
|
||||||
|
int usedZeroedSpecies = 0;
|
||||||
|
std::vector<size_t> orderVectorSpecies;
|
||||||
|
std::vector<size_t> orderVectorElements;
|
||||||
|
|
||||||
|
bool doFormMatrix = true;
|
||||||
|
vector_fp formRxnMatrix;
|
||||||
|
|
||||||
|
size_t nc = BasisOptimize(&usedZeroedSpecies, doFormMatrix, &mphase,
|
||||||
|
orderVectorSpecies, orderVectorElements,
|
||||||
|
formRxnMatrix);
|
||||||
|
ASSERT_EQ(1, (int) nc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
printf("Running main() from equil_gas.cpp\n");
|
||||||
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
int result = RUN_ALL_TESTS();
|
||||||
|
appdelete();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
#include "cantera/IdealGasMix.h"
|
|
||||||
#include "cantera/equil/MultiPhase.h"
|
|
||||||
|
|
||||||
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("red1.xml", "gri30_mix");
|
|
||||||
|
|
||||||
#ifdef DEBUG_BASISOPTIMIZE
|
|
||||||
Cantera::BasisOptimize_print_lvl = 0;
|
|
||||||
#endif
|
|
||||||
#ifdef DEBUG_CHEMEQUIL
|
|
||||||
Cantera::ChemEquil_print_lvl = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
double pres = 1.0E5;
|
|
||||||
g.setState_TPX(2000.0, pres, "C2H2:0.9, CH:0.1");
|
|
||||||
|
|
||||||
MultiPhase mphase;
|
|
||||||
mphase.addPhase(&g, 10.0);
|
|
||||||
mphase.init();
|
|
||||||
int usedZeroedSpecies = 0;
|
|
||||||
std::vector<size_t> orderVectorSpecies;
|
|
||||||
std::vector<size_t> orderVectorElements;
|
|
||||||
|
|
||||||
bool doFormMatrix = true;
|
|
||||||
vector_fp formRxnMatrix;
|
|
||||||
|
|
||||||
size_t nc = BasisOptimize(&usedZeroedSpecies, doFormMatrix,
|
|
||||||
&mphase, orderVectorSpecies,
|
|
||||||
orderVectorElements,
|
|
||||||
formRxnMatrix);
|
|
||||||
|
|
||||||
cout << "number of components = " << nc << endl;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The ChemEquil solver throws an error for this case.
|
|
||||||
* The MultiPhaseEquil solver just gets the wrong result.
|
|
||||||
*/
|
|
||||||
g.equilibrate("TP", "auto");
|
|
||||||
cout.unsetf(ios::floatfield);
|
|
||||||
cout.precision(3);
|
|
||||||
//cout << g;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
} catch (CanteraError& err) {
|
|
||||||
std::cerr << err.what() << std::endl;
|
|
||||||
cerr << "program terminating." << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
number of components = 1
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,35 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
#
|
|
||||||
temp_success="1"
|
|
||||||
/bin/rm -f output.txt outputa.txt
|
|
||||||
testName="baseopt_red1"
|
|
||||||
|
|
||||||
#################################################################
|
|
||||||
#
|
|
||||||
#################################################################
|
|
||||||
CANTERA_DATA=${CANTERA_DATA:=../../data/inputs}; export CANTERA_DATA
|
|
||||||
|
|
||||||
CANTERA_BIN=${CANTERA_BIN:=../../bin}
|
|
||||||
./basopt_red1 > output.txt
|
|
||||||
retnStat=$?
|
|
||||||
if [ $retnStat != "0" ]
|
|
||||||
then
|
|
||||||
temp_success="0"
|
|
||||||
echo "$testName returned with bad status, $retnStat, check output"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
diff -w output.txt output_blessed.txt > diff_test.out
|
|
||||||
retnStat=$?
|
|
||||||
if [ $retnStat = "0" ]
|
|
||||||
then
|
|
||||||
echo "successful diff comparison on $testName test"
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "unsuccessful diff comparison on $testName test"
|
|
||||||
echo "FAILED" > csvCode.txt
|
|
||||||
temp_success="0"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
@ -228,8 +228,6 @@ CompileAndTest('ChemEquil_ionizedGas',
|
||||||
'ChemEquil_ionizedGas', 'ionizedGasEquil',
|
'ChemEquil_ionizedGas', 'ionizedGasEquil',
|
||||||
'output_blessed.txt',
|
'output_blessed.txt',
|
||||||
comparisons=[('table_blessed.csv', 'table.csv')])
|
comparisons=[('table_blessed.csv', 'table.csv')])
|
||||||
CompileAndTest('ChemEquil_red1',
|
|
||||||
'ChemEquil_red1', 'basopt_red1', 'output_blessed.txt')
|
|
||||||
#CompileAndTest('CpJump', 'CpJump', 'CpJump', 'output_blessed.txt')
|
#CompileAndTest('CpJump', 'CpJump', 'CpJump', 'output_blessed.txt')
|
||||||
CompileAndTest('cxx_ex', 'cxx_ex', 'cxx_examples', 'output_blessed.txt',
|
CompileAndTest('cxx_ex', 'cxx_ex', 'cxx_examples', 'output_blessed.txt',
|
||||||
comparisons=[('eq1_blessed.csv', 'eq1.csv'),
|
comparisons=[('eq1_blessed.csv', 'eq1.csv'),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue