[Thermo] Refactor common initialization out of constructors

This commit is contained in:
Ray Speth 2015-08-05 12:09:02 -04:00
parent ff60328ecd
commit 7fe8f0f3b7
7 changed files with 23 additions and 56 deletions

View file

@ -41,10 +41,6 @@ DebyeHuckel::DebyeHuckel() :
m_densWaterSS(1000.),
m_waterProps(0)
{
m_npActCoeff.resize(3);
m_npActCoeff[0] = 0.1127;
m_npActCoeff[1] = -0.01049;
m_npActCoeff[2] = 1.545E-3;
}
DebyeHuckel::DebyeHuckel(const std::string& inputFile,
@ -62,10 +58,6 @@ DebyeHuckel::DebyeHuckel(const std::string& inputFile,
m_densWaterSS(1000.),
m_waterProps(0)
{
m_npActCoeff.resize(3);
m_npActCoeff[0] = 0.1127;
m_npActCoeff[1] = -0.01049;
m_npActCoeff[2] = 1.545E-3;
initThermoFile(inputFile, id_);
}
@ -83,10 +75,6 @@ DebyeHuckel::DebyeHuckel(XML_Node& phaseRoot, const std::string& id_) :
m_densWaterSS(1000.),
m_waterProps(0)
{
m_npActCoeff.resize(3);
m_npActCoeff[0] = 0.1127;
m_npActCoeff[1] = -0.01049;
m_npActCoeff[2] = 1.545E-3;
importPhase(*findXMLPhase(&phaseRoot, id_), this);
}
@ -504,6 +492,10 @@ void DebyeHuckel::getPartialMolarCp(doublereal* cpbar) const
void DebyeHuckel::initThermo()
{
MolalityVPSSTP::initThermo();
m_npActCoeff.resize(3);
m_npActCoeff[0] = 0.1127;
m_npActCoeff[1] = -0.01049;
m_npActCoeff[2] = 1.545E-3;
initLengths();
}

View file

@ -68,11 +68,6 @@ FixedChemPotSSTP::FixedChemPotSSTP(XML_Node& xmlphase, const std::string& id_) :
"thermo model attribute must be StoichSubstance or FixedChemPot");
}
importPhase(xmlphase, this);
if (model == "StoichSubstance" || model == "StoichSubstanceSSTP") {
_updateThermo();
chemPot_ = (m_h0_RT[0] - m_s0_R[0]) * GasConstant * temperature();
}
}
FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) :
@ -284,11 +279,15 @@ void FixedChemPotSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_
throw CanteraError("FixedChemPotSSTP::initThermoXML()",
"thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
}
SingleSpeciesTP::initThermoXML(phaseNode, id_);
if (model == "FixedChemPot") {
double val = getFloatDefaultUnits(tnode, "chemicalPotential", "J/kmol");
chemPot_ = val;
} else {
_updateThermo();
chemPot_ = (m_h0_RT[0] - m_s0_R[0]) * GasConstant * temperature();
}
SingleSpeciesTP::initThermoXML(phaseNode, id_);
}
void FixedChemPotSSTP::setParameters(int n, doublereal* const c)

View file

@ -72,10 +72,6 @@ HMWSoln::HMWSoln() :
m_last_is(-1.0),
m_debugCalc(0)
{
for (size_t i = 0; i < 17; i++) {
elambda[i] = 0.0;
elambda1[i] = 0.0;
}
}
HMWSoln::HMWSoln(const std::string& inputFile, const std::string& id_) :
@ -122,10 +118,6 @@ HMWSoln::HMWSoln(const std::string& inputFile, const std::string& id_) :
m_last_is(-1.0),
m_debugCalc(0)
{
for (int i = 0; i < 17; i++) {
elambda[i] = 0.0;
elambda1[i] = 0.0;
}
initThermoFile(inputFile, id_);
}
@ -173,10 +165,6 @@ HMWSoln::HMWSoln(XML_Node& phaseRoot, const std::string& id_) :
m_last_is(-1.0),
m_debugCalc(0)
{
for (int i = 0; i < 17; i++) {
elambda[i] = 0.0;
elambda1[i] = 0.0;
}
importPhase(*findXMLPhase(&phaseRoot, id_), this);
}

View file

