StoichSubstanceSSTP.cpp

Go to the documentation of this file.
00001 /**
00002  *  @file StoichSubstanceSSTP.cpp
00003  * Definition file for the StoichSubstanceSSTP class, which represents a fixed-composition
00004  * incompressible substance (see \ref thermoprops and 
00005  * class \link Cantera::StoichSubstanceSSTP StoichSubstanceSSTP\endlink)
00006  */
00007 
00008 /*
00009  * Copywrite (2005) Sandia Corporation. Under the terms of
00010  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
00011  * U.S. Government retains certain rights in this software.
00012  *
00013  * Copyright 2001 California Institute of Technology
00014  */
00015 
00016 /*
00017  * $Id: StoichSubstanceSSTP.cpp 279 2009-12-05 19:08:43Z hkmoffa $ 
00018  */
00019 
00020 #include "ct_defs.h"
00021 #include "mix_defs.h"
00022 #include "StoichSubstanceSSTP.h"
00023 #include "SpeciesThermo.h"
00024 #include "ThermoFactory.h"
00025 
00026 #include <string>
00027 
00028 namespace Cantera {
00029 
00030   /*
00031    * ----  Constructors -------
00032    */
00033 
00034   /*
00035    * Default Constructor for the StoichSubstanceSSTP class
00036    */
00037   StoichSubstanceSSTP::StoichSubstanceSSTP():
00038     SingleSpeciesTP()
00039   {
00040   }
00041 
00042   // Create and initialize a StoichSubstanceSSTP ThermoPhase object 
00043   // from an asci input file
00044   /*
00045    * @param infile name of the input file
00046    * @param id     name of the phase id in the file.
00047    *               If this is blank, the first phase in the file is used.
00048    */
00049   StoichSubstanceSSTP::StoichSubstanceSSTP(std::string infile, std::string id) :
00050     SingleSpeciesTP()
00051   {
00052     XML_Node* root = get_XML_File(infile);
00053     if (id == "-") id = "";
00054     XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id, root);
00055     if (!xphase) {
00056       throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
00057                           "Couldn't find phase name in file:" + id);
00058     }
00059     // Check the model name to ensure we have compatibility
00060     const XML_Node& th = xphase->child("thermo");
00061     std::string model = th["model"];
00062     if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
00063       throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
00064                          "thermo model attribute must be StoichSubstance");
00065     }
00066     importPhase(*xphase, this);
00067   }
00068 
00069   // Full Constructor.
00070   /*
00071    *  @param phaseRef XML node pointing to a StoichSubstanceSSTP description
00072    *  @param id       Id of the phase. 
00073    */
00074   StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, std::string id) :
00075     SingleSpeciesTP()
00076   {
00077     if (id != "") {
00078       std::string idxml = xmlphase["id"];
00079       if (id != idxml) {
00080         throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
00081                            "id's don't match");
00082       }
00083     }
00084     const XML_Node& th = xmlphase.child("thermo");
00085     std::string model = th["model"];
00086     if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
00087       throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
00088                          "thermo model attribute must be StoichSubstance");
00089     }
00090     importPhase(xmlphase, this);
00091   }
00092 
00093   //! Copy constructor
00094   /*!
00095    * @param right Object to be copied
00096    */
00097   StoichSubstanceSSTP::StoichSubstanceSSTP(const StoichSubstanceSSTP  &right) :
00098     SingleSpeciesTP()
00099   {
00100     *this = operator=(right);
00101   }
00102   
00103   //! Assignment operator
00104   /*!
00105    * @param right Object to be copied
00106    */
00107   StoichSubstanceSSTP & 
00108   StoichSubstanceSSTP::operator=(const StoichSubstanceSSTP & right) {
00109     if (&right != this) {
00110       SingleSpeciesTP::operator=(right);
00111     }
00112     return *this;
00113   }
00114 
00115   /*
00116    * Destructor for the routine (virtual)
00117    *        
00118    */
00119   StoichSubstanceSSTP::~StoichSubstanceSSTP() 
00120   {
00121   }
00122 
00123   // Duplication function
00124   /*
00125    * This virtual function is used to create a duplicate of the
00126    * current phase. It's used to duplicate the phase when given
00127    * a ThermoPhase pointer to the phase.
00128    *
00129    * @return It returns a ThermoPhase pointer.
00130    */
00131   ThermoPhase *StoichSubstanceSSTP::duplMyselfAsThermoPhase() const {
00132     StoichSubstanceSSTP *stp = new StoichSubstanceSSTP(*this);
00133     return (ThermoPhase *) stp;
00134   }
00135 
00136 
00137   /*
00138    * ---- Utilities -----
00139    */
00140 
00141   /*
00142    * Equation of state flag. Returns the value cStoichSubstance,
00143    * defined in mix_defs.h.
00144    */
00145   int StoichSubstanceSSTP::eosType() const {
00146     return cStoichSubstance; 
00147   }
00148 
00149   /*
00150    * ---- Molar Thermodynamic properties of the solution ----
00151    */
00152 
00153   /**
00154    * ----- Mechanical Equation of State ------
00155    */
00156 
00157   /*
00158    * Pressure. Units: Pa.
00159    * For an incompressible substance, the density is independent
00160    * of pressure. This method simply returns the stored
00161    * pressure value.
00162    */ 
00163   doublereal StoichSubstanceSSTP::pressure() const {
00164     return m_press;
00165   }
00166     
00167   /*
00168    * Set the pressure at constant temperature. Units: Pa.
00169    * For an incompressible substance, the density is 
00170    * independent of pressure. Therefore, this method only 
00171    * stores the specified pressure value. It does not 
00172    * modify the density.
00173    */
00174   void StoichSubstanceSSTP::setPressure(doublereal p) {
00175     m_press = p;
00176   }
00177 
00178   /*
00179    * The isothermal compressibility. Units: 1/Pa.
00180    * The isothermal compressibility is defined as
00181    * \f[
00182    * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T
00183    * \f]
00184    *
00185    *  It's equal to zero for this model, since the molar volume
00186    *  doesn't change with pressure or temperature.
00187    */
00188   doublereal StoichSubstanceSSTP::isothermalCompressibility() const {
00189     return 0.0;
00190   } 
00191     
00192   /*
00193    * The thermal expansion coefficient. Units: 1/K.
00194    * The thermal expansion coefficient is defined as
00195    *
00196    * \f[
00197    * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P
00198    * \f]
00199    *
00200    *  It's equal to zero for this model, since the molar volume
00201    *  doesn't change with pressure or temperature.
00202    */
00203   doublereal StoichSubstanceSSTP::thermalExpansionCoeff() const {
00204     return 0.0;
00205   }
00206     
00207   /*
00208    * ---- Chemical Potentials and Activities ----
00209    */
00210 
00211   /*
00212    * This method returns the array of generalized
00213    * concentrations.  For a stoichiomeetric substance, there is
00214    * only one species, and the generalized concentration is 1.0.
00215    */
00216   void StoichSubstanceSSTP::
00217   getActivityConcentrations(doublereal* c) const {
00218     c[0] = 1.0;
00219   }
00220 
00221   /*
00222    * The standard concentration. This is defined as the concentration 
00223    * by which the generalized concentration is normalized to produce 
00224    * the activity. 
00225    */ 
00226   doublereal StoichSubstanceSSTP::standardConcentration(int k) const {
00227     return 1.0;
00228   }
00229 
00230   /*
00231    * Returns the natural logarithm of the standard 
00232    * concentration of the kth species
00233    */
00234   doublereal StoichSubstanceSSTP::logStandardConc(int k) const {
00235     return 0.0;
00236   }
00237 
00238   /*
00239    * Returns the units of the standard and generalized
00240    * concentrations Note they have the same units, as their
00241    * ratio is defined to be equal to the activity of the kth
00242    * species in the solution, which is unitless.
00243    *
00244    * This routine is used in print out applications where the
00245    * units are needed. Usually, MKS units are assumed throughout
00246    * the program and in the XML input files.
00247    *
00248    *  uA[0] = kmol units - default  = 1
00249    *  uA[1] = m    units - default  = -nDim(), the number of spatial
00250    *                                dimensions in the Phase class.
00251    *  uA[2] = kg   units - default  = 0;
00252    *  uA[3] = Pa(pressure) units - default = 0;
00253    *  uA[4] = Temperature units - default = 0;
00254    *  uA[5] = time units - default = 0
00255    */
00256   void StoichSubstanceSSTP::
00257   getUnitsStandardConc(doublereal *uA, int k, int sizeUA) const {
00258     for (int i = 0; i < 6; i++) {
00259       uA[i] = 0;
00260     }
00261   }
00262 
00263   /*
00264    *  ---- Partial Molar Properties of the Solution ----
00265    */
00266 
00267 
00268 
00269   /*
00270    * ---- Properties of the Standard State of the Species in the Solution
00271    * ----
00272    */
00273 
00274   /*
00275    * Get the array of chemical potentials at unit activity 
00276    * \f$ \mu^0_k \f$.
00277    *
00278    * For a stoichiometric substance, there is no activity term in 
00279    * the chemical potential expression, and therefore the
00280    * standard chemical potential and the chemical potential
00281    * are both equal to the molar Gibbs function.
00282    */
00283   void StoichSubstanceSSTP::
00284   getStandardChemPotentials(doublereal* mu0) const {
00285     getGibbs_RT(mu0);
00286     mu0[0] *= GasConstant * temperature();
00287   }
00288     
00289   /*
00290    * Get the nondimensional Enthalpy functions for the species
00291    * at their standard states at the current 
00292    * <I>T</I> and <I>P</I> of the solution.
00293    * Molar enthalpy. Units: J/kmol.  For an incompressible,
00294    * stoichiometric substance, the internal energy is
00295    * independent of pressure, and therefore the molar enthalpy
00296    * is \f[ \hat h(T, P) = \hat u(T) + P \hat v \f], where the
00297    * molar specific volume is constant.
00298    */
00299   void StoichSubstanceSSTP::getEnthalpy_RT(doublereal* hrt) const {
00300     getEnthalpy_RT_ref(hrt);
00301     doublereal RT = GasConstant * temperature();
00302     doublereal presCorrect = (m_press - m_p0) /  molarDensity();
00303     hrt[0] += presCorrect / RT;
00304   }
00305 
00306   /*
00307    * Get the array of nondimensional Entropy functions for the
00308    * standard state species
00309    * at the current <I>T</I> and <I>P</I> of the solution.
00310    */
00311   void StoichSubstanceSSTP::getEntropy_R(doublereal* sr) const {
00312     getEntropy_R_ref(sr);
00313   }
00314 
00315   /*
00316    * Get the nondimensional Gibbs functions for the species
00317    * at their standard states of solution at the current T and P
00318    * of the solution
00319    */
00320   void StoichSubstanceSSTP::getGibbs_RT(doublereal* grt) const {
00321     getEnthalpy_RT(grt);
00322     grt[0] -= m_s0_R[0];
00323   }
00324 
00325   /*
00326    * Get the nondimensional Gibbs functions for the standard
00327    * state of the species at the current T and P.
00328    */
00329   void StoichSubstanceSSTP::getCp_R(doublereal* cpr) const {
00330     _updateThermo();
00331     cpr[0] = m_cp0_R[0];
00332   }
00333    
00334   /*
00335    * Molar internal energy (J/kmol).
00336    * For an incompressible,
00337    * stoichiometric substance, the molar internal energy is
00338    * independent of pressure. Since the thermodynamic properties
00339    * are specified by giving the standard-state enthalpy, the
00340    * term \f$ P_0 \hat v\f$ is subtracted from the specified molar
00341    * enthalpy to compute the molar internal energy.
00342    */
00343   void StoichSubstanceSSTP::getIntEnergy_RT(doublereal* urt) const {
00344     _updateThermo();
00345     doublereal RT = GasConstant * temperature();
00346     doublereal PV = m_p0 / molarDensity();
00347     urt[0] = m_h0_RT[0] - PV / RT;
00348   }
00349 
00350   /*
00351    * ---- Thermodynamic Values for the Species Reference States ----
00352    */
00353   /*
00354    * Molar internal energy or the reference state at the current
00355    * temperature, T  (J/kmol).  
00356    * For an incompressible,
00357    * stoichiometric substance, the molar internal energy is
00358    * independent of pressure. Since the thermodynamic properties
00359    * are specified by giving the standard-state enthalpy, the
00360    * term \f$ P_0 \hat v\f$ is subtracted from the specified molar
00361    * enthalpy to compute the molar internal energy.
00362    *
00363    * Note, this is equal to the standard state internal energy
00364    * evaluated at the reference pressure.
00365    */
00366   void StoichSubstanceSSTP::getIntEnergy_RT_ref(doublereal* urt) const {
00367     _updateThermo();
00368     doublereal RT = GasConstant * temperature();
00369     doublereal PV = m_p0 / molarDensity();
00370     urt[0] = m_h0_RT[0] - PV / RT;
00371   }
00372               
00373   /*
00374    * ---- Saturation Properties
00375    */
00376     
00377  
00378 
00379   /*
00380    * ---- Initialization and Internal functions
00381    */
00382 
00383   /**
00384    * @internal Initialize. This method is provided to allow
00385    * subclasses to perform any initialization required after all
00386    * species have been added. For example, it might be used to
00387    * resize internal work arrays that must have an entry for
00388    * each species.  The base class implementation does nothing,
00389    * and subclasses that do not require initialization do not
00390    * need to overload this method.  When importing a CTML phase
00391    * description, this method is called just prior to returning
00392    * from function importPhase.
00393    *
00394    * @see importCTML.cpp
00395    */
00396   void StoichSubstanceSSTP::initThermo() {
00397     /*
00398      * Make sure there is one and only one species in this phase.
00399      */
00400     m_kk = nSpecies();
00401     if (m_kk != 1) {
00402       throw CanteraError("initThermo",
00403                          "stoichiometric substances may only contain one species.");
00404     }
00405     doublereal tmin = m_spthermo->minTemp();
00406     doublereal tmax = m_spthermo->maxTemp();
00407     if (tmin > 0.0) m_tmin = tmin;
00408     if (tmax > 0.0) m_tmax = tmax;
00409     /*
00410      * Store the reference pressure in the variables for the class.
00411      */
00412     m_p0 = refPressure();
00413 
00414     /*
00415      * Resize temporary arrays.
00416      */
00417     int leng = 1;
00418     m_h0_RT.resize(leng);
00419     m_cp0_R.resize(leng);
00420     m_s0_R.resize(leng);
00421     /*
00422      * Call the base class thermo initializer
00423      */
00424     SingleSpeciesTP::initThermo();
00425   }
00426 
00427 
00428   void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, std::string id) {
00429     /*
00430      * Find the Thermo XML node
00431      */
00432     if (!phaseNode.hasChild("thermo")) {
00433       throw CanteraError("StoichSubstanceSSTP::initThermoXML",
00434                          "no thermo XML node");
00435     }
00436     XML_Node &tnode = phaseNode.child("thermo");
00437     double dens = getFloatDefaultUnits(tnode, "density", "kg/m3");
00438     setDensity(dens);
00439     SingleSpeciesTP::initThermoXML(phaseNode, id);
00440   }
00441 
00442   /**
00443    * setParameters:
00444    *
00445    *   Generic routine that is used to set the parameters used
00446    *   by this model.
00447    *        C[0] = density of phase [ kg/m3 ]
00448    */
00449   void StoichSubstanceSSTP::setParameters(int n, doublereal * const c) {
00450     doublereal rho = c[0];
00451     setDensity(rho);
00452   }
00453 
00454   /**
00455    * getParameters:
00456    *
00457    *   Generic routine that is used to get the parameters used
00458    *   by this model.
00459    *        n = 1
00460    *        C[0] = density of phase [ kg/m3 ]
00461    */
00462   void StoichSubstanceSSTP::getParameters(int &n, doublereal * const c) const {
00463     doublereal rho = density();
00464     n = 1;
00465     c[0] = rho;
00466   }
00467 
00468   /*
00469    * Reads an xml data block for the parameters needed by this
00470    * routine. eosdata is a reference to the xml thermo block, and looks
00471    * like this:
00472    * 
00473    *   <phase id="stoichsolid" >
00474    *     <thermo model="StoichSubstance">
00475    *         <density units="g/cm3">3.52</density>
00476    *     </thermo>
00477    *   </phase>
00478    */
00479   void StoichSubstanceSSTP::setParametersFromXML(const XML_Node& eosdata) {
00480     std::string model = eosdata["model"];
00481     if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
00482       throw CanteraError("StoichSubstanceSSTP::setParametersFromXML",
00483                          "thermo model attribute must be StoichSubstance");
00484     }
00485     doublereal rho = getFloat(eosdata, "density", "toSI");
00486     setDensity(rho);
00487   }
00488 
00489 
00490 
00491 
00492 
00493   /*
00494    * Default Constructor for the electrodeElectron class
00495    */
00496   electrodeElectron::electrodeElectron():
00497    StoichSubstanceSSTP()
00498   {
00499   }
00500 
00501   // Create and initialize a electrodeElectron ThermoPhase object 
00502   // from an asci input file
00503   /*
00504    * @param infile name of the input file
00505    * @param id     name of the phase id in the file.
00506    *               If this is blank, the first phase in the file is used.
00507    */
00508   electrodeElectron::electrodeElectron(std::string infile, std::string id) :
00509     StoichSubstanceSSTP()
00510   {
00511     XML_Node* root = get_XML_File(infile);
00512     if (id == "-") id = "";
00513     XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id, root);
00514     if (!xphase) {
00515       throw CanteraError("electrodeElectron::electrodeElectron",
00516                           "Couldn't find phase name in file:" + id);
00517     }
00518     // Check the model name to ensure we have compatibility
00519     const XML_Node& th = xphase->child("thermo");
00520     std::string model = th["model"];
00521     if (model != "electrodeElectron") {
00522       throw CanteraError("electrodeElectron::electrodeElectron",
00523                          "thermo model attribute must be electrodeElectron");
00524     }
00525     importPhase(*xphase, this);
00526   }
00527 
00528   // Full Constructor.
00529   /*
00530    *  @param phaseRef XML node pointing to a electrodeElectron description
00531    *  @param id       Id of the phase. 
00532    */
00533   electrodeElectron::electrodeElectron(XML_Node& xmlphase, std::string id) :
00534     StoichSubstanceSSTP()
00535   {
00536     if (id != "") {
00537       std::string idxml = xmlphase["id"];
00538       if (id != idxml) {
00539         throw CanteraError("electrodeElectron::electrodeElectron",
00540                            "id's don't match");
00541       }
00542     }
00543     const XML_Node& th = xmlphase.child("thermo");
00544     std::string model = th["model"];
00545     if (model != "electrodeElectron") {
00546       throw CanteraError("electrodeElectron::electrodeElectron",
00547                          "thermo model attribute must be electrodeElectron");
00548     }
00549     importPhase(xmlphase, this);
00550   }
00551 
00552   //! Copy constructor
00553   /*!
00554    * @param right Object to be copied
00555    */
00556   electrodeElectron::electrodeElectron(const electrodeElectron  &right) :
00557     StoichSubstanceSSTP()
00558   {
00559     *this = operator=(right);
00560   }
00561   
00562   //! Assignment operator
00563   /*!
00564    * @param right Object to be copied
00565    */
00566   electrodeElectron & 
00567   electrodeElectron::operator=(const electrodeElectron & right) {
00568     if (&right != this) {
00569       StoichSubstanceSSTP::operator=(right);
00570     }
00571     return *this;
00572   }
00573 
00574   /*
00575    * Destructor for the routine (virtual)
00576    *        
00577    */
00578   electrodeElectron::~electrodeElectron() 
00579   {
00580   }
00581 
00582   void electrodeElectron::setParametersFromXML(const XML_Node& eosdata) {
00583     std::string model = eosdata["model"];
00584     if (model != "electrodeElectron") {
00585       throw CanteraError("electrodeElectron::setParametersFromXML",
00586                          "thermo model attribute must be electrodeElectron");
00587     }
00588   }
00589 
00590   void electrodeElectron::initThermoXML(XML_Node& phaseNode, std::string id) {
00591     doublereal rho = 10.0;
00592     setDensity(rho);
00593     SingleSpeciesTP::initThermoXML(phaseNode, id);
00594   }
00595   
00596   void electrodeElectron::setParameters(int n, doublereal * const c) {
00597     doublereal rho = 10.0;
00598     setDensity(rho);
00599   }
00600 
00601 }
00602 
00603 
Generated by  doxygen 1.6.3