[Thermo] Make PureFluidPhase configurable without XML
The 'setSubstance' method allows setting the equation of state to use, which could only be done before using the 'setParametersFromXML' method.
This commit is contained in:
parent
62c67e4ad1
commit
86dca05369
3 changed files with 32 additions and 2 deletions
|
|
@ -49,6 +49,12 @@ public:
|
|||
return "PureFluid";
|
||||
}
|
||||
|
||||
//! Set the name of the TPX substance to use for the equation of state. This
|
||||
//! function should be called before initThermo().
|
||||
void setSubstance(const std::string& name) {
|
||||
m_tpx_name = name;
|
||||
}
|
||||
|
||||
virtual doublereal enthalpy_mole() const;
|
||||
virtual doublereal intEnergy_mole() const;
|
||||
virtual doublereal entropy_mole() const;
|
||||
|
|
@ -190,10 +196,15 @@ private:
|
|||
|
||||
//! Int indicating the type of the fluid
|
||||
/*!
|
||||
* The tpx package uses an int to indicate what fluid is being sought.
|
||||
* The tpx package uses an int to indicate what fluid is being sought. Used
|
||||
* only if #m_tpx_name is not set.
|
||||
*/
|
||||
int m_subflag;
|
||||
|
||||
//! Name for this substance used by the TPX package. If this is not set,
|
||||
//! #m_subflag is used instead.
|
||||
std::string m_tpx_name;
|
||||
|
||||
//! Molecular weight of the substance (kg kmol-1)
|
||||
doublereal m_mw;
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,11 @@ ThermoPhase* PureFluidPhase::duplMyselfAsThermoPhase() const
|
|||
|
||||
void PureFluidPhase::initThermo()
|
||||
{
|
||||
m_sub.reset(tpx::GetSub(m_subflag));
|
||||
if (m_tpx_name != "") {
|
||||
m_sub.reset(tpx::newSubstance(m_tpx_name));
|
||||
} else {
|
||||
m_sub.reset(tpx::GetSub(m_subflag));
|
||||
}
|
||||
if (!m_sub) {
|
||||
throw CanteraError("PureFluidPhase::initThermo",
|
||||
"could not create new substance object.");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "cantera/thermo/ThermoFactory.h"
|
||||
#include "cantera/thermo/FixedChemPotSSTP.h"
|
||||
#include "cantera/thermo/PureFluidPhase.h"
|
||||
#include "cantera/thermo/NasaPoly2.h"
|
||||
#include "cantera/thermo/ShomatePoly.h"
|
||||
#include "cantera/thermo/IdealGasPhase.h"
|
||||
#include "cantera/base/ctml.h"
|
||||
#include "cantera/base/stringUtils.h"
|
||||
|
|
@ -184,4 +186,17 @@ TEST_F(ConstructFromScratch, addUndefinedElements)
|
|||
ASSERT_DOUBLE_EQ(0.5, p.massFraction("CO2"));
|
||||
}
|
||||
|
||||
TEST(PureFluidFromScratch, CarbonDioxide)
|
||||
{
|
||||
PureFluidPhase p;
|
||||
auto sCO2 = make_shared<Species>("CO2", parseCompString("C:1 O:2"));
|
||||
sCO2->thermo.reset(new ShomatePoly2(200, 6000, 101325, co2_shomate_coeffs));
|
||||
p.addUndefinedElements();
|
||||
p.addSpecies(sCO2);
|
||||
p.setSubstance("carbondioxide");
|
||||
p.initThermo();
|
||||
p.setState_Tsat(280, 0.5);
|
||||
EXPECT_NEAR(p.pressure(), 4160236.987, 1e-2);
|
||||
}
|
||||
|
||||
} // namespace Cantera
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue