cantera/test/thermo/phaseConstructors.cpp
Ray Speth ff9584105b Do implicit CTI to XML conversions without generating .xml files
When instantiating a phase from a .cti file, do the conversion in memory,
without writing the XML representation to disk. This eliminates the unrequrested
XML files that Cantera normally generates, and also avoids errors when running
Cantera from a directory where the user does not have write permissons.
2014-01-30 00:47:37 +00:00

66 lines
1.6 KiB
C++

#include "gtest/gtest.h"
#include "cantera/thermo/FixedChemPotSSTP.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/ctml.h"
namespace Cantera
{
class FixedChemPotSstpConstructorTest : public testing::Test
{
};
TEST_F(FixedChemPotSstpConstructorTest, fromXML)
{
ThermoPhase* p = newPhase("../data/LiFixed.xml", "");
ASSERT_EQ((int) p->nSpecies(), 1);
double mu;
p->getChemPotentials(&mu);
ASSERT_FLOAT_EQ(-2.3e7, mu);
delete p;
}
TEST_F(FixedChemPotSstpConstructorTest, SimpleConstructor)
{
FixedChemPotSSTP p("Li", -2.3e7);
ASSERT_EQ((int) p.nSpecies(), 1);
double mu;
p.getChemPotentials(&mu);
ASSERT_FLOAT_EQ(-2.3e7, mu);
}
#ifndef HAS_NO_PYTHON // skip these tests if the Python converter is unavailable
class InputFileConversionTest : public testing::Test
{
public:
InputFileConversionTest() {
appdelete();
}
ThermoPhase* p1;
ThermoPhase* p2;
void compare()
{
ASSERT_EQ(p1->nSpecies(), p2->nSpecies());
for (size_t i = 0; i < p1->nSpecies(); i++) {
ASSERT_EQ(p1->speciesName(i), p2->speciesName(i));
ASSERT_EQ(p1->molecularWeight(i), p2->molecularWeight(i));
}
}
};
TEST_F(InputFileConversionTest, ExplicitConversion) {
p1 = newPhase("../data/air-no-reactions.xml", "");
ctml::ct2ctml("../data/air-no-reactions.cti");
p2 = newPhase("air-no-reactions.xml", "");
compare();
}
TEST_F(InputFileConversionTest, ImplicitConversion) {
p1 = newPhase("../data/air-no-reactions.xml", "");
p2 = newPhase("../data/air-no-reactions.cti", "");
compare();
}
#endif
} // namespace Cantera