[Thermo] Use consistent implementation for convenience constructors

The constructor with the signature (inputFile, [id]) just calls initThermoFile.
The constructor with the signature (phase XML node, [id]) just calls importPhase
(note that the id argument is unused, since the correct XML node must already be
given).
This commit is contained in:
Ray Speth 2015-08-05 12:34:22 -04:00
parent 7fe8f0f3b7
commit 7bcbbaafd9
23 changed files with 30 additions and 157 deletions

View file

@ -162,7 +162,7 @@ public:
* @param id name of the phase id in the file.
* If this is blank, the first phase in the file is used.
*/
FixedChemPotSSTP(const std::string& infile, std::string id = "");
FixedChemPotSSTP(const std::string& infile, const std::string& id = "");
//! Construct and initialize a FixedChemPotSSTP ThermoPhase object
//! directly from an XML database

View file

@ -190,7 +190,7 @@ public:
* @param id name of the phase id in the file.
* If this is blank, the first phase in the file is used.
*/
MetalSHEelectrons(const std::string& infile, std::string id = "");
MetalSHEelectrons(const std::string& infile, const std::string& id = "");
//! Construct and initialize a MetalSHEelectrons ThermoPhase object
//! directly from an XML database

View file

@ -104,7 +104,7 @@ public:
* @param id name of the phase id in the file.
* If this is blank, the first phase in the file is used.
*/
MineralEQ3(const std::string& infile, std::string id = "");
MineralEQ3(const std::string& infile, const std::string& id = "");
//! Construct and initialize a StoichSubstanceSSTP ThermoPhase object
//! directly from an XML database

View file

@ -42,7 +42,7 @@ public:
* to set up the object
* @param id ID of the phase in the input file. Defaults to the empty string.
*/
RedlichKwongMFTP(const std::string& infile, std::string id="");
RedlichKwongMFTP(const std::string& infile, const std::string& id="");
//! Construct and initialize a RedlichKwongMFTP object directly from an
//! XML database

View file

@ -167,7 +167,7 @@ public:
* @param id name of the phase id in the file.
* If this is blank, the first phase in the file is used.
*/
StoichSubstanceSSTP(const std::string& infile, std::string id = "");
StoichSubstanceSSTP(const std::string& infile, const std::string& id = "");
//! Construct and initialize a StoichSubstanceSSTP ThermoPhase object
//! directly from an XML database

View file

@ -157,7 +157,7 @@ public:
* @param id name of the phase id in the file.
* If this is blank, the first phase in the file is used.
*/
SurfPhase(const std::string& infile, std::string id);
SurfPhase(const std::string& infile, const std::string& id);
//! Construct and initialize a SurfPhase ThermoPhase object
//! directly from an XML database

View file

@ -75,7 +75,7 @@ DebyeHuckel::DebyeHuckel(XML_Node& phaseRoot, const std::string& id_) :
m_densWaterSS(1000.),
m_waterProps(0)
{
importPhase(*findXMLPhase(&phaseRoot, id_), this);
importPhase(phaseRoot, this);
}
DebyeHuckel::DebyeHuckel(const DebyeHuckel& b) :

View file

@ -30,43 +30,14 @@ FixedChemPotSSTP::FixedChemPotSSTP() :
{
}
FixedChemPotSSTP::FixedChemPotSSTP(const std::string& infile, std::string id_) :
FixedChemPotSSTP::FixedChemPotSSTP(const std::string& infile, const std::string& id_) :
chemPot_(0.0)
{
XML_Node* root = get_XML_File(infile);
if (id_ == "-") {
id_ = "";
}
XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
if (!xphase) {
throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
"Couldn't find phase name in file:" + id_);
}
// Check the model name to ensure we have compatibility
const XML_Node& th = xphase->child("thermo");
std::string model = th["model"];
if (model != "StoichSubstance" && model != "StoichSubstanceSSTP" && model != "FixedChemPot") {
throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
"thermo model attribute must be FixedChemPot or StoichSubstance");
}
importPhase(*xphase, this);
initThermoFile(infile, id_);
}
FixedChemPotSSTP::FixedChemPotSSTP(XML_Node& xmlphase, const std::string& id_) :
chemPot_(0.0)
{
if (id_ != "") {
std::string idxml = xmlphase["id"];
if (id_ != idxml) {
throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
"id's don't match");
}
}
const XML_Node& th = xmlphase.child("thermo");
std::string model = th["model"];
if (model != "StoichSubstance" && model != "StoichSubstanceSSTP" && model != "FixedChemPotSSTP") {
throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
"thermo model attribute must be StoichSubstance or FixedChemPot");
}
importPhase(xmlphase, this);
}

View file

@ -165,7 +165,7 @@ HMWSoln::HMWSoln(XML_Node& phaseRoot, const std::string& id_) :
m_last_is(-1.0),
m_debugCalc(0)
{
importPhase(*findXMLPhase(&phaseRoot, id_), this);
importPhase(phaseRoot, this);
}
HMWSoln::HMWSoln(const HMWSoln& b) :

