From 1d4480db101b1e484e04d1e87da0a181463fc725 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sun, 28 Dec 2008 04:56:09 +0000 Subject: [PATCH] Added an electrodeElectron ThermoPhase. --- Cantera/src/thermo/SpeciesThermoFactory.cpp | 40 +++++- Cantera/src/thermo/StoichSubstanceSSTP.cpp | 129 +++++++++++++++++++- Cantera/src/thermo/StoichSubstanceSSTP.h | 52 +++++++- Cantera/src/thermo/ThermoFactory.cpp | 12 +- Cantera/src/thermo/mix_defs.h | 1 + 5 files changed, 222 insertions(+), 12 deletions(-) diff --git a/Cantera/src/thermo/SpeciesThermoFactory.cpp b/Cantera/src/thermo/SpeciesThermoFactory.cpp index 2e3f52145..a23398f32 100755 --- a/Cantera/src/thermo/SpeciesThermoFactory.cpp +++ b/Cantera/src/thermo/SpeciesThermoFactory.cpp @@ -272,6 +272,16 @@ namespace Cantera { tmin0 = fpValue(f0["Tmin"]); tmax0 = fpValue(f0["Tmax"]); + + doublereal p0 = OneAtm; + if (f0.hasAttrib("P0")) { + p0 = fpValue(f0["P0"]); + } + if (f0.hasAttrib("Pref")) { + p0 = fpValue(f0["Pref"]); + } + p0 = OneAtm; + tmin1 = tmax0; tmax1 = tmin1 + 0.0001; if (dualRange) { @@ -311,7 +321,7 @@ namespace Cantera { // coefficients in a different order, so rearrange them. array_fp c(15); c[0] = tmid; - doublereal p0 = OneAtm; + c[1] = c0[5]; c[2] = c0[6]; copy(c0.begin(), c0.begin()+5, c.begin() + 3); @@ -344,6 +354,15 @@ namespace Cantera { tmax1 = fpValue((*f1ptr)["Tmax"]); } + + doublereal p0 = OneAtm; + if (f0.hasAttrib("P0")) { + p0 = fpValue(f0["P0"]); + } + if (f0.hasAttrib("Pref")) { + p0 = fpValue(f0["Pref"]); + } + vector_fp c0, c1; if (fabs(tmax0 - tmin1) < 0.01) { tmin = tmin0; @@ -370,7 +389,6 @@ namespace Cantera { } array_fp c(15); c[0] = tmid; - doublereal p0 = OneAtm; c[1] = c0[5]; c[2] = c0[6]; copy(c0.begin(), c0.begin()+5, c.begin() + 3); @@ -611,7 +629,7 @@ namespace Cantera { vector_fp cPoly; Nasa9Poly1 *np_ptr = 0; std::vector regionPtrs; - doublereal tmin, tmax, pref; + doublereal tmin, tmax, pref = OneAtm; // Loop over all of the possible temperature regions for (int i = 0; i < nRegTmp; i++) { fptr = tp[i]; @@ -621,7 +639,12 @@ namespace Cantera { tmin = fpValue((*fptr)["Tmin"]); tmax = fpValue((*fptr)["Tmax"]); - pref = fpValue((*fptr)["P0"]); + if ((*fptr).hasAttrib("P0")) { + pref = fpValue((*fptr)["P0"]); + } + if ((*fptr).hasAttrib("Pref")) { + pref = fpValue((*fptr)["Pref"]); + } getFloatArray(fptr->child("floatArray"), cPoly, false); if (cPoly.size() != 9) { @@ -659,11 +682,16 @@ namespace Cantera { SpeciesThermo& sp, int k, const XML_Node& f) { vector_fp freqs; - doublereal tmin, tmax, pref; + doublereal tmin, tmax, pref = OneAtm; int nfreq = 0; tmin = fpValue(f["Tmin"]); tmax = fpValue(f["Tmax"]); - pref = fpValue(f["P0"]); + if (f.hasAttrib("P0")) { + pref = fpValue(f["P0"]); + } + if (f.hasAttrib("Pref")) { + pref = fpValue(f["Pref"]); + } if (tmax == 0.0) tmax = 1.0e30; if (f.hasChild("floatArray")) { diff --git a/Cantera/src/thermo/StoichSubstanceSSTP.cpp b/Cantera/src/thermo/StoichSubstanceSSTP.cpp index e855b295e..baebef116 100644 --- a/Cantera/src/thermo/StoichSubstanceSSTP.cpp +++ b/Cantera/src/thermo/StoichSubstanceSSTP.cpp @@ -424,6 +424,21 @@ namespace Cantera { SingleSpeciesTP::initThermo(); } + + void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, std::string id) { + /* + * Find the Thermo XML node + */ + if (!phaseNode.hasChild("thermo")) { + throw CanteraError("StoichSubstanceSSTP::initThermoXML", + "no thermo XML node"); + } + XML_Node &tnode = phaseNode.child("thermo"); + double dens = getFloatDefaultUnits(tnode, "density", "kg/m3"); + setDensity(dens); + SingleSpeciesTP::initThermoXML(phaseNode, id); + } + /** * setParameters: * @@ -464,13 +479,125 @@ namespace Cantera { void StoichSubstanceSSTP::setParametersFromXML(const XML_Node& eosdata) { std::string model = eosdata["model"]; if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { - throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP", + throw CanteraError("StoichSubstanceSSTP::setParametersFromXML", "thermo model attribute must be StoichSubstance"); } doublereal rho = getFloat(eosdata, "density", "toSI"); setDensity(rho); } + + + + + /* + * Default Constructor for the electrodeElectron class + */ + electrodeElectron::electrodeElectron(): + StoichSubstanceSSTP() + { + } + + // Create and initialize a electrodeElectron 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. + */ + electrodeElectron::electrodeElectron(std::string infile, std::string id) : + StoichSubstanceSSTP() + { + 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("electrodeElectron::electrodeElectron", + "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 != "electrodeElectron") { + throw CanteraError("electrodeElectron::electrodeElectron", + "thermo model attribute must be electrodeElectron"); + } + importPhase(*xphase, this); + } + + // Full Constructor. + /* + * @param phaseRef XML node pointing to a electrodeElectron description + * @param id Id of the phase. + */ + electrodeElectron::electrodeElectron(XML_Node& xmlphase, std::string id) : + StoichSubstanceSSTP() + { + if (id != "") { + std::string idxml = xmlphase["id"]; + if (id != idxml) { + throw CanteraError("electrodeElectron::electrodeElectron", + "id's don't match"); + } + } + const XML_Node& th = xmlphase.child("thermo"); + std::string model = th["model"]; + if (model != "electrodeElectron") { + throw CanteraError("electrodeElectron::electrodeElectron", + "thermo model attribute must be electrodeElectron"); + } + importPhase(xmlphase, this); + } + + //! Copy constructor + /*! + * @param right Object to be copied + */ + electrodeElectron::electrodeElectron(const electrodeElectron &right) : + StoichSubstanceSSTP() + { + *this = operator=(right); + } + + //! Assignment operator + /*! + * @param right Object to be copied + */ + electrodeElectron & + electrodeElectron::operator=(const electrodeElectron & right) { + if (&right != this) { + StoichSubstanceSSTP::operator=(right); + } + return *this; + } + + /* + * Destructor for the routine (virtual) + * + */ + electrodeElectron::~electrodeElectron() + { + } + + void electrodeElectron::setParametersFromXML(const XML_Node& eosdata) { + std::string model = eosdata["model"]; + if (model != "electrodeElectron") { + throw CanteraError("electrodeElectron::setParametersFromXML", + "thermo model attribute must be electrodeElectron"); + } + } + + void electrodeElectron::initThermoXML(XML_Node& phaseNode, std::string id) { + doublereal rho = 10.0; + setDensity(rho); + SingleSpeciesTP::initThermoXML(phaseNode, id); + } + + void electrodeElectron::setParameters(int n, doublereal * const c) { + doublereal rho = 10.0; + setDensity(rho); + } + } diff --git a/Cantera/src/thermo/StoichSubstanceSSTP.h b/Cantera/src/thermo/StoichSubstanceSSTP.h index 71cb6d537..834c29d97 100644 --- a/Cantera/src/thermo/StoichSubstanceSSTP.h +++ b/Cantera/src/thermo/StoichSubstanceSSTP.h @@ -159,8 +159,8 @@ namespace Cantera { @endverbatim * - * The model attribute, "StoichSubstanceSSTP", on the thermo element identifies the phase as being - * a StoichSubstanceSSTP object. + * The model attribute, "StoichSubstanceSSTP", on the thermo element + * identifies the phase as being a StoichSubstanceSSTP object. * * @ingroup thermoprops */ @@ -470,6 +470,9 @@ namespace Cantera { */ virtual void initThermo(); + + virtual void initThermoXML(XML_Node& phaseNode, std::string id); + //! Set the equation of state parameters /*! * @internal @@ -523,7 +526,52 @@ namespace Cantera { protected: }; + + + class electrodeElectron : public StoichSubstanceSSTP { + public: + //! Default constructor for the electrodeElectron class + electrodeElectron(); + + //! Construct and initialize a electrodeElectron 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. + */ + electrodeElectron(std::string infile, std::string id = ""); + + //! Construct and initialize a electrodeElectron ThermoPhase object + //! directly from an XML database + /*! + * @param phaseRef XML node pointing to a electrodeElectron description + * @param id Id of the phase. + */ + electrodeElectron(XML_Node& phaseRef, std::string id = ""); + + //! Copy constructor + /*! + * @param right Object to be copied + */ + electrodeElectron(const electrodeElectron &right); + //! Assignment operator + /*! + * @param right Object to be copied + */ + electrodeElectron & operator=(const electrodeElectron & right); + + //! Destructor for the routine (virtual) + virtual ~electrodeElectron(); + + void setParametersFromXML(const XML_Node& eosdata); + + virtual void initThermoXML(XML_Node& phaseNode, std::string id); + + void setParameters(int n, doublereal * const c); + }; + } #endif diff --git a/Cantera/src/thermo/ThermoFactory.cpp b/Cantera/src/thermo/ThermoFactory.cpp index e6fb07791..48d6e1191 100644 --- a/Cantera/src/thermo/ThermoFactory.cpp +++ b/Cantera/src/thermo/ThermoFactory.cpp @@ -83,13 +83,13 @@ namespace Cantera { boost::mutex ThermoFactory::thermo_mutex; #endif - static int ntypes = 15; + static int ntypes = 16; static string _types[] = {"IdealGas", "Incompressible", "Surface", "Edge", "Metal", "StoichSubstance", "PureFluid", "LatticeSolid", "Lattice", "HMW", "IdealSolidSolution", "DebyeHuckel", "IdealMolalSolution", "IdealGasVPSS", - "MineralEQ3" + "MineralEQ3", "electrodeElectron" }; static int _itypes[] = {cIdealGas, cIncompressible, @@ -97,7 +97,7 @@ namespace Cantera { cPureFluid, cLatticeSolid, cLattice, cHMW, cIdealSolidSolnPhase, cDebyeHuckel, cIdealMolalSoln, cVPSS_IdealGas, - cMineralEQ3 + cMineralEQ3, cElectrodeElectron }; /* @@ -158,6 +158,12 @@ namespace Cantera { break; #endif +#ifdef WITH_STOICH_SUBSTANCE + case cElectrodeElectron: + th = new electrodeElectron(); + break; +#endif + #ifdef WITH_LATTICE_SOLID case cLatticeSolid: th = new LatticeSolidPhase; diff --git a/Cantera/src/thermo/mix_defs.h b/Cantera/src/thermo/mix_defs.h index 47392fd23..32e72bf12 100755 --- a/Cantera/src/thermo/mix_defs.h +++ b/Cantera/src/thermo/mix_defs.h @@ -44,6 +44,7 @@ namespace Cantera { const int cSemiconductor = 7; const int cMineralEQ3 = 8; // MineralEQ3 in MineralEQ3.h + const int cElectrodeElectron = 9; // electrodeElectron const int cLatticeSolid = 20; // LatticeSolidPhase.h const int cLattice = 21;