From 6abac36cad2fcc02fb2c91775a41aba1025d02bf Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Thu, 20 Dec 2007 20:39:51 +0000 Subject: [PATCH] Added a few constructor routines, directly from file strings. --- Cantera/src/thermo/HMWSoln.h | 6 ++-- Cantera/src/thermo/IdealSolidSolnPhase.h | 14 ++++---- Cantera/src/thermo/StoichSubstanceSSTP.cpp | 39 ++++++++++++++++++-- Cantera/src/thermo/StoichSubstanceSSTP.h | 24 +++++++++---- Cantera/src/thermo/SurfPhase.cpp | 41 ++++++++++++++++++++-- Cantera/src/thermo/SurfPhase.h | 12 ++++++- Cantera/src/thermo/ThermoFactory.h | 3 +- 7 files changed, 115 insertions(+), 24 deletions(-) diff --git a/Cantera/src/thermo/HMWSoln.h b/Cantera/src/thermo/HMWSoln.h index 9a749c43f..2cbf6c98b 100644 --- a/Cantera/src/thermo/HMWSoln.h +++ b/Cantera/src/thermo/HMWSoln.h @@ -1200,7 +1200,8 @@ namespace Cantera { //! Default Constructor HMWSoln(); - //! Full constructor for setting up the entire ThermoPhase Object + //! Construct and initialize an HMWSoln ThermoPhase object + //! directly from an asci input file /*! * Working constructors * @@ -1216,7 +1217,8 @@ namespace Cantera { */ HMWSoln(std::string inputFile, std::string id = ""); - //! Full constructor for creating the phase. + //! Construct and initialize an HMWSoln ThermoPhase object + //! directly from an XML database /*! * @param phaseRef XML phase node containing the description of the phase * @param id id attribute containing the name of the phase. diff --git a/Cantera/src/thermo/IdealSolidSolnPhase.h b/Cantera/src/thermo/IdealSolidSolnPhase.h index cb00b0737..3f3edc537 100644 --- a/Cantera/src/thermo/IdealSolidSolnPhase.h +++ b/Cantera/src/thermo/IdealSolidSolnPhase.h @@ -88,8 +88,10 @@ namespace Cantera { */ IdealSolidSolnPhase(int formCG=0); - /** - * Constructor for IdealSolidSolnPhase. + + //! Construct and initialize an IdealSolidSolnPhase ThermoPhase object + //! directly from an asci input file + /*! * * This constructor will also fully initialize the object. * The generalized concentrations can have three different forms @@ -112,11 +114,9 @@ namespace Cantera { */ IdealSolidSolnPhase(std::string infile, std::string id="", int formCG=0); - - /** - * Constructor for IdealSolidSolnPhase. - * This constructor will also fully initialize the object. - * + //! Construct and initialize an IdealSolidSolnPhase ThermoPhase object + //! directly from an XML database + /*! * The generalized concentrations can have three different forms * depending on the value of the member attribute m_formGC, which * is supplied in the constructor and/or read from the data file. diff --git a/Cantera/src/thermo/StoichSubstanceSSTP.cpp b/Cantera/src/thermo/StoichSubstanceSSTP.cpp index 034c99118..41452a740 100644 --- a/Cantera/src/thermo/StoichSubstanceSSTP.cpp +++ b/Cantera/src/thermo/StoichSubstanceSSTP.cpp @@ -39,12 +39,41 @@ namespace Cantera { { } + // Create and initialize a StoichSubstanceSSTP ThermoPhase object + // from an asci input file + /* + * @param infile name of the input file + * @param id name of the phase id in the file. + * If this is blank, the first phase in the file is used. + */ + StoichSubstanceSSTP::StoichSubstanceSSTP(std::string infile, std::string id) : + SingleSpeciesTP() + { + 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); + } + // 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") { + throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP", + "thermo model attribute must be StoichSubstance"); + } + importPhase(*xphase, this); + } + // Full Constructor. /* * @param phaseRef XML node pointing to a StoichSubstanceSSTP description * @param id Id of the phase. */ - StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, std::string id) { + StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, std::string id) : + SingleSpeciesTP() + { if (id != "") { std::string idxml = xmlphase["id"]; if (id != idxml) { @@ -54,7 +83,7 @@ namespace Cantera { } const XML_Node& th = xmlphase.child("thermo"); std::string model = th["model"]; - if (model != "StoichSubstanceSSTP") { + if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP", "thermo model attribute must be StoichSubstance"); } @@ -433,7 +462,11 @@ namespace Cantera { * */ void StoichSubstanceSSTP::setParametersFromXML(const XML_Node& eosdata) { - eosdata._require("model","StoichSubstanceSSTP"); + std::string model = eosdata["model"]; + if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { + throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP", + "thermo model attribute must be StoichSubstance"); + } doublereal rho = getFloat(eosdata, "density", "-"); setDensity(rho); } diff --git a/Cantera/src/thermo/StoichSubstanceSSTP.h b/Cantera/src/thermo/StoichSubstanceSSTP.h index f0759366f..0feeaa6a5 100644 --- a/Cantera/src/thermo/StoichSubstanceSSTP.h +++ b/Cantera/src/thermo/StoichSubstanceSSTP.h @@ -26,12 +26,12 @@ namespace Cantera { - //! Class %StoichSubstanceSSTP represents a stoichiometric (fixed composition) - //! incompressible substance. - /*! + //! Class %StoichSubstanceSSTP represents a stoichiometric (fixed + //! composition) incompressible substance. + /*! * This class internally changes the independent degree of freedom from - * density to pressure. This is necessary because the phase is incompressible. - * It uses a constant volume approximation. + * density to pressure. This is necessary because the phase is + * incompressible. It uses a constant volume approximation. * * * Specification of Species Standard %State Properties @@ -168,10 +168,20 @@ namespace Cantera { public: - //! Default Constructor for the StoichSubstanceSSTP class + //! Default constructor for the StoichSubstanceSSTP class StoichSubstanceSSTP(); - //! Full Constructor. + //! Construct and initialize a StoichSubstanceSSTP ThermoPhase object + //! directly from an asci input file + /*! + * @param infile name of the input file + * @param id name of the phase id in the file. + * If this is blank, the first phase in the file is used. + */ + StoichSubstanceSSTP(std::string infile, std::string id = ""); + + //! Construct and initialize a StoichSubstanceSSTP ThermoPhase object + //! directly from an XML database /*! * @param phaseRef XML node pointing to a StoichSubstanceSSTP description * @param id Id of the phase. diff --git a/Cantera/src/thermo/SurfPhase.cpp b/Cantera/src/thermo/SurfPhase.cpp index 2eecb791e..82b32b417 100644 --- a/Cantera/src/thermo/SurfPhase.cpp +++ b/Cantera/src/thermo/SurfPhase.cpp @@ -46,12 +46,47 @@ namespace Cantera { setNDim(2); } - SurfPhase::SurfPhase(XML_Node& xmlphase) { + SurfPhase::SurfPhase(std::string infile, std::string id) : + ThermoPhase(), + m_n0(0.0), + m_logn0(0.0), + m_tmin(0.0), + m_tmax(0.0), + m_press(OneAtm), + m_tlast(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("SurfPhase::SurfPhase", + "Couldn't find phase name in file:" + id); + } + // Check the model name to ensure we have compatibility + const XML_Node& th = xphase->child("thermo"); + string model = th["model"]; + if (model != "Surface" && model != "Edge") { + throw CanteraError("SurfPhase::SurfPhase", + "thermo model attribute must be Surface or Edge"); + } + importPhase(*xphase, this); + } + + + SurfPhase::SurfPhase(XML_Node& xmlphase) : + ThermoPhase(), + m_n0(0.0), + m_logn0(0.0), + m_tmin(0.0), + m_tmax(0.0), + m_press(OneAtm), + m_tlast(0.0) + { const XML_Node& th = xmlphase.child("thermo"); string model = th["model"]; - if (model != "Surface") { + if (model != "Surface" && model != "Edge") { throw CanteraError("SurfPhase::SurfPhase", - "thermo model attribute must be Surface"); + "thermo model attribute must be Surface or Edge"); } importPhase(xmlphase, this); } diff --git a/Cantera/src/thermo/SurfPhase.h b/Cantera/src/thermo/SurfPhase.h index 55358f863..46e3c9c9b 100644 --- a/Cantera/src/thermo/SurfPhase.h +++ b/Cantera/src/thermo/SurfPhase.h @@ -161,7 +161,17 @@ namespace Cantera { */ SurfPhase(doublereal n0 = 0.0); - //! Constructor. + //! Construct and initialize a SurfPhase ThermoPhase object + //! directly from an asci input file + /*! + * @param infile name of the input file + * @param id name of the phase id in the file. + * If this is blank, the first phase in the file is used. + */ + SurfPhase(std::string infile, std::string id); + + //! Construct and initialize a SurfPhase ThermoPhase object + //! directly from an XML database /*! * @param xmlphase XML node pointing to a SurfPhase description */ diff --git a/Cantera/src/thermo/ThermoFactory.h b/Cantera/src/thermo/ThermoFactory.h index f107d897c..8a526ea1b 100644 --- a/Cantera/src/thermo/ThermoFactory.h +++ b/Cantera/src/thermo/ThermoFactory.h @@ -168,7 +168,8 @@ namespace Cantera { /*! * This routine is a wrapper around the newPhase(XML_Node) routine * which does the work. The wrapper locates the input phase XML_Node - * in a file. + * in a file, and then instantiates the object, returning the pointer + * to the ThermoPhase object. * * @param infile name of the input file * @param id name of the phase id in the file.