View file

@ -125,7 +125,7 @@ IdealMolalSoln::IdealMolalSoln(XML_Node& root, const std::string& id_) :
IMS_agCut_(0.0),
IMS_bgCut_(0.0)
{
importPhase(*findXMLPhase(&root, id_), this);
importPhase(root, this);
}
ThermoPhase* IdealMolalSoln::duplMyselfAsThermoPhase() const

View file

@ -55,7 +55,7 @@ IdealSolidSolnPhase::IdealSolidSolnPhase(XML_Node& root, const std::string& id_,
throw CanteraError(" IdealSolidSolnPhase Constructor",
" Illegal value of formGC");
}
importPhase(*findXMLPhase(&root, id_), this);
importPhase(root, this);
}
IdealSolidSolnPhase::IdealSolidSolnPhase(const IdealSolidSolnPhase& b)

View file

@ -55,7 +55,7 @@ LatticePhase::LatticePhase(const std::string& inputFile, const std::string& id_)
LatticePhase::LatticePhase(XML_Node& phaseRef, const std::string& id_)
{
importPhase(*findXMLPhase(&phaseRef, id_), this);
importPhase(phaseRef, this);
}
ThermoPhase* LatticePhase::duplMyselfAsThermoPhase() const

View file

@ -39,7 +39,7 @@ MargulesVPSSTP::MargulesVPSSTP(XML_Node& phaseRoot, const std::string& id_) :
formMargules_(0),
formTempModel_(0)
{
importPhase(*findXMLPhase(&phaseRoot, id_), this);
importPhase(phaseRoot, this);
}
MargulesVPSSTP::MargulesVPSSTP(const MargulesVPSSTP& b)

View file

@ -29,43 +29,15 @@ MetalSHEelectrons::MetalSHEelectrons():
{
}
MetalSHEelectrons::MetalSHEelectrons(const std::string& infile, std::string id_) :
MetalSHEelectrons::MetalSHEelectrons(const std::string& infile, const std::string& id_) :
xdef_(0)
{
XML_Node* root;
if (infile == "MetalSHEelectrons_default.xml") {
xdef_ = MetalSHEelectrons::makeDefaultXMLTree();
root = xdef_;
} else {
root = get_XML_File(infile);
}
if (id_ == "-") {
id_ = "";
}
XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
if (!xphase) {
throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
"Couldn't find phase name in file:" + id_);
}
// Check the model name to ensure we have compatibility
if (xphase->child("thermo")["model"] != "MetalSHEelectrons") {
throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
"thermo model attribute must be MetalSHEelectrons");
}
importPhase(*xphase, this);
initThermoFile(infile, id_);
}
MetalSHEelectrons::MetalSHEelectrons(XML_Node& xmlphase, const std::string& id_) :
xdef_(0)
{
if (id_ != "" && id_ != xmlphase["id"]) {
throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
"id's don't match");
}
if (xmlphase.child("thermo")["model"] != "MetalSHEelectrons") {
throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
"thermo model attribute must be MetalSHEelectrons");
}
importPhase(xmlphase, this);
}

View file

