PDSS_ConstVol.cpp

Go to the documentation of this file.
00001 /**
00002  * @file PDSS_ConstVol.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_ConstVol.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_ConstVol.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_ConstVol::PDSS_ConstVol(VPStandardStateTP *tp, int spindex) :
00031     PDSS(tp, spindex)
00032   {
00033     m_pdssType = cPDSS_CONSTVOL;
00034   }
00035 
00036 
00037   PDSS_ConstVol::PDSS_ConstVol(VPStandardStateTP *tp, int spindex, std::string inputFile, std::string id) :
00038     PDSS(tp, spindex)
00039   {
00040     m_pdssType = cPDSS_CONSTVOL;
00041     constructPDSSFile(tp, spindex, inputFile, id);
00042   }
00043 
00044   PDSS_ConstVol::PDSS_ConstVol(VPStandardStateTP *tp, int spindex,
00045                                const XML_Node& speciesNode, 
00046                                const XML_Node& phaseRoot, 
00047                                bool spInstalled) :
00048     PDSS(tp, spindex)
00049   {
00050     m_pdssType = cPDSS_CONSTVOL;
00051     constructPDSSXML(tp, spindex, speciesNode,  phaseRoot, spInstalled) ;
00052   }
00053 
00054 
00055   PDSS_ConstVol::PDSS_ConstVol(const PDSS_ConstVol &b) :
00056     PDSS(b)
00057   {
00058     /*
00059      * Use the assignment operator to do the brunt
00060      * of the work for the copy construtor.
00061      */
00062     *this = b;
00063   }
00064 
00065   /*
00066    * Assignment operator
00067    */
00068   PDSS_ConstVol& PDSS_ConstVol::operator=(const PDSS_ConstVol&b) {
00069     if (&b == this) return *this;
00070     PDSS::operator=(b);
00071     m_constMolarVolume      = b.m_constMolarVolume;
00072     return *this;
00073   }
00074 
00075   PDSS_ConstVol::~PDSS_ConstVol() { 
00076   }
00077   
00078   // Duplicator
00079   PDSS* PDSS_ConstVol::duplMyselfAsPDSS() const {
00080     PDSS_ConstVol * idg = new PDSS_ConstVol(*this);
00081     return (PDSS *) idg;
00082   }
00083 
00084   /*
00085    * constructPDSSXML:
00086    *
00087    * Initialization of a PDSS_ConstVol object using an
00088    * xml file.
00089    *
00090    * This routine is a precursor to initThermo(XML_Node*)
00091    * routine, which does most of the work.
00092    *
00093    * @param infile XML file containing the description of the
00094    *        phase
00095    *
00096    * @param id  Optional parameter identifying the name of the
00097    *            phase. If none is given, the first XML
00098    *            phase element will be used.
00099    */
00100   void PDSS_ConstVol::constructPDSSXML(VPStandardStateTP *tp, int spindex,
00101                                        const XML_Node& speciesNode, 
00102                                        const XML_Node& phaseNode, bool spInstalled) {
00103     PDSS::initThermo();
00104     SpeciesThermo &sp = m_tp->speciesThermo();
00105     m_p0 = sp.refPressure(m_spindex);
00106 
00107     if (!spInstalled) {
00108       throw CanteraError("PDSS_ConstVol::constructPDSSXML", "spInstalled false not handled");
00109     }
00110 
00111     const XML_Node *ss = speciesNode.findByName("standardState");
00112     if (!ss) {
00113       throw CanteraError("PDSS_ConstVol::constructPDSSXML",
00114                          "no standardState Node for species " + speciesNode.name());
00115     }
00116     std::string model = (*ss)["model"];
00117     if (model != "constant_incompressible") {
00118       throw CanteraError("PDSS_ConstVol::initThermoXML",
00119                          "standardState model for species isn't constant_incompressible: " + speciesNode.name());
00120     }
00121   
00122     m_constMolarVolume = getFloat(*ss, "molarVolume", "toSI");
00123   
00124     std::string id = "";
00125     // initThermoXML(phaseNode, id);
00126   }
00127 
00128    
00129   /*
00130    * constructPDSSFile():
00131    *
00132    * Initialization of a PDSS_ConstVol object using an
00133    * xml file.
00134    *
00135    * This routine is a precursor to initThermo(XML_Node*)
00136    * routine, which does most of the work.
00137    *
00138    * @param infile XML file containing the description of the
00139    *        phase
00140    *
00141    * @param id  Optional parameter identifying the name of the
00142    *            phase. If none is given, the first XML
00143    *            phase element will be used.
00144    */
00145   void PDSS_ConstVol::constructPDSSFile(VPStandardStateTP *tp, int spindex,
00146                                         std::string inputFile, std::string id) {
00147 
00148     if (inputFile.size() == 0) {
00149       throw CanteraError("PDSS_ConstVol::initThermo",
00150                          "input file is null");
00151     }
00152     std::string path = findInputFile(inputFile);
00153     ifstream fin(path.c_str());
00154     if (!fin) {
00155       throw CanteraError("PDSS_ConstVol::initThermo","could not open "
00156                          +path+" for reading.");
00157     }
00158     /*
00159      * The phase object automatically constructs an XML object.
00160      * Use this object to store information.
00161      */
00162 
00163     XML_Node *fxml = new XML_Node();
00164     fxml->build(fin);
00165     XML_Node *fxml_phase = findXMLPhase(fxml, id);
00166     if (!fxml_phase) {
00167       throw CanteraError("PDSS_ConstVol::initThermo",
00168                          "ERROR: Can not find phase named " +
00169                          id + " in file named " + inputFile);
00170     }
00171 
00172     XML_Node& speciesList = fxml_phase->child("speciesArray");
00173     XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
00174                                          &(fxml_phase->root()));
00175     const vector<string>&sss = tp->speciesNames();
00176     const XML_Node* s =  speciesDB->findByAttr("name", sss[spindex]);
00177 
00178     constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
00179     delete fxml;
00180   }
00181 
00182   void PDSS_ConstVol::initThermoXML(const XML_Node& phaseNode, std::string& id) {
00183     PDSS::initThermoXML(phaseNode, id);
00184     m_minTemp = m_spthermo->minTemp(m_spindex);
00185     m_maxTemp = m_spthermo->maxTemp(m_spindex);
00186     m_p0 = m_spthermo->refPressure(m_spindex);
00187     m_mw = m_tp->molecularWeight(m_spindex);
00188   }
00189 
00190   void PDSS_ConstVol::initThermo() {
00191     PDSS::initThermo();
00192     SpeciesThermo &sp = m_tp->speciesThermo();
00193     m_p0 = sp.refPressure(m_spindex);
00194     m_V0_ptr[m_spindex] = m_constMolarVolume;
00195     m_Vss_ptr[m_spindex] = m_constMolarVolume;
00196   }
00197 
00198   doublereal 
00199   PDSS_ConstVol::enthalpy_mole() const {
00200     doublereal val = enthalpy_RT();
00201     doublereal RT = GasConstant * m_temp;
00202     return (val * RT);
00203   }
00204 
00205   doublereal 
00206   PDSS_ConstVol::enthalpy_RT() const {
00207     doublereal val = m_hss_RT_ptr[m_spindex];
00208     return (val);
00209   }
00210 
00211 
00212   doublereal 
00213   PDSS_ConstVol::intEnergy_mole() const {
00214     doublereal pVRT = (m_pres * m_Vss_ptr[m_spindex]) / (GasConstant * m_temp);
00215     doublereal val = m_h0_RT_ptr[m_spindex] - pVRT;
00216     doublereal RT = GasConstant * m_temp;
00217     return (val * RT);
00218   }
00219 
00220 
00221   doublereal
00222   PDSS_ConstVol::entropy_mole() const {
00223     doublereal val = entropy_R();
00224     return (val * GasConstant);
00225   }
00226 
00227   doublereal
00228   PDSS_ConstVol::entropy_R() const {
00229     doublereal val = m_sss_R_ptr[m_spindex];
00230     return (val);
00231   }
00232 
00233   /*
00234    * Calculate the Gibbs free energy in mks units of
00235    * J kmol-1 K-1.
00236    */
00237   doublereal
00238   PDSS_ConstVol::gibbs_mole() const {
00239     doublereal val = gibbs_RT();
00240     doublereal RT = GasConstant * m_temp;
00241     return (val * RT);
00242   }
00243 
00244   doublereal
00245   PDSS_ConstVol::gibbs_RT() const {
00246     doublereal val = m_gss_RT_ptr[m_spindex];
00247     return (val);
00248   }
00249 
00250   doublereal 
00251   PDSS_ConstVol::cp_mole() const {
00252     doublereal val = m_cpss_R_ptr[m_spindex];
00253     return (val * GasConstant);
00254   }
00255 
00256   doublereal 
00257   PDSS_ConstVol::cp_R() const {
00258     doublereal val = m_cpss_R_ptr[m_spindex];
00259     return (val);
00260   }
00261 
00262   doublereal 
00263   PDSS_ConstVol::cv_mole() const {
00264     doublereal val = (cp_mole() -  m_V0_ptr[m_spindex]);
00265     return (val);
00266   }
00267 
00268   doublereal 
00269   PDSS_ConstVol::molarVolume() const {
00270     doublereal val = m_Vss_ptr[m_spindex];
00271     return (val);
00272   }
00273 
00274   doublereal 
00275   PDSS_ConstVol::density() const {
00276     doublereal val = m_Vss_ptr[m_spindex];
00277     return (m_mw/val);
00278   }
00279 
00280   doublereal
00281   PDSS_ConstVol::gibbs_RT_ref() const {
00282     doublereal val = m_g0_RT_ptr[m_spindex];
00283     return (val);
00284   }
00285 
00286   doublereal PDSS_ConstVol::enthalpy_RT_ref() const {
00287     doublereal val = m_h0_RT_ptr[m_spindex];
00288     return (val);
00289   }
00290 
00291   doublereal PDSS_ConstVol::entropy_R_ref() const {
00292     doublereal val = m_s0_R_ptr[m_spindex];
00293     return (val);
00294   }
00295 
00296   doublereal PDSS_ConstVol::cp_R_ref() const {
00297     doublereal val = m_cp0_R_ptr[m_spindex];
00298     return (val);
00299   }
00300 
00301   doublereal PDSS_ConstVol::molarVolume_ref() const {
00302     doublereal val = m_V0_ptr[m_spindex];
00303     return (val);
00304   }
00305 
00306  
00307 
00308   // critical temperature 
00309   doublereal PDSS_ConstVol::critTemperature() const { 
00310     throw CanteraError("PDSS_ConstVol::critTemperature()", "unimplemented");
00311     return (0.0);
00312   }
00313         
00314   // critical pressure
00315   doublereal PDSS_ConstVol::critPressure() const {
00316     throw CanteraError("PDSS_ConstVol::critPressure()", "unimplemented");
00317     return (0.0);
00318   }
00319         
00320   // critical density
00321   doublereal PDSS_ConstVol::critDensity() const {
00322     throw CanteraError("PDSS_ConstVol::critDensity()", "unimplemented");
00323     return (0.0);
00324   }
00325 
00326   void PDSS_ConstVol::setPressure(doublereal p) {
00327     m_pres = p;
00328     doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
00329     m_hss_RT_ptr[m_spindex]  = m_h0_RT_ptr[m_spindex] + del_pRT * m_Vss_ptr[m_spindex];
00330     m_gss_RT_ptr[m_spindex] = m_hss_RT_ptr[m_spindex] - m_sss_R_ptr[m_spindex];
00331   }
00332  
00333   void PDSS_ConstVol::setTemperature(doublereal temp) {
00334     m_temp = temp;
00335     m_spthermo->update_one(m_spindex, temp,
00336                            m_cp0_R_ptr, m_h0_RT_ptr, m_s0_R_ptr);
00337     m_g0_RT_ptr[m_spindex] =  m_h0_RT_ptr[m_spindex] -  m_s0_R_ptr[m_spindex];
00338 
00339     doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
00340  
00341     m_hss_RT_ptr[m_spindex]  = m_h0_RT_ptr[m_spindex] + del_pRT * m_Vss_ptr[m_spindex];
00342     m_cpss_R_ptr[m_spindex]  = m_cp0_R_ptr[m_spindex];
00343     m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex];
00344     m_gss_RT_ptr[m_spindex] = m_hss_RT_ptr[m_spindex] - m_sss_R_ptr[m_spindex];
00345     
00346   }
00347 
00348 
00349   void PDSS_ConstVol::setState_TP(doublereal temp, doublereal pres) {
00350     setTemperature(temp);
00351     setPressure(pres);
00352   }
00353 
00354 
00355   void PDSS_ConstVol::setState_TR(doublereal temp, doublereal rho) {
00356     doublereal rhoStored = m_mw / m_constMolarVolume;
00357     if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
00358       throw CanteraError("PDSS_ConstVol::setState_TR",
00359                          "Inconsistent supplied rho");
00360     }
00361     setTemperature(temp);
00362   }
00363 
00364   // saturation pressure
00365   doublereal PDSS_ConstVol::satPressure(doublereal t){
00366     return (1.0E-200);
00367   }
00368  
00369 }
Generated by  doxygen 1.6.3