Skip to content

Commit

Permalink
[Thermo] Use consistent implementation for convenience constructors
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
speth committed Aug 5, 2015
1 parent 7fe8f0f commit 7bcbbaa
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 157 deletions.
2 changes: 1 addition & 1 deletion include/cantera/thermo/FixedChemPotSSTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class FixedChemPotSSTP : public SingleSpeciesTP
* @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
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/MetalSHEelectrons.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class MetalSHEelectrons : public SingleSpeciesTP
* @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
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/MineralEQ3.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class MineralEQ3 : public StoichSubstanceSSTP
* @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
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/RedlichKwongMFTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RedlichKwongMFTP : public MixtureFugacityTP
* 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
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/StoichSubstanceSSTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class StoichSubstanceSSTP : public SingleSpeciesTP
* @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
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/SurfPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class SurfPhase : public ThermoPhase
* @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
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/DebyeHuckel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
33 changes: 2 additions & 31 deletions src/thermo/FixedChemPotSSTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/thermo/HMWSoln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/IdealMolalSoln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/IdealSolidSolnPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/LatticePhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/MargulesVPSSTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 2 additions & 30 deletions src/thermo/MetalSHEelectrons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
28 changes: 2 additions & 26 deletions src/thermo/MineralEQ3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/thermo/MixedSolventElectrolyte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/MolarityIonicVPSSTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/PhaseCombo_Interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/RedlichKisterVPSSTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
19 changes: 3 additions & 16 deletions src/thermo/RedlichKwongMFTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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_) :
Expand All @@ -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) :
Expand Down
17 changes: 2 additions & 15 deletions src/thermo/StoichSubstanceSSTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
24 changes: 2 additions & 22 deletions src/thermo/SurfPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/thermo/WaterSSTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down

0 comments on commit 7bcbbaa

Please sign in to comment.