diff --git a/include/cantera/thermo/FixedChemPotSSTP.h b/include/cantera/thermo/FixedChemPotSSTP.h index 6034a4ce8..45142e38e 100644 --- a/include/cantera/thermo/FixedChemPotSSTP.h +++ b/include/cantera/thermo/FixedChemPotSSTP.h @@ -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 diff --git a/include/cantera/thermo/MetalSHEelectrons.h b/include/cantera/thermo/MetalSHEelectrons.h index a1a1bc680..9fe3df2fb 100644 --- a/include/cantera/thermo/MetalSHEelectrons.h +++ b/include/cantera/thermo/MetalSHEelectrons.h @@ -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 diff --git a/include/cantera/thermo/MineralEQ3.h b/include/cantera/thermo/MineralEQ3.h index 56b57cf19..e608405a4 100644 --- a/include/cantera/thermo/MineralEQ3.h +++ b/include/cantera/thermo/MineralEQ3.h @@ -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 diff --git a/include/cantera/thermo/RedlichKwongMFTP.h b/include/cantera/thermo/RedlichKwongMFTP.h index d0dbc05bb..36eb15296 100644 --- a/include/cantera/thermo/RedlichKwongMFTP.h +++ b/include/cantera/thermo/RedlichKwongMFTP.h @@ -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 diff --git a/include/cantera/thermo/StoichSubstanceSSTP.h b/include/cantera/thermo/StoichSubstanceSSTP.h index c50a3c1bf..a97b1308f 100644 --- a/include/cantera/thermo/StoichSubstanceSSTP.h +++ b/include/cantera/thermo/StoichSubstanceSSTP.h @@ -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 diff --git a/include/cantera/thermo/SurfPhase.h b/include/cantera/thermo/SurfPhase.h index 2f223e2d7..97c07b696 100644 --- a/include/cantera/thermo/SurfPhase.h +++ b/include/cantera/thermo/SurfPhase.h @@ -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 diff --git a/src/thermo/DebyeHuckel.cpp b/src/thermo/DebyeHuckel.cpp index e0ced1e4c..8f3311137 100644 --- a/src/thermo/DebyeHuckel.cpp +++ b/src/thermo/DebyeHuckel.cpp @@ -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) : diff --git a/src/thermo/FixedChemPotSSTP.cpp b/src/thermo/FixedChemPotSSTP.cpp index 6ea13ed75..dd1e092d8 100644 --- a/src/thermo/FixedChemPotSSTP.cpp +++ b/src/thermo/FixedChemPotSSTP.cpp @@ -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); } diff --git a/src/thermo/HMWSoln.cpp b/src/thermo/HMWSoln.cpp index 2d01c786d..228045646 100644 --- a/src/thermo/HMWSoln.cpp +++ b/src/thermo/HMWSoln.cpp @@ -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) : diff --git a/src/thermo/IdealMolalSoln.cpp b/src/thermo/IdealMolalSoln.cpp index 4fdad07fb..8db61327e 100644 --- a/src/thermo/IdealMolalSoln.cpp +++ b/src/thermo/IdealMolalSoln.cpp @@ -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 diff --git a/src/thermo/IdealSolidSolnPhase.cpp b/src/thermo/IdealSolidSolnPhase.cpp index 6ba032378..abb5f505a 100644 --- a/src/thermo/IdealSolidSolnPhase.cpp +++ b/src/thermo/IdealSolidSolnPhase.cpp @@ -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) diff --git a/src/thermo/LatticePhase.cpp b/src/thermo/LatticePhase.cpp index 438e5d60e..a42d7578f 100644 --- a/src/thermo/LatticePhase.cpp +++ b/src/thermo/LatticePhase.cpp @@ -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 diff --git a/src/thermo/MargulesVPSSTP.cpp b/src/thermo/MargulesVPSSTP.cpp index 996d608b5..b10b6f6ed 100644 --- a/src/thermo/MargulesVPSSTP.cpp +++ b/src/thermo/MargulesVPSSTP.cpp @@ -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) diff --git a/src/thermo/MetalSHEelectrons.cpp b/src/thermo/MetalSHEelectrons.cpp index 64e1d2d62..09b629fe3 100644 --- a/src/thermo/MetalSHEelectrons.cpp +++ b/src/thermo/MetalSHEelectrons.cpp @@ -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); } diff --git a/src/thermo/MineralEQ3.cpp b/src/thermo/MineralEQ3.cpp index ebef9986a..1594d596f 100644 --- a/src/thermo/MineralEQ3.cpp +++ b/src/thermo/MineralEQ3.cpp @@ -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); } diff --git a/src/thermo/MixedSolventElectrolyte.cpp b/src/thermo/MixedSolventElectrolyte.cpp index ba415c2e3..dc6d9d0cf 100644 --- a/src/thermo/MixedSolventElectrolyte.cpp +++ b/src/thermo/MixedSolventElectrolyte.cpp @@ -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) diff --git a/src/thermo/MolarityIonicVPSSTP.cpp b/src/thermo/MolarityIonicVPSSTP.cpp index 754c60cb3..ed189a7ba 100644 --- a/src/thermo/MolarityIonicVPSSTP.cpp +++ b/src/thermo/MolarityIonicVPSSTP.cpp @@ -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) : diff --git a/src/thermo/PhaseCombo_Interaction.cpp b/src/thermo/PhaseCombo_Interaction.cpp index bd5234eea..31324404c 100644 --- a/src/thermo/PhaseCombo_Interaction.cpp +++ b/src/thermo/PhaseCombo_Interaction.cpp @@ -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) diff --git a/src/thermo/RedlichKisterVPSSTP.cpp b/src/thermo/RedlichKisterVPSSTP.cpp index 73408ecbe..c96d57ccd 100644 --- a/src/thermo/RedlichKisterVPSSTP.cpp +++ b/src/thermo/RedlichKisterVPSSTP.cpp @@ -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) : diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index cdb72df0c..61f14fc2e 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -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) : diff --git a/src/thermo/StoichSubstanceSSTP.cpp b/src/thermo/StoichSubstanceSSTP.cpp index 19549acde..6c167a5c9 100644 --- a/src/thermo/StoichSubstanceSSTP.cpp +++ b/src/thermo/StoichSubstanceSSTP.cpp @@ -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); } diff --git a/src/thermo/SurfPhase.cpp b/src/thermo/SurfPhase.cpp index 18533e37f..2ad091b3e 100644 --- a/src/thermo/SurfPhase.cpp +++ b/src/thermo/SurfPhase.cpp @@ -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); } diff --git a/src/thermo/WaterSSTP.cpp b/src/thermo/WaterSSTP.cpp index 3388799fb..a513fa26c 100644 --- a/src/thermo/WaterSSTP.cpp +++ b/src/thermo/WaterSSTP.cpp @@ -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) :