@ -942,6 +942,10 @@ void HMWSoln::readXMLCroppingCoefficients(const XML_Node& acNode)
void HMWSoln::initThermo()
{
MolalityVPSSTP::initThermo();
for (int i = 0; i < 17; i++) {
elambda[i] = 0.0;
elambda1[i] = 0.0;
}
initLengths();
}

View file

@ -53,7 +53,6 @@ IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(const std::string& inputFile,
IOwnNThermoPhase_ = false;
}
constructPhaseFile(inputFile, id_);
geThermo = dynamic_cast<GibbsExcessVPSSTP*>(neutralMoleculePhase_);
}
IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(XML_Node& phaseRoot,
@ -69,11 +68,6 @@ IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(XML_Node& phaseRoot,
IOwnNThermoPhase_ = false;
}
constructPhaseXML(phaseRoot, id_);
geThermo = dynamic_cast<GibbsExcessVPSSTP*>(neutralMoleculePhase_);
y_.resize(numNeutralMoleculeSpecies_,0.0);
size_t numNeutMolSpec = geThermo->nSpecies();
dlnActCoeff_NeutralMolecule_.resize(numNeutMolSpec);
dX_NeutralMolecule_.resize(numNeutMolSpec);
}
IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(const IonsFromNeutralVPSSTP& b) :
@ -721,6 +715,7 @@ void IonsFromNeutralVPSSTP::initThermo()
{
initLengths();
GibbsExcessVPSSTP::initThermo();
geThermo = dynamic_cast<GibbsExcessVPSSTP*>(neutralMoleculePhase_);
}
void IonsFromNeutralVPSSTP::initLengths()

View file

@ -37,9 +37,6 @@ RedlichKwongMFTP::RedlichKwongMFTP() :
dpdV_(0.0),
dpdT_(0.0)
{
Vroot_[0] = 0.0;
Vroot_[1] = 0.0;
Vroot_[2] = 0.0;
}
RedlichKwongMFTP::RedlichKwongMFTP(const std::string& infile, std::string id_) :
@ -51,9 +48,6 @@ RedlichKwongMFTP::RedlichKwongMFTP(const std::string& infile, std::string id_) :
dpdV_(0.0),
dpdT_(0.0)
{
Vroot_[0] = 0.0;
Vroot_[1] = 0.0;
Vroot_[2] = 0.0;
XML_Node* root = get_XML_File(infile);
if (id_ == "-") {
id_ = "";
@ -75,9 +69,6 @@ RedlichKwongMFTP::RedlichKwongMFTP(XML_Node& phaseRefRoot, const std::string& id
dpdV_(0.0),
dpdT_(0.0)
{
Vroot_[0] = 0.0;
Vroot_[1] = 0.0;
Vroot_[2] = 0.0;
XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, &phaseRefRoot);
if (!xphase) {
throw CanteraError("RedlichKwongMFTP::RedlichKwongMFTP()","Couldn't find phase named \"" + id_ + "\" in XML node");
@ -580,6 +571,10 @@ doublereal RedlichKwongMFTP::critDensity() const
void RedlichKwongMFTP::initThermo()
{
Vroot_[0] = 0.0;
Vroot_[1] = 0.0;
Vroot_[2] = 0.0;
initLengths();
MixtureFugacityTP::initThermo();
}

View file

@ -35,12 +35,6 @@ StoichSubstanceSSTP::StoichSubstanceSSTP(const std::string& infile, std::string
throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
"Couldn't find phase name in file:" + id_);
}
// Check the model name to ensure we have compatibility
std::string model = xphase->child("thermo")["model"];
if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
"thermo model attribute must be StoichSubstance");
}
importPhase(*xphase, this);
}
@ -50,11 +44,6 @@ StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, const std::string&
throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
"id's don't match");
}
std::string model = xmlphase.child("thermo")["model"];
if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
"thermo model attribute must be StoichSubstance");
}
importPhase(xmlphase, this);
}
@ -220,6 +209,11 @@ void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, const std::string&
"no thermo XML node");
}
XML_Node& tnode = phaseNode.child("thermo");
std::string model = tnode["model"];
if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
throw CanteraError("StoichSubstanceSSTP::initThermoXML",
"thermo model attribute must be StoichSubstance");
}
double dens = getFloatDefaultUnits(tnode, "density", "kg/m3");
setDensity(dens);
SingleSpeciesTP::initThermoXML(phaseNode, id_);