From 1d7677f590fdb449f75160ce54962a7b07f5e0d1 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Mon, 15 Sep 2008 19:29:15 +0000 Subject: [PATCH] bug fix go VPSSMgr. Added a SpeciesThermoInterpType that refers to a PDSS type to calculate its reference state thermo. --- Cantera/src/thermo/GeneralSpeciesThermo.cpp | 22 +- Cantera/src/thermo/GeneralSpeciesThermo.h | 42 +++- Cantera/src/thermo/Makefile.in | 4 +- Cantera/src/thermo/SpeciesThermoFactory.cpp | 8 + .../src/thermo/SpeciesThermoInterpType.cpp | 189 ++++++++++++++++++ Cantera/src/thermo/SpeciesThermoInterpType.h | 136 ++++++++++++- Cantera/src/thermo/VPSSMgr.cpp | 17 ++ Cantera/src/thermo/VPSSMgr_Water_ConstVol.cpp | 7 + Cantera/src/thermo/speciesThermoTypes.h | 2 + 9 files changed, 407 insertions(+), 20 deletions(-) create mode 100644 Cantera/src/thermo/SpeciesThermoInterpType.cpp diff --git a/Cantera/src/thermo/GeneralSpeciesThermo.cpp b/Cantera/src/thermo/GeneralSpeciesThermo.cpp index 0a9471da8..e8eb969aa 100644 --- a/Cantera/src/thermo/GeneralSpeciesThermo.cpp +++ b/Cantera/src/thermo/GeneralSpeciesThermo.cpp @@ -211,6 +211,14 @@ namespace Cantera { m_tlow_max = max(minTemp, m_tlow_max); m_thigh_min = min(maxTemp, m_thigh_min); } + + + + void GeneralSpeciesThermo::installPDSShandler(int k, PDSS *PDSS_ptr, + VPSSMgr *vpssmgr_ptr) { + STITbyPDSS *stit_ptr = new STITbyPDSS(k, vpssmgr_ptr, PDSS_ptr); + install_STIT(stit_ptr); + } /** * Update the properties for one species. @@ -265,18 +273,16 @@ namespace Cantera { * For the NASA object, there are 15 coefficients. */ void GeneralSpeciesThermo:: - reportParams(int index, int &type, - doublereal * const c, - doublereal &minTemp, - doublereal &maxTemp, - doublereal &refPressure) const { + reportParams(int index, int &type, doublereal * const c, + doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const { SpeciesThermoInterpType *sp = m_sp[index]; int n; if (sp) { sp->reportParameters(n, type, minTemp, maxTemp, refPressure, c); if (n != index) { - throw CanteraError(" ", "confused"); + throw CanteraError("GeneralSpeciesThermo::reportParams", + "Internal error encountered"); } } else { type = -1; @@ -342,4 +348,8 @@ namespace Cantera { } + SpeciesThermoInterpType * GeneralSpeciesThermo::provideSTIT(int k) { + return (m_sp[k]); + } + } diff --git a/Cantera/src/thermo/GeneralSpeciesThermo.h b/Cantera/src/thermo/GeneralSpeciesThermo.h index b8a7505f9..0e0134b33 100644 --- a/Cantera/src/thermo/GeneralSpeciesThermo.h +++ b/Cantera/src/thermo/GeneralSpeciesThermo.h @@ -21,11 +21,10 @@ #include "NasaPoly1.h" #include "Nasa9Poly1.h" #include "speciesThermoTypes.h" -//#include "polyfit.h" + namespace Cantera { - //! A species thermodynamic property manager for a phase. /*! * This is a general manager that can handle a wide variety @@ -44,12 +43,18 @@ namespace Cantera { GeneralSpeciesThermo(); //! Copy constructor - GeneralSpeciesThermo(const GeneralSpeciesThermo &); + /*! + * @param b Object to be copied + */ + GeneralSpeciesThermo(const GeneralSpeciesThermo &b); //! Assignment operator - GeneralSpeciesThermo & operator=(const GeneralSpeciesThermo &); + /*! + * @param b Object to be copied + */ + GeneralSpeciesThermo & operator=(const GeneralSpeciesThermo &b); - //! destructor + //! Destructor virtual ~GeneralSpeciesThermo(); //! Duplicator @@ -97,6 +102,17 @@ namespace Cantera { */ virtual void install_STIT(SpeciesThermoInterpType *stit_ptr); + //! Install a PDSS object to handle the reference state thermodynamics + //! calculation + /*! + * @param k species index + * @param PDSS_ptr Pressure dependent standard state (PDSS) object + * that will handle the reference state calc + * @param vpssmgr_ptr Pointer to the variable pressure standard state + * manager that handles the PDSS object. + */ + void installPDSShandler(int k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr); + //! Like update(), but only updates the single species k. /*! * @param k species index @@ -202,6 +218,18 @@ namespace Cantera { */ virtual void modifyParams(int index, doublereal *c); + private: + //! Provide the SpeciesthermoInterpType object + /*! + * provide access to the SpeciesThermoInterpType object. + * This + * + * @param k integer parameter + * + * @return pointer to the SpeciesThermoInterpType object. + */ + SpeciesThermoInterpType * provideSTIT(int k); + protected: /** @@ -231,8 +259,10 @@ namespace Cantera { */ int m_kk; - private: + //! Make the class VPSSMgr a friend because we need to access + //! the function provideSTIT() + friend class VPSSMgr; }; diff --git a/Cantera/src/thermo/Makefile.in b/Cantera/src/thermo/Makefile.in index 20feb2ba9..3826c3398 100644 --- a/Cantera/src/thermo/Makefile.in +++ b/Cantera/src/thermo/Makefile.in @@ -34,7 +34,7 @@ THERMO_OBJ = State.o Elements.o Constituents.o Phase.o \ ThermoPhase.o IdealGasPhase.o ConstDensityThermo.o \ SpeciesThermoFactory.o ConstCpPoly.o Nasa9Poly1.o Nasa9PolyMultiTempRegion.o \ Mu0Poly.o GeneralSpeciesThermo.o SurfPhase.o \ - ThermoFactory.o phasereport.o \ + ThermoFactory.o phasereport.o SpeciesThermoInterpType.o \ VPSSMgr.o VPSSMgrFactory.o VPSSMgr_General.o IdealSolnGasVPSS.o \ VPSSMgr_IdealGas.o VPSSMgr_ConstVol.o PDSS_ConstVol.o PDSS_IdealGas.o \ @phase_object_files@ @@ -48,7 +48,7 @@ THERMO_H = State.h Elements.h Constituents.h Phase.h mix_defs.h \ SpeciesThermoInterpType.h \ GeneralSpeciesThermo.h Mu0Poly.h \ speciesThermoTypes.h SpeciesThermo.h SurfPhase.h \ - EdgePhase.h \ + EdgePhase.h \ VPSSMgr.h VPSSMgrFactory.h VPSSMgr_General.h IdealSolnGasVPSS.h \ VPSSMgr_IdealGas.h VPSSMgr_ConstVol.h PDSS_ConstVol.h PDSS_IdealGas.h \ @phase_header_files@ diff --git a/Cantera/src/thermo/SpeciesThermoFactory.cpp b/Cantera/src/thermo/SpeciesThermoFactory.cpp index b490adf46..0b4c4f557 100755 --- a/Cantera/src/thermo/SpeciesThermoFactory.cpp +++ b/Cantera/src/thermo/SpeciesThermoFactory.cpp @@ -624,6 +624,14 @@ namespace Cantera { SpeciesThermo *spthermo_ptr, const XML_Node *phaseNode_ptr) { + // Call the VPStandardStateTP object to install the pressure dependent species + // standard state into the object. + // + // We don't need to pass spthermo_ptr down, because it's already installed + // into vp_ptr. + // + // We don't need to pass vpssmgr_ptr down, because it's already installed + // into vp_ptr. vp_ptr->createInstallPDSS(k, speciesNode, phaseNode_ptr); } diff --git a/Cantera/src/thermo/SpeciesThermoInterpType.cpp b/Cantera/src/thermo/SpeciesThermoInterpType.cpp new file mode 100644 index 000000000..d153b4152 --- /dev/null +++ b/Cantera/src/thermo/SpeciesThermoInterpType.cpp @@ -0,0 +1,189 @@ +/** + * @file SpeciesThermoInterpType.cpp + * Definitions for a + */ + +/* $Author$ + * $Revision$ + * $Date$ + */ +// Copyright 2007 Sandia National Laboratories + +#include "SpeciesThermoInterpType.h" +#include "VPSSMgr.h" +#include "PDSS.h" +#include "ctexceptions.h" + +namespace Cantera { + + SpeciesThermoInterpType::SpeciesThermoInterpType() { + } + + SpeciesThermoInterpType::~SpeciesThermoInterpType() { + } + + void SpeciesThermoInterpType::updateProperties(const doublereal* tempPoly, + doublereal* cp_R, doublereal* h_RT, + doublereal* s_R) const { + double T = tempPoly[0]; + updatePropertiesTemp(T, cp_R, h_RT, s_R); + } + + /***************************************************************************************************/ + + //! Constructor + STITbyPDSS::STITbyPDSS() : + m_speciesIndex(-1) + { + } + + STITbyPDSS::STITbyPDSS(int k, VPSSMgr *vpssmgr_ptr, PDSS *PDSS_ptr) : + m_vpssmgr_ptr(vpssmgr_ptr), + m_PDSS_ptr(PDSS_ptr), + m_speciesIndex(k) + { + } + + STITbyPDSS::STITbyPDSS(const STITbyPDSS& b) : + m_vpssmgr_ptr(b.m_vpssmgr_ptr), + m_PDSS_ptr(b.m_PDSS_ptr), + m_speciesIndex(b.m_speciesIndex) + { + } + + //! Destructor + STITbyPDSS::~STITbyPDSS() { + } + + //! duplicator + SpeciesThermoInterpType * + STITbyPDSS::duplMyselfAsSpeciesThermoInterpType() const { + STITbyPDSS *np = new STITbyPDSS(*this); + return (SpeciesThermoInterpType *) np; + } + + + void STITbyPDSS::initAllPtrs(int k, VPSSMgr *vpssmgr_ptr, PDSS *PDSS_ptr) { + AssertThrow(k == m_speciesIndex, "STITbyPDSS::initAllPtrs internal confusion"); + m_vpssmgr_ptr = vpssmgr_ptr; + m_PDSS_ptr = PDSS_ptr; + } + + //! Returns the minimum temperature that the thermo + //! parameterization is valid + doublereal STITbyPDSS::minTemp() const { + // This concept needs to be put into PDSS + return 0.0; + } + + //! Returns the maximum temperature that the thermo + //! parameterization is valid + doublereal STITbyPDSS::maxTemp() const { + // This concept needs to be put into PDSS + return 0.0; + } + + //! Returns the reference pressure (Pa) + doublereal STITbyPDSS::refPressure() const { + return m_PDSS_ptr->refPressure(); + } + + //! Returns an integer representing the type of parameterization + int STITbyPDSS::reportType() const { + return PDSS_TYPE; + } + + //! Returns an integer representing the species index + int STITbyPDSS::speciesIndex() const { + return m_speciesIndex; + } + + //! Update the properties for this species, given a temperature + //! polynomial + /*! + * This method is called with a pointer to an array containing the functions of + * temperature needed by this parameterization, and three pointers to arrays where the + * computed property values should be written. This method updates only one value in + * each array. + * + * The form and length of the Temperature Polynomial may vary depending on the + * parameterization. + * + * @param tempPoly vector of temperature polynomials + * @param cp_R Vector of Dimensionless heat capacities. + * (length m_kk). + * @param h_RT Vector of Dimensionless enthalpies. + * (length m_kk). + * @param s_R Vector of Dimensionless entropies. + * (length m_kk). + */ + void STITbyPDSS::updateProperties(const doublereal* tempPoly, + doublereal* cp_R, doublereal* h_RT, + doublereal* s_R) const { + doublereal T = tempPoly[0]; + updatePropertiesTemp(T, cp_R, h_RT, s_R); + } + + //! Compute the reference-state property of one species + /*! + * Given temperature T in K, this method updates the values of + * the non-dimensional heat capacity at constant pressure, + * enthalpy, and entropy, at the reference pressure, Pref + * of one of the species. The species index is used + * to reference into the cp_R, h_RT, and s_R arrays. + * + * @param temp Temperature (Kelvin) + * @param cp_R Vector of Dimensionless heat capacities. + * (length m_kk). + * @param h_RT Vector of Dimensionless enthalpies. + * (length m_kk). + * @param s_R Vector of Dimensionless entropies. + * (length m_kk). + */ + void STITbyPDSS::updatePropertiesTemp(const doublereal temp, + doublereal* cp_R, + doublereal* h_RT, + doublereal* s_R) const { + m_vpssmgr_ptr->setState_T(temp); + AssertThrowMsg(m_speciesIndex >= 0, "STITbyPDSS::updatePropertiesTemp", + "object was probably not installed correctly"); + h_RT[m_speciesIndex] = m_PDSS_ptr->enthalpy_RT_ref(); + cp_R[m_speciesIndex] = m_PDSS_ptr->cp_R_ref(); + s_R[m_speciesIndex] = m_PDSS_ptr->entropy_R_ref(); + } + + //!This utility function reports back the type of + //! parameterization and all of the parameters for the + //! species, index. + /*! + * All parameters are output variables + * + * @param index Species index + * @param type Integer type of the standard type + * @param minTemp output - Minimum temperature + * @param maxTemp output - Maximum temperature + * @param refPressure output - reference pressure (Pa). + * @param coeffs Vector of coefficients used to set the + * parameters for the standard state. + */ + void STITbyPDSS::reportParameters(int &index, int &type, + doublereal &minTemp, doublereal &maxTemp, + doublereal &refPressure, + doublereal* const coeffs) const { + index = m_speciesIndex; + type = PDSS_TYPE; + minTemp = m_vpssmgr_ptr->minTemp(m_speciesIndex); + maxTemp = m_vpssmgr_ptr->maxTemp(m_speciesIndex); + refPressure = m_PDSS_ptr->refPressure(); + } + + //! Modify parameters for the standard state + /*! + * @param coeffs Vector of coefficients used to set the + * parameters for the standard state. + */ + void STITbyPDSS::modifyParameters(doublereal* coeffs) { + } + + +} diff --git a/Cantera/src/thermo/SpeciesThermoInterpType.h b/Cantera/src/thermo/SpeciesThermoInterpType.h index 33669fde8..9ff042d7a 100644 --- a/Cantera/src/thermo/SpeciesThermoInterpType.h +++ b/Cantera/src/thermo/SpeciesThermoInterpType.h @@ -18,6 +18,9 @@ namespace Cantera { + class PDSS; + class VPSSMgr; + //! Pure Virtual Base class for the thermoydnamic manager for //! an individual species' reference state /*! @@ -49,10 +52,10 @@ namespace Cantera { public: //! Constructor - SpeciesThermoInterpType() {}; + SpeciesThermoInterpType(); //! Destructor - virtual ~SpeciesThermoInterpType() {}; + virtual ~SpeciesThermoInterpType(); //! duplicator virtual SpeciesThermoInterpType * @@ -97,10 +100,7 @@ namespace Cantera { */ virtual void updateProperties(const doublereal* tempPoly, doublereal* cp_R, doublereal* h_RT, - doublereal* s_R) const { - double T = tempPoly[0]; - updatePropertiesTemp(T, cp_R, h_RT, s_R); - } + doublereal* s_R) const; //! Compute the reference-state property of one species /*! @@ -151,6 +151,130 @@ namespace Cantera { }; + + class STITbyPDSS : public SpeciesThermoInterpType { + + public: + + //! Constructor + STITbyPDSS(); + + + //! Constructor + + STITbyPDSS(int k, VPSSMgr *vpssmgr_ptr, PDSS *PDSS_ptr); + + + //! copy constructor + /*! + * @param b Object to be copied + */ + STITbyPDSS(const STITbyPDSS& b); + + //! Destructor + virtual ~STITbyPDSS(); + + //! duplicator + virtual SpeciesThermoInterpType *duplMyselfAsSpeciesThermoInterpType() const; + + void initAllPtrs(int k, VPSSMgr *vpssmgr_ptr, PDSS *PDSS_ptr); + + //! Returns the minimum temperature that the thermo + //! parameterization is valid + virtual doublereal minTemp() const; + + //! Returns the maximum temperature that the thermo + //! parameterization is valid + virtual doublereal maxTemp() const; + + //! Returns the reference pressure (Pa) + virtual doublereal refPressure() const; + + //! Returns an integer representing the type of parameterization + virtual int reportType() const; + + //! Returns an integer representing the species index + virtual int speciesIndex() const; + + //! Update the properties for this species, given a temperature + //! polynomial + /*! + * This method is called with a pointer to an array containing the functions of + * temperature needed by this parameterization, and three pointers to arrays where the + * computed property values should be written. This method updates only one value in + * each array. + * + * The form and length of the Temperature Polynomial may vary depending on the + * parameterization. + * + * @param tempPoly vector of temperature polynomials + * @param cp_R Vector of Dimensionless heat capacities. + * (length m_kk). + * @param h_RT Vector of Dimensionless enthalpies. + * (length m_kk). + * @param s_R Vector of Dimensionless entropies. + * (length m_kk). + */ + virtual void updateProperties(const doublereal* tempPoly, + doublereal* cp_R, doublereal* h_RT, + doublereal* s_R) const; + + //! Compute the reference-state property of one species + /*! + * Given temperature T in K, this method updates the values of + * the non-dimensional heat capacity at constant pressure, + * enthalpy, and entropy, at the reference pressure, Pref + * of one of the species. The species index is used + * to reference into the cp_R, h_RT, and s_R arrays. + * + * @param temp Temperature (Kelvin) + * @param cp_R Vector of Dimensionless heat capacities. + * (length m_kk). + * @param h_RT Vector of Dimensionless enthalpies. + * (length m_kk). + * @param s_R Vector of Dimensionless entropies. + * (length m_kk). + */ + virtual void updatePropertiesTemp(const doublereal temp, + doublereal* cp_R, + doublereal* h_RT, + doublereal* s_R) const; + + //!This utility function reports back the type of + //! parameterization and all of the parameters for the + //! species, index. + /*! + * All parameters are output variables + * + * @param index Species index + * @param type Integer type of the standard type + * @param minTemp output - Minimum temperature + * @param maxTemp output - Maximum temperature + * @param refPressure output - reference pressure (Pa). + * @param coeffs Vector of coefficients used to set the + * parameters for the standard state. + */ + virtual void reportParameters(int &index, int &type, + doublereal &minTemp, doublereal &maxTemp, + doublereal &refPressure, + doublereal* const coeffs) const; + + //! Modify parameters for the standard state + /*! + * This is a stub routine, without functionality + * + * @param coeffs Vector of coefficients used to set the + * parameters for the standard state. + */ + virtual void modifyParameters(doublereal* coeffs); + + private: + + VPSSMgr *m_vpssmgr_ptr; + PDSS *m_PDSS_ptr; + int m_speciesIndex; + }; + } #endif diff --git a/Cantera/src/thermo/VPSSMgr.cpp b/Cantera/src/thermo/VPSSMgr.cpp index b35d1e5c2..255036fc3 100644 --- a/Cantera/src/thermo/VPSSMgr.cpp +++ b/Cantera/src/thermo/VPSSMgr.cpp @@ -27,6 +27,7 @@ #include "VPStandardStateTP.h" #include "SpeciesThermoFactory.h" #include "PDSS.h" +#include "GeneralSpeciesThermo.h" using namespace std; @@ -125,6 +126,22 @@ namespace Cantera { SpeciesThermo *sp_ptr) { m_vptp_ptr = vp_ptr; m_spthermo = sp_ptr; + + // Take care of STITTbyPDSS objects + + // Go see if the SpeciesThermo type is a GeneralSpeciesThermo + GeneralSpeciesThermo * gst = dynamic_cast(sp_ptr); + if (gst) { + for (int k = 0; k < m_kk; k++) { + SpeciesThermoInterpType *st = gst->provideSTIT(k); + STITbyPDSS * stpd = dynamic_cast(st); + if (stpd) { + PDSS * PDSS_ptr = vp_ptr->providePDSS(k); + stpd->initAllPtrs(k, this, PDSS_ptr); + } + } + } + } /*****************************************************************/ diff --git a/Cantera/src/thermo/VPSSMgr_Water_ConstVol.cpp b/Cantera/src/thermo/VPSSMgr_Water_ConstVol.cpp index 4e004714a..0a98dc460 100644 --- a/Cantera/src/thermo/VPSSMgr_Water_ConstVol.cpp +++ b/Cantera/src/thermo/VPSSMgr_Water_ConstVol.cpp @@ -29,6 +29,7 @@ #include "VPStandardStateTP.h" #include "PDSS_Water.h" #include "PDSS_ConstVol.h" +#include "GeneralSpeciesThermo.h" using namespace std; @@ -257,6 +258,12 @@ namespace Cantera { } if (m_waterSS) delete m_waterSS; m_waterSS = new PDSS_Water(m_vptp_ptr, 0); + GeneralSpeciesThermo *genSpthermo = dynamic_cast(m_spthermo); + if (!genSpthermo) { + throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies", + "failed dynamic cast"); + } + genSpthermo->installPDSShandler(k, m_waterSS, this); kPDSS = m_waterSS; } else { diff --git a/Cantera/src/thermo/speciesThermoTypes.h b/Cantera/src/thermo/speciesThermoTypes.h index 5e5e24265..777aff675 100755 --- a/Cantera/src/thermo/speciesThermoTypes.h +++ b/Cantera/src/thermo/speciesThermoTypes.h @@ -69,6 +69,8 @@ //! This is implemented in the class Adsorbate. #define ADSORBATE 1024 +#define PDSS_TYPE 37 + #include "ct_defs.h" #include "stringUtils.h"