@ -27,37 +27,13 @@ namespace Cantera
* ---- Constructors -------
*/
MineralEQ3::MineralEQ3(const std::string& infile, std::string id_)
MineralEQ3::MineralEQ3(const std::string& infile, const std::string& id_)
{
XML_Node* root = get_XML_File(infile);
if (id_ == "-") {
id_ = "";
}
XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
if (!xphase) {
throw CanteraError("MineralEQ3::MineralEQ3",
"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 != "MineralEQ3") {
throw CanteraError("MineralEQ3::MineralEQ3",
"thermo model attribute must be StoichSubstance");
}
importPhase(*xphase, this);
initThermoFile(infile, id_);
}
MineralEQ3::MineralEQ3(XML_Node& xmlphase, const std::string& id_)
{
if (id_ != "" && id_ != xmlphase["id"]) {
throw CanteraError("MineralEQ3::MineralEQ3",
"id's don't match");
}
std::string model = xmlphase.child("thermo")["model"];
if (model != "StoichSubstance" && model != "MineralEQ3") {
throw CanteraError("MineralEQ3::MineralEQ3",
"thermo model attribute must be StoichSubstance");
}
importPhase(xmlphase, this);
}

View file

@ -42,7 +42,7 @@ MixedSolventElectrolyte::MixedSolventElectrolyte(XML_Node& phaseRoot,
formMargules_(0),
formTempModel_(0)
{
importPhase(*findXMLPhase(&phaseRoot, id_), this);
importPhase(phaseRoot, this);
}
MixedSolventElectrolyte::MixedSolventElectrolyte(const MixedSolventElectrolyte& b)

View file

@ -52,7 +52,7 @@ MolarityIonicVPSSTP::MolarityIonicVPSSTP(XML_Node& phaseRoot,
indexSpecialSpecies_(npos),
neutralPBindexStart(0)
{
importPhase(*findXMLPhase(&phaseRoot, id_), this);
importPhase(phaseRoot, this);
}
MolarityIonicVPSSTP::MolarityIonicVPSSTP(const MolarityIonicVPSSTP& b) :

View file

@ -38,7 +38,7 @@ PhaseCombo_Interaction::PhaseCombo_Interaction(XML_Node& phaseRoot,
formMargules_(0),
formTempModel_(0)
{
importPhase(*findXMLPhase(&phaseRoot, id_), this);
importPhase(phaseRoot, this);
}
PhaseCombo_Interaction::PhaseCombo_Interaction(const PhaseCombo_Interaction& b)

View file

@ -42,7 +42,7 @@ RedlichKisterVPSSTP::RedlichKisterVPSSTP(XML_Node& phaseRoot,
formRedlichKister_(0),
formTempModel_(0)
{
importPhase(*findXMLPhase(&phaseRoot, id_), this);
importPhase(phaseRoot, this);
}
RedlichKisterVPSSTP::RedlichKisterVPSSTP(const RedlichKisterVPSSTP& b) :

View file

@ -39,7 +39,7 @@ RedlichKwongMFTP::RedlichKwongMFTP() :
{
}
RedlichKwongMFTP::RedlichKwongMFTP(const std::string& infile, std::string id_) :
RedlichKwongMFTP::RedlichKwongMFTP(const std::string& infile, const std::string& id_) :
m_standardMixingRules(0),
m_formTempParam(0),
m_b_current(0.0),
@ -48,16 +48,7 @@ RedlichKwongMFTP::RedlichKwongMFTP(const std::string& infile, std::string id_) :
dpdV_(0.0),
dpdT_(0.0)
{
XML_Node* root = get_XML_File(infile);
if (id_ == "-") {
id_ = "";
}
XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
if (!xphase) {
throw CanteraError("newPhase",
"Couldn't find phase named \"" + id_ + "\" in file, " + infile);
}
importPhase(*xphase, this);
initThermoFile(infile, id_);
}
RedlichKwongMFTP::RedlichKwongMFTP(XML_Node& phaseRefRoot, const std::string& id_) :
@ -69,11 +60,7 @@ RedlichKwongMFTP::RedlichKwongMFTP(XML_Node& phaseRefRoot, const std::string& id
dpdV_(0.0),
dpdT_(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");
}
importPhase(*xphase, this);
importPhase(phaseRefRoot, this);
}
RedlichKwongMFTP::RedlichKwongMFTP(const RedlichKwongMFTP& b) :

View file

@ -24,26 +24,13 @@ namespace Cantera
* ---- Constructors -------
*/
StoichSubstanceSSTP::StoichSubstanceSSTP(const std::string& infile, std::string id_)
StoichSubstanceSSTP::StoichSubstanceSSTP(const std::string& infile, const std::string& id_)
{
XML_Node* root = get_XML_File(infile);
if (id_ == "-") {
id_ = "";
}
XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
if (!xphase) {
throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
"Couldn't find phase name in file:" + id_);
}
importPhase(*xphase, this);
initThermoFile(infile, id_);
}
StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, const std::string& id_)
{
if (id_ != "" && id_ != xmlphase["id"]) {
throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
"id's don't match");
}
importPhase(xmlphase, this);
}

View file

@ -25,35 +25,15 @@ SurfPhase::SurfPhase(doublereal n0):
setNDim(2);
}
SurfPhase::SurfPhase(const std::string& infile, std::string id_) :
SurfPhase::SurfPhase(const std::string& infile, const std::string& id_) :
m_press(OneAtm)
{
XML_Node* root = get_XML_File(infile);
if (id_ == "-") {
id_ = "";
}
XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
if (!xphase) {
throw CanteraError("SurfPhase::SurfPhase",
"Couldn't find phase name in file:" + id_);
}
// Check the model name to ensure we have compatibility
string model = xphase->child("thermo")["model"];
if (model != "Surface" && model != "Edge") {
throw CanteraError("SurfPhase::SurfPhase",
"thermo model attribute must be Surface or Edge");
}
importPhase(*xphase, this);
initThermoFile(infile, id_);
}
SurfPhase::SurfPhase(XML_Node& xmlphase) :
m_press(OneAtm)
{
string model = xmlphase.child("thermo")["model"];
if (model != "Surface" && model != "Edge") {
throw CanteraError("SurfPhase::SurfPhase",
"thermo model attribute must be Surface or Edge");
}
importPhase(xmlphase, this);
}

View file

@ -51,7 +51,7 @@ WaterSSTP::WaterSSTP(XML_Node& phaseRoot, const std::string& id) :
m_ready(false),
m_allowGasPhase(false)
{
importPhase(*findXMLPhase(&phaseRoot, id), this);
importPhase(phaseRoot, this);
}
WaterSSTP::WaterSSTP(const WaterSSTP& b) :