VPSSMgr_Water_ConstVol.cpp

Go to the documentation of this file.
00001 /**
00002  *  @file VPSSMgr_Water_ConstVol.cpp
00003  * Definition file for a derived class that handles the calculation
00004  * of standard state thermo properties for pure water and
00005  * a set of species which have a constant molar volume pressure
00006  * dependence.
00007  * (see \ref thermoprops and class 
00008  * \link Cantera::VPSSMgr_Water_ConstVol VPSSMgr_Water_ConstVol\endlink).
00009  */
00010 
00011 /*
00012  * Copywrite (2005) Sandia Corporation. Under the terms of 
00013  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
00014  * U.S. Government retains certain rights in this software.
00015  */
00016 
00017 /*
00018  *  $Date: 2009-12-05 14:08:43 -0500 (Sat, 05 Dec 2009) $
00019  *  $Revision: 279 $
00020  */
00021 
00022 // turn off warnings under Windows
00023 #ifdef WIN32
00024 #pragma warning(disable:4786)
00025 #pragma warning(disable:4503)
00026 #endif
00027 
00028 #include "VPSSMgr_Water_ConstVol.h"
00029 #include "PDSS_Water.h"
00030 #include "PDSS_ConstVol.h"
00031 #include "GeneralSpeciesThermo.h"
00032 
00033 using namespace std;
00034 
00035 namespace Cantera {
00036 
00037   VPSSMgr_Water_ConstVol::VPSSMgr_Water_ConstVol(VPStandardStateTP *vp_ptr,
00038                                                  SpeciesThermo *spth) :
00039     VPSSMgr(vp_ptr, spth),
00040     m_waterSS(0)
00041   {
00042     m_useTmpRefStateStorage      = true;
00043     m_useTmpStandardStateStorage = true;
00044   }
00045 
00046 
00047   VPSSMgr_Water_ConstVol::~VPSSMgr_Water_ConstVol() 
00048   {
00049   }
00050 
00051   VPSSMgr_Water_ConstVol::VPSSMgr_Water_ConstVol(const VPSSMgr_Water_ConstVol &right) :
00052     VPSSMgr(right.m_vptp_ptr, right.m_spthermo)
00053   {
00054     m_useTmpRefStateStorage = true;
00055     m_useTmpStandardStateStorage = true;
00056     *this = right;
00057   }
00058 
00059 
00060   VPSSMgr_Water_ConstVol& 
00061   VPSSMgr_Water_ConstVol::operator=(const VPSSMgr_Water_ConstVol &b) 
00062   {
00063     if (&b == this) return *this;
00064     VPSSMgr::operator=(b);
00065     return *this;
00066   }
00067 
00068   VPSSMgr *
00069   VPSSMgr_Water_ConstVol::duplMyselfAsVPSSMgr() const {
00070     VPSSMgr_Water_ConstVol *vpm = new VPSSMgr_Water_ConstVol(*this);
00071     return (VPSSMgr *) vpm;
00072   }
00073 
00074   void 
00075   VPSSMgr_Water_ConstVol::initAllPtrs(VPStandardStateTP *vp_ptr, 
00076                                       SpeciesThermo *sp_ptr) {
00077     VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
00078     m_waterSS = dynamic_cast<PDSS_Water *>(m_vptp_ptr->providePDSS(0));
00079     if (!m_waterSS) {
00080       throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
00081                          "bad dynamic cast");
00082     }
00083   }
00084 
00085 
00086   void
00087   VPSSMgr_Water_ConstVol::getEnthalpy_RT_ref(doublereal *hrt) const{
00088     // Everything should be OK except for the water SS
00089     m_p0 = m_waterSS->pref_safe(m_tlast);
00090     if (m_p0 != m_plast) {
00091       doublereal RT = GasConstant * m_tlast;
00092       m_waterSS->setState_TP(m_tlast, m_p0);
00093       m_h0_RT[0] = (m_waterSS->enthalpy_mole()) / RT;
00094       m_waterSS->setState_TP(m_tlast, m_plast);
00095     } else {
00096       m_h0_RT[0] = m_hss_RT[0];
00097     }
00098     copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
00099   }
00100 
00101   void
00102   VPSSMgr_Water_ConstVol::getGibbs_RT_ref(doublereal *grt) const{
00103     // Everything should be OK except for the water SS
00104     m_p0 = m_waterSS->pref_safe(m_tlast);
00105     if (m_p0 != m_plast) {
00106       doublereal RT = GasConstant * m_tlast;
00107       m_waterSS->setState_TP(m_tlast, m_p0);
00108       m_g0_RT[0] = (m_waterSS->gibbs_mole()) / RT;
00109       m_waterSS->setState_TP(m_tlast, m_plast);
00110     } else {
00111       m_g0_RT[0] = m_gss_RT[0];
00112     }
00113     copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
00114   }
00115 
00116   void 
00117   VPSSMgr_Water_ConstVol::getGibbs_ref(doublereal *g) const{
00118     doublereal RT = GasConstant * m_tlast;
00119     getGibbs_RT_ref(g);
00120     for (int k = 0; k < m_kk; k++) {
00121       g[k] *= RT;
00122     }
00123   }
00124 
00125   void
00126   VPSSMgr_Water_ConstVol::getEntropy_R_ref(doublereal *sr) const{
00127     // Everything should be OK except for the water SS
00128     m_p0 = m_waterSS->pref_safe(m_tlast);
00129     if (m_p0 != m_plast) {
00130       m_waterSS->setState_TP(m_tlast, m_p0);
00131       m_s0_R[0] = (m_waterSS->entropy_mole()) / GasConstant;
00132       m_waterSS->setState_TP(m_tlast, m_plast);
00133     } else {
00134       m_s0_R[0] = m_sss_R[0];
00135     }
00136     copy(m_s0_R.begin(), m_s0_R.end(), sr);
00137   }
00138 
00139   void
00140   VPSSMgr_Water_ConstVol::getCp_R_ref(doublereal *cpr) const{
00141     // Everything should be OK except for the water SS
00142     m_p0 = m_waterSS->pref_safe(m_tlast);
00143     if (m_p0 != m_plast) {
00144       m_waterSS->setState_TP(m_tlast, m_p0);
00145       m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
00146       m_waterSS->setState_TP(m_tlast, m_plast);
00147     } else {
00148       m_cp0_R[0] = m_cpss_R[0];
00149     }
00150     copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
00151   }
00152 
00153   void
00154   VPSSMgr_Water_ConstVol::getStandardVolumes_ref(doublereal *vol) const{
00155     // Everything should be OK except for the water SS
00156     m_p0 = m_waterSS->pref_safe(m_tlast);
00157     if (m_p0 != m_plast) {
00158      m_waterSS->setState_TP(m_tlast, m_p0);
00159      m_V0[0] = m_vptp_ptr->molecularWeight(0) / m_waterSS->density();
00160      m_waterSS->setState_TP(m_tlast, m_plast);
00161     } else {
00162       m_V0[0] = m_Vss[0];
00163     }
00164     copy(m_V0.begin(), m_V0.end(), vol);
00165   }
00166 
00167   void VPSSMgr_Water_ConstVol::_updateRefStateThermo() const {
00168     m_p0 = m_waterSS->pref_safe(m_tlast);
00169     m_spthermo->update(m_tlast, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
00170     for (int k = 0; k < m_kk; k++) {
00171       m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
00172       PDSS *kPDSS = m_vptp_ptr->providePDSS(k);
00173       kPDSS->setTemperature(m_tlast);
00174     }
00175     doublereal RT = GasConstant * m_tlast;
00176     m_waterSS->setState_TP(m_tlast, m_p0);
00177     m_h0_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
00178     m_s0_R[0]  = (m_waterSS->entropy_mole()) / GasConstant;
00179     m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
00180     m_g0_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
00181     m_V0[0]    =  m_vptp_ptr->molecularWeight(0) / (m_waterSS->density());
00182     m_waterSS->setState_TP(m_tlast, m_plast);
00183   }
00184 
00185  
00186 
00187   void VPSSMgr_Water_ConstVol::_updateStandardStateThermo() {
00188  
00189     doublereal RT = GasConstant * m_tlast;
00190     doublereal del_pRT = (m_plast - OneAtm) / (RT);
00191  
00192     for (int k = 1; k < m_kk; k++) {
00193       m_hss_RT[k]  = m_h0_RT[k] + del_pRT * m_Vss[k];
00194       m_cpss_R[k]  = m_cp0_R[k];
00195       m_sss_R[k]   = m_s0_R[k];
00196       m_gss_RT[k]  = m_hss_RT[k] - m_sss_R[k];
00197       // m_Vss[k] constant
00198       PDSS *kPDSS = m_vptp_ptr->providePDSS(k);
00199       kPDSS->setState_TP(m_tlast, m_plast);
00200     }
00201     // Do the water
00202     m_waterSS->setState_TP(m_tlast, m_plast);
00203     m_hss_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
00204     m_sss_R[0]  = (m_waterSS->entropy_mole()) / GasConstant;
00205     m_cpss_R[0] = (m_waterSS->cp_mole())      / GasConstant;
00206     m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
00207     m_Vss[0]    = (m_vptp_ptr->molecularWeight(0) / m_waterSS->density());
00208   }
00209 
00210 
00211   void VPSSMgr_Water_ConstVol::initThermo() {
00212     VPSSMgr::initThermo();
00213   }
00214 
00215   void 
00216   VPSSMgr_Water_ConstVol::initThermoXML(XML_Node& phaseNode, std::string id) {
00217     VPSSMgr::initThermoXML(phaseNode, id);
00218    
00219     XML_Node& speciesList = phaseNode.child("speciesArray");
00220     XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
00221                                          &phaseNode.root());
00222     const vector<string>&sss = m_vptp_ptr->speciesNames();
00223 
00224 
00225     if (!m_waterSS) {
00226       throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
00227                          "bad dynamic cast");
00228     }
00229     
00230     m_waterSS->setState_TP(300., OneAtm);
00231     m_Vss[0] =  (m_waterSS->density())      / m_vptp_ptr->molecularWeight(0);
00232 
00233     for (int k = 1; k < m_kk; k++) {
00234       const XML_Node* s =  speciesDB->findByAttr("name", sss[k]);
00235       if (!s) {
00236         throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
00237                            "no species Node for species " + sss[k]);
00238       }
00239       const XML_Node *ss = s->findByName("standardState");
00240       if (!ss) {
00241         std::string sName = s->operator[]("name");
00242         throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
00243                            "no standardState Node for species " + sName);
00244       }
00245       std::string model = (*ss)["model"];
00246       if (model != "constant_incompressible") {
00247         std::string sName = s->operator[]("name");
00248         throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
00249                            "standardState model for species isn't "
00250                            "constant_incompressible: " + sName);
00251       }
00252       m_Vss[k] = getFloat(*ss, "molarVolume", "toSI");
00253     }   
00254   }
00255 
00256   PDSS*
00257   VPSSMgr_Water_ConstVol::createInstallPDSS(int k, const XML_Node& speciesNode,  
00258                                             const XML_Node * const phaseNode_ptr) {
00259     
00260     PDSS *kPDSS = 0;
00261     // Will have to do something for water 
00262     // -> make sure it's species 0
00263     // -> make sure it's designated as a real water EOS
00264     if (k == 0) {
00265       string xn = speciesNode["name"];
00266       if (xn != "H2O(L)") {
00267         throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
00268                            "h2o wrong name: " + xn);
00269       }
00270       const XML_Node *ss = speciesNode.findByName("standardState");
00271       std::string model = (*ss)["model"];
00272       if (model != "waterIAPWS" && model != "waterPDSS") {
00273         throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
00274                            "wrong SS mode: " + model);
00275       }
00276       if (m_waterSS) delete m_waterSS;
00277       m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
00278       GeneralSpeciesThermo *genSpthermo = dynamic_cast<GeneralSpeciesThermo *>(m_spthermo);
00279       if (!genSpthermo) {
00280         throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
00281                            "failed dynamic cast");
00282       }
00283       genSpthermo->installPDSShandler(k, m_waterSS, this);
00284       kPDSS = m_waterSS;
00285     } else {
00286 
00287       VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
00288 
00289       const XML_Node *ss = speciesNode.findByName("standardState");
00290       if (!ss) {
00291         throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
00292                            "no standardState Node for species " + speciesNode.name());
00293       }
00294       std::string model = (*ss)["model"];
00295       if (model != "constant_incompressible") {
00296         throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
00297                            "standardState model for species isn't "
00298                            "constant_incompressible: " + speciesNode.name());
00299       }
00300       if ((int) m_Vss.size() < k+1) {
00301         m_Vss.resize(k+1, 0.0);
00302       }
00303       m_Vss[k] = getFloat(*ss, "molarVolume", "toSI");
00304 
00305       // instantiate a new kPDSS object
00306       kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
00307     }
00308     return kPDSS;
00309   }
00310 
00311   PDSS_enumType VPSSMgr_Water_ConstVol::reportPDSSType(int k) const {
00312     return cPDSS_UNDEF;
00313   }
00314 
00315   VPSSMgr_enumType VPSSMgr_Water_ConstVol::reportVPSSMgrType() const {
00316     return cVPSSMGR_WATER_CONSTVOL;
00317   }
00318 }
00319 
00320 
Generated by  doxygen 1.6.3