PDSS_IdealGas.cpp

Go to the documentation of this file.
00001 /**
00002  * @file PDSS_IdealGas.cpp
00003  * Implementation of a pressure dependent standard state 
00004  * virtual function.
00005  */
00006 /*
00007  * Copywrite (2006) Sandia Corporation. Under the terms of
00008  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
00009  * U.S. Government retains certain rights in this software.
00010  */
00011 /*
00012  * $Id: PDSS_IdealGas.cpp 385 2010-01-17 17:05:46Z hkmoffa $
00013  */
00014 
00015 #include "ct_defs.h"
00016 #include "xml.h"
00017 #include "ctml.h"
00018 #include "PDSS_IdealGas.h"
00019 #include "ThermoFactory.h"
00020 
00021 #include "VPStandardStateTP.h"
00022 
00023 using namespace std;
00024 
00025 namespace Cantera {
00026   /**
00027    * Basic list of constructors and duplicators
00028    */
00029 
00030   PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP *tp, int spindex) :
00031     PDSS(tp, spindex)
00032   {
00033     m_pdssType = cPDSS_IDEALGAS;
00034   }
00035 
00036 
00037   PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP *tp, int spindex, 
00038                              std::string inputFile, std::string id) :
00039     PDSS(tp, spindex)
00040   {
00041     m_pdssType = cPDSS_IDEALGAS;
00042     constructPDSSFile(tp, spindex, inputFile, id);
00043   }
00044 
00045 
00046 
00047   PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP *tp, int spindex, const XML_Node& speciesNode,
00048                                const XML_Node& phaseRoot, bool spInstalled) :
00049     PDSS(tp, spindex)
00050   {
00051     if (!spInstalled) {
00052       throw CanteraError("PDSS_IdealGas", "sp installing not done yet");
00053     }
00054     m_pdssType = cPDSS_IDEALGAS;
00055     std::string id = "";
00056     constructPDSSXML(tp, spindex, phaseRoot, id);
00057   }
00058 
00059 
00060 
00061   PDSS_IdealGas::PDSS_IdealGas(const PDSS_IdealGas &b) :
00062     PDSS(b)
00063   {
00064     /*
00065      * Use the assignment operator to do the brunt
00066      * of the work for the copy construtor.
00067      */
00068     *this = b;
00069   }
00070 
00071   /*
00072    * Assignment operator
00073    */
00074   PDSS_IdealGas& PDSS_IdealGas::operator=(const PDSS_IdealGas&b) {
00075     if (&b == this) return *this;
00076     PDSS::operator=(b);
00077 
00078     m_tmin       =   b.m_tmin;
00079     m_tmax       =   b.m_tmax;
00080 
00081     return *this;
00082   }
00083 
00084   PDSS_IdealGas::~PDSS_IdealGas() { 
00085   }
00086   
00087   // Duplicator
00088   PDSS* PDSS_IdealGas::duplMyselfAsPDSS() const {
00089     PDSS_IdealGas * idg = new PDSS_IdealGas(*this);
00090     return (PDSS *) idg;
00091   }
00092 
00093 
00094    
00095   /*
00096    * constructPDSSXML:
00097    *
00098    * Initialization of a PDSS_IdealGas object using an
00099    * xml file.
00100    *
00101    * This routine is a precursor to initThermo(XML_Node*)
00102    * routine, which does most of the work.
00103    *
00104    * @param infile XML file containing the description of the
00105    *        phase
00106    *
00107    * @param id  Optional parameter identifying the name of the
00108    *            phase. If none is given, the first XML
00109    *            phase element will be used.
00110    */
00111   void PDSS_IdealGas::constructPDSSXML(VPStandardStateTP *tp, int spindex, 
00112                                       const XML_Node& phaseNode, std::string id) {
00113     //initThermo();
00114     //initThermoXML(phaseNode, id);
00115   }
00116 
00117  
00118   void PDSS_IdealGas::constructPDSSFile(VPStandardStateTP *tp, int spindex,
00119                                         std::string inputFile, std::string id) {
00120 
00121     if (inputFile.size() == 0) {
00122       throw CanteraError("PDSS_IdealGas::constructPDSSFile",
00123                          "input file is null");
00124     }
00125     std::string path = findInputFile(inputFile);
00126     ifstream fin(path.c_str());
00127     if (!fin) {
00128       throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open "
00129                          +path+" for reading.");
00130     }
00131     /*
00132      * The phase object automatically constructs an XML object.
00133      * Use this object to store information.
00134      */
00135 
00136     XML_Node *fxml = new XML_Node();
00137     fxml->build(fin);
00138     XML_Node *fxml_phase = findXMLPhase(fxml, id);
00139     if (!fxml_phase) {
00140       throw CanteraError("PDSS_IdealGas::constructPDSSFile",
00141                          "ERROR: Can not find phase named " +
00142                          id + " in file named " + inputFile);
00143     }   
00144     constructPDSSXML(tp, spindex, *fxml_phase, id);
00145     delete fxml;
00146   }
00147 
00148   void PDSS_IdealGas::initThermoXML(const XML_Node& phaseNode, std::string &id) {
00149     PDSS::initThermoXML(phaseNode, id);
00150   }
00151 
00152   void PDSS_IdealGas::initThermo() {
00153     PDSS::initThermo();
00154     SpeciesThermo &sp = m_tp->speciesThermo();
00155     m_p0 = sp.refPressure(m_spindex);
00156     m_minTemp = m_spthermo->minTemp(m_spindex);
00157     m_maxTemp = m_spthermo->maxTemp(m_spindex); 
00158   }
00159 
00160   /*
00161    * Return the molar enthalpy in units of J kmol-1
00162    */
00163   doublereal 
00164   PDSS_IdealGas::enthalpy_mole() const {
00165     doublereal val = enthalpy_RT();
00166     doublereal RT = GasConstant * m_temp;
00167     return (val * RT);
00168   }
00169 
00170   doublereal 
00171   PDSS_IdealGas::enthalpy_RT() const {
00172     doublereal val = m_h0_RT_ptr[m_spindex];
00173     return (val);
00174   }
00175 
00176 
00177   /*
00178    * Calculate the internal energy in mks units of
00179    * J kmol-1 
00180    */
00181   doublereal 
00182   PDSS_IdealGas::intEnergy_mole() const {
00183     doublereal val = m_h0_RT_ptr[m_spindex] - 1.0;
00184     doublereal RT = GasConstant * m_temp;
00185     return (val * RT);
00186   }
00187 
00188   /*
00189    * Calculate the entropy in mks units of 
00190    * J kmol-1 K-1
00191    */
00192   doublereal
00193   PDSS_IdealGas::entropy_mole() const {
00194     doublereal val = entropy_R();
00195     return (val * GasConstant);
00196   }
00197 
00198   doublereal
00199   PDSS_IdealGas::entropy_R() const {
00200     doublereal val = m_s0_R_ptr[m_spindex] - log(m_pres/m_p0);
00201     return (val);
00202   }
00203 
00204   /*
00205    * Calculate the Gibbs free energy in mks units of
00206    * J kmol-1 K-1.
00207    */
00208   doublereal
00209   PDSS_IdealGas::gibbs_mole() const {
00210     doublereal val = gibbs_RT();
00211     doublereal RT = GasConstant * m_temp;
00212     return (val * RT);
00213   }
00214 
00215   doublereal
00216   PDSS_IdealGas::gibbs_RT() const {
00217     doublereal val = m_g0_RT_ptr[m_spindex] + log(m_pres/m_p0);
00218     return (val);
00219   }
00220 
00221   /*
00222    * Calculate the constant pressure heat capacity
00223    * in mks units of J kmol-1 K-1
00224    */
00225   doublereal 
00226   PDSS_IdealGas::cp_mole() const {
00227     doublereal val = cp_R();
00228     return (val * GasConstant);
00229   }
00230 
00231   doublereal 
00232   PDSS_IdealGas::cp_R() const {
00233     doublereal val = m_cp0_R_ptr[m_spindex];
00234     return (val);
00235   }
00236 
00237   doublereal 
00238   PDSS_IdealGas::molarVolume() const {
00239     return (GasConstant * m_temp / m_pres);
00240   }
00241 
00242 
00243   doublereal 
00244   PDSS_IdealGas::density() const {
00245     return (m_pres * m_mw / (GasConstant * m_temp));
00246   }
00247 
00248   /*
00249    * Calculate the constant volume heat capacity
00250    * in mks units of J kmol-1 K-1
00251    */
00252   doublereal 
00253   PDSS_IdealGas::cv_mole() const {
00254     return (cp_mole() - GasConstant);
00255   }
00256 
00257 
00258   doublereal
00259   PDSS_IdealGas::gibbs_RT_ref() const {
00260     doublereal val = m_g0_RT_ptr[m_spindex];
00261     return (val);
00262   }
00263 
00264   doublereal PDSS_IdealGas::enthalpy_RT_ref() const {
00265     doublereal val = m_h0_RT_ptr[m_spindex];
00266     return (val);
00267   }
00268 
00269   doublereal PDSS_IdealGas::entropy_R_ref() const {
00270     doublereal val = m_s0_R_ptr[m_spindex];
00271     return (val);
00272   }
00273 
00274   doublereal PDSS_IdealGas::cp_R_ref() const {
00275     return (cp_R());
00276   }
00277 
00278   doublereal PDSS_IdealGas::molarVolume_ref() const {
00279     return (GasConstant * m_temp / m_p0);
00280   }
00281 
00282   /*
00283    * Calculate the pressure (Pascals), given the temperature and density
00284    *  Temperature: kelvin
00285    *  rho: density in kg m-3
00286    */
00287   doublereal  PDSS_IdealGas::pressure() const {
00288     throw CanteraError("PDSS_IdealGas::pressure()", "unimplemented");
00289     return (0.0);
00290   }
00291   
00292   void PDSS_IdealGas::setPressure(doublereal p) {
00293     m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex] + log(m_pres/m_p0);
00294     m_gss_RT_ptr[m_spindex] = m_hss_RT_ptr[m_spindex] - m_sss_R_ptr[m_spindex];
00295     m_Vss_ptr[m_spindex] = GasConstant * m_temp / m_pres;
00296   }
00297  
00298 
00299   // critical temperature 
00300   doublereal PDSS_IdealGas::critTemperature() const { 
00301     throw CanteraError("PDSS_IdealGas::critTemperature()", "unimplemented");
00302     return (0.0);
00303   }
00304         
00305   // critical pressure
00306   doublereal PDSS_IdealGas::critPressure() const {
00307     throw CanteraError("PDSS_IdealGas::critPressure()", "unimplemented");
00308     return (0.0);
00309   }
00310         
00311   // critical density
00312   doublereal PDSS_IdealGas::critDensity() const {
00313     throw CanteraError("PDSS_IdealGas::critDensity()", "unimplemented");
00314     return (0.0);
00315   }
00316         
00317 
00318   /*
00319    * Return the temperature 
00320    *
00321    * Obtain the temperature from the owning VPStandardStateTP object
00322    * if you can. 
00323    */
00324   doublereal PDSS_IdealGas::temperature() const {
00325     m_temp = m_vpssmgr_ptr->temperature();
00326     return m_temp;
00327   }
00328  
00329   void PDSS_IdealGas::setTemperature(doublereal temp) {
00330     m_temp = temp;
00331     m_spthermo->update_one(m_spindex, temp,
00332                            m_cp0_R_ptr, m_h0_RT_ptr, m_s0_R_ptr);
00333     m_g0_RT_ptr[m_spindex] =  m_h0_RT_ptr[m_spindex] -  m_s0_R_ptr[m_spindex];
00334     m_V0_ptr[m_spindex] = GasConstant * m_temp / m_p0;
00335  
00336     m_hss_RT_ptr[m_spindex]  = m_h0_RT_ptr[m_spindex];
00337     m_cpss_R_ptr[m_spindex]  = m_cp0_R_ptr[m_spindex];
00338     m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex] + log(m_pres/m_p0);
00339     m_gss_RT_ptr[m_spindex] = m_hss_RT_ptr[m_spindex] - m_sss_R_ptr[m_spindex];
00340     m_Vss_ptr[m_spindex] = GasConstant * m_temp / m_pres;
00341   }
00342 
00343 
00344   void PDSS_IdealGas::setState_TP(doublereal temp, doublereal pres) {
00345     m_pres = pres;
00346     setTemperature(temp);
00347   }
00348 
00349   void  PDSS_IdealGas::setState_TR(doublereal temp, doublereal rho) {
00350     m_pres = GasConstant * temp * rho / m_mw;
00351     setTemperature(temp);
00352   }
00353 
00354   // saturation pressure
00355   doublereal PDSS_IdealGas::satPressure(doublereal t){
00356     throw CanteraError("PDSS_IdealGas::satPressure()", "unimplemented");
00357     /*NOTREACHED*/
00358     return (0.0);
00359   }
00360    
00361 
00362 }
Generated by  doxygen 1.6.3