LatticePhase.cpp

Go to the documentation of this file.
00001 /**
00002  *
00003  *  @file LatticePhase.cpp
00004  *  Definitions for a simple thermodynamics model of a bulk phase
00005  *  derived from ThermoPhase,
00006  *  assuming a lattice of solid atoms
00007  *  (see \ref thermoprops and class \link Cantera::LatticePhase LatticePhase\endlink).
00008  *
00009  */
00010 /*
00011  * $Id: LatticePhase.cpp 279 2009-12-05 19:08:43Z hkmoffa $
00012  */
00013 
00014 #include "config.h"
00015 #ifdef WITH_LATTICE_SOLID
00016 
00017 #ifdef WIN32
00018 #pragma warning(disable:4786)
00019 #pragma warning(disable:4503)
00020 #endif
00021 
00022 #include "ct_defs.h"
00023 #include "mix_defs.h"
00024 #include "LatticePhase.h"
00025 #include "SpeciesThermo.h"
00026 
00027 #include <cmath>
00028 
00029 namespace Cantera {
00030 
00031   // Base Empty constructor
00032   LatticePhase::LatticePhase() :
00033     m_tlast(0.0) 
00034   {
00035   }
00036   
00037   // Copy Constructor
00038   /*
00039    * @param right Object to be copied
00040    */
00041   LatticePhase::LatticePhase(const LatticePhase &right) :
00042     m_tlast(0.0)
00043   {
00044     *this = operator=(right);
00045   }
00046   
00047   // Assignment operator
00048   /*
00049    * @param right Object to be copied
00050    */
00051   LatticePhase& LatticePhase::operator=(const LatticePhase& right) {
00052     if (&right != this) {
00053       ThermoPhase::operator=(right);
00054       m_mm         = right.m_mm;
00055       m_tmin       = right.m_tmin;
00056       m_tmax       = right.m_tmax;
00057       m_p0         = right.m_p0;
00058       m_tlast      = right.m_tlast;
00059       m_h0_RT      = right.m_h0_RT;
00060       m_cp0_R      = right.m_cp0_R;
00061       m_g0_RT      = right.m_g0_RT;
00062       m_s0_R       = right.m_s0_R;
00063       m_press      = right.m_press;
00064       m_vacancy    = right.m_vacancy;
00065       m_molar_density = right.m_molar_density;
00066     }
00067     return *this;
00068   }
00069   
00070   // Destructor
00071   LatticePhase::~LatticePhase() {
00072   }
00073   
00074   // Duplication function
00075   /*
00076    * This virtual function is used to create a duplicate of the
00077    * current phase. It's used to duplicate the phase when given
00078    * a ThermoPhase pointer to the phase.
00079    *
00080    * @return It returns a ThermoPhase pointer.
00081    */
00082   ThermoPhase *LatticePhase::duplMyselfAsThermoPhase() const {
00083     LatticePhase *igp = new LatticePhase(*this);
00084     return (ThermoPhase *) igp;
00085   }
00086   
00087   
00088   doublereal LatticePhase::
00089   enthalpy_mole() const {
00090     doublereal p0 = m_spthermo->refPressure();
00091     return GasConstant * temperature() * 
00092       mean_X(&enthalpy_RT_ref()[0]) 
00093       + (pressure() - p0)/molarDensity();
00094   }
00095 
00096   doublereal LatticePhase::intEnergy_mole() const {
00097     doublereal p0 = m_spthermo->refPressure();
00098     return GasConstant * temperature() * 
00099       mean_X(&enthalpy_RT_ref()[0]) 
00100       - p0/molarDensity();
00101   }
00102 
00103   doublereal LatticePhase::entropy_mole() const {
00104     return GasConstant * (mean_X(&entropy_R_ref()[0]) -
00105                           sum_xlogx());
00106   }
00107 
00108   doublereal LatticePhase::gibbs_mole() const {
00109     return enthalpy_mole() - temperature() * entropy_mole();
00110   }
00111 
00112   doublereal LatticePhase::cp_mole() const {
00113     return GasConstant * mean_X(&cp_R_ref()[0]);
00114   }
00115 
00116   doublereal LatticePhase::cv_mole() const {
00117     return cp_mole();
00118   }
00119   
00120   
00121 
00122   void LatticePhase::setPressure(doublereal p) {
00123     m_press = p;
00124     setMolarDensity(m_molar_density);
00125   }
00126 
00127   void LatticePhase::getActivityConcentrations(doublereal* c) const {
00128     getMoleFractions(c);
00129   }
00130 
00131   void LatticePhase::getActivityCoefficients(doublereal* ac) const {
00132     for (int k = 0; k < m_kk; k++) {
00133       ac[k] = 1.0;
00134     }
00135   }
00136 
00137   doublereal LatticePhase::standardConcentration(int k) const {
00138     return 1.0;
00139   }
00140 
00141   doublereal LatticePhase::logStandardConc(int k) const {
00142     return 0.0;
00143   }
00144 
00145   void LatticePhase::getChemPotentials(doublereal* mu) const {
00146     doublereal vdp = ((pressure() - m_spthermo->refPressure())/
00147                       molarDensity());
00148     doublereal xx;
00149     doublereal rt = temperature() * GasConstant;
00150     const array_fp& g_RT = gibbs_RT_ref();
00151     for (int k = 0; k < m_kk; k++) {
00152       xx = fmaxx(SmallNumber, moleFraction(k));
00153       mu[k] = rt*(g_RT[k] + log(xx)) + vdp;
00154     }
00155   }
00156 
00157   void LatticePhase::getPartialMolarVolumes(doublereal* vbar) const {
00158     getStandardVolumes(vbar); 
00159   }
00160 
00161   void LatticePhase::getStandardChemPotentials(doublereal* mu0) const {
00162     const array_fp& gibbsrt = gibbs_RT_ref();
00163     scale(gibbsrt.begin(), gibbsrt.end(), mu0, _RT());
00164   }
00165   
00166   void LatticePhase::getPureGibbs(doublereal* gpure) const {
00167     const array_fp& gibbsrt = gibbs_RT_ref();
00168     scale(gibbsrt.begin(), gibbsrt.end(), gpure, _RT());
00169   }
00170 
00171   void LatticePhase::getEnthalpy_RT(doublereal* hrt) const {
00172     const array_fp& _h = enthalpy_RT_ref();
00173     std::copy(_h.begin(), _h.end(), hrt);
00174     doublereal tmp = (pressure() - m_p0) / (molarDensity() * GasConstant * temperature());
00175     for (int k = 0; k < m_kk; k++) {
00176       hrt[k] += tmp;
00177     }
00178   }
00179 
00180   void LatticePhase::getEntropy_R(doublereal* sr) const {
00181     const array_fp& _s = entropy_R_ref();
00182     std::copy(_s.begin(), _s.end(), sr);
00183   }
00184 
00185   void LatticePhase::getGibbs_RT(doublereal* grt) const {
00186     const array_fp& gibbsrt = gibbs_RT_ref();
00187     std::copy(gibbsrt.begin(), gibbsrt.end(), grt);
00188   }
00189 
00190   void LatticePhase::getCp_R(doublereal* cpr) const {
00191     const array_fp& _cpr = cp_R_ref();
00192     std::copy(_cpr.begin(), _cpr.end(), cpr);
00193   }
00194 
00195   void LatticePhase::getStandardVolumes(doublereal* vbar) const {
00196     doublereal vv = 1.0/m_molar_density;
00197     for (int k = 0; k < m_kk; k++) {
00198       vbar[k] = vv;
00199     }
00200   }
00201 
00202   void LatticePhase::initThermo() {
00203     m_kk = nSpecies();
00204     m_mm = nElements();
00205     doublereal tmin = m_spthermo->minTemp();
00206     doublereal tmax = m_spthermo->maxTemp();
00207     if (tmin > 0.0) m_tmin = tmin;
00208     if (tmax > 0.0) m_tmax = tmax;
00209     m_p0 = refPressure();
00210 
00211     int leng = m_kk;
00212     m_h0_RT.resize(leng);
00213     m_g0_RT.resize(leng);
00214     m_cp0_R.resize(leng);
00215     m_s0_R.resize(leng);
00216     setMolarDensity(m_molar_density);
00217   }
00218 
00219 
00220   void LatticePhase::_updateThermo() const {
00221     doublereal tnow = temperature();
00222     if (fabs(molarDensity() - m_molar_density)/m_molar_density > 0.0001) {
00223       throw CanteraError("_updateThermo","molar density changed from "
00224                          +fp2str(m_molar_density)+" to "+fp2str(molarDensity()));
00225     }
00226     if (m_tlast != tnow) {
00227       m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], 
00228                          &m_s0_R[0]);
00229       m_tlast = tnow;
00230       int k;
00231       for (k = 0; k < m_kk; k++) {
00232         m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
00233       }
00234       m_tlast = tnow;
00235     }
00236   }
00237 
00238   void LatticePhase::setParameters(int n, doublereal* const c) {
00239     m_molar_density = c[0];
00240     setMolarDensity(m_molar_density);
00241   }
00242 
00243   void LatticePhase::getParameters(int &n, doublereal * const c) const {
00244     double d = molarDensity();
00245     c[0] = d;
00246     n = 1;
00247   }
00248 
00249   void LatticePhase::setParametersFromXML(const XML_Node& eosdata) {
00250     eosdata._require("model","Lattice");
00251     m_molar_density = getFloat(eosdata, "site_density", "toSI");
00252     m_vacancy = getChildValue(eosdata, "vacancy_species");
00253   }
00254 }
00255 
00256 #endif
Generated by  doxygen 1.6.3