From 7fe8f0f3b7732f668944cfef62881d801ec5d84e Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 5 Aug 2015 12:09:02 -0400 Subject: [PATCH] [Thermo] Refactor common initialization out of constructors --- src/thermo/DebyeHuckel.cpp | 16 ++++------------ src/thermo/FixedChemPotSSTP.cpp | 11 +++++------ src/thermo/HMWSoln.cpp | 12 ------------ src/thermo/HMWSoln_input.cpp | 4 ++++ src/thermo/IonsFromNeutralVPSSTP.cpp | 7 +------ src/thermo/RedlichKwongMFTP.cpp | 13 ++++--------- src/thermo/StoichSubstanceSSTP.cpp | 16 +++++----------- 7 files changed, 23 insertions(+), 56 deletions(-) diff --git a/src/thermo/DebyeHuckel.cpp b/src/thermo/DebyeHuckel.cpp index 072128dbc..e0ced1e4c 100644 --- a/src/thermo/DebyeHuckel.cpp +++ b/src/thermo/DebyeHuckel.cpp @@ -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(); } diff --git a/src/thermo/FixedChemPotSSTP.cpp b/src/thermo/FixedChemPotSSTP.cpp index e021abb4f..6ea13ed75 100644 --- a/src/thermo/FixedChemPotSSTP.cpp +++ b/src/thermo/FixedChemPotSSTP.cpp @@ -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) diff --git a/src/thermo/HMWSoln.cpp b/src/thermo/HMWSoln.cpp index 97b5d497e..2d01c786d 100644 --- a/src/thermo/HMWSoln.cpp +++ b/src/thermo/HMWSoln.cpp @@ -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); } diff --git a/src/thermo/HMWSoln_input.cpp b/src/thermo/HMWSoln_input.cpp index df8a4ffff..5c2bdb638 100644 --- a/src/thermo/HMWSoln_input.cpp +++ b/src/thermo/HMWSoln_input.cpp @@ -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(); } diff --git a/src/thermo/IonsFromNeutralVPSSTP.cpp b/src/thermo/IonsFromNeutralVPSSTP.cpp index b3bdf357f..f49693a21 100644 --- a/src/thermo/IonsFromNeutralVPSSTP.cpp +++ b/src/thermo/IonsFromNeutralVPSSTP.cpp @@ -53,7 +53,6 @@ IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(const std::string& inputFile, IOwnNThermoPhase_ = false; } constructPhaseFile(inputFile, id_); - geThermo = dynamic_cast(neutralMoleculePhase_); } IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(XML_Node& phaseRoot, @@ -69,11 +68,6 @@ IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(XML_Node& phaseRoot, IOwnNThermoPhase_ = false; } constructPhaseXML(phaseRoot, id_); - geThermo = dynamic_cast(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(neutralMoleculePhase_); } void IonsFromNeutralVPSSTP::initLengths() diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index 2768731a1..cdb72df0c 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -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(); } diff --git a/src/thermo/StoichSubstanceSSTP.cpp b/src/thermo/StoichSubstanceSSTP.cpp index 584c3fafb..19549acde 100644 --- a/src/thermo/StoichSubstanceSSTP.cpp +++ b/src/thermo/StoichSubstanceSSTP.cpp @@ -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_);