ConstDensityThermo.cpp

Go to the documentation of this file.
00001 /**
00002  *  @file ConstDensityThermo.cpp
00003  * Declarations for a Thermo manager for incompressible ThermoPhases 
00004  * (see \ref thermoprops and \link Cantera::ConstDensityThermo ConstDensityThermo
00005 \endlink).
00006  */
00007 /*
00008  * $Id: ConstDensityThermo.cpp 306 2009-12-09 17:29:23Z hkmoffa $
00009  *
00010  *  Copyright 2002 California Institute of Technology
00011  */
00012 
00013 #ifdef WIN32
00014 #pragma warning(disable:4786)
00015 #pragma warning(disable:4503)
00016 #endif
00017 
00018 #include "ct_defs.h"
00019 #include "mix_defs.h"
00020 #include "ConstDensityThermo.h"
00021 #include "SpeciesThermo.h"
00022 
00023 #include <cmath>
00024 
00025 namespace Cantera {
00026 
00027   ConstDensityThermo::ConstDensityThermo() : m_tlast(0.0) {
00028   }
00029 
00030 
00031   ConstDensityThermo::ConstDensityThermo(const ConstDensityThermo &right)
00032     : m_tlast(0.0) {
00033     *this = operator=(right);
00034   }
00035 
00036   ConstDensityThermo& ConstDensityThermo::operator=(const ConstDensityThermo &right) {
00037     if (&right == this) return *this;
00038 
00039     m_mm            = right.m_mm;
00040     m_tmin          = right.m_tmin;
00041     m_tmax          = right.m_tmax;
00042     m_p0            = right.m_p0;
00043     m_tlast         = right.m_tlast;
00044     m_h0_RT         = right.m_h0_RT;
00045     m_cp0_R         = right.m_cp0_R;
00046     m_g0_RT         = right.m_g0_RT;
00047     m_s0_R          = right.m_s0_R;
00048     m_expg0_RT      = right.m_expg0_RT;
00049     m_pe            = right.m_pe;
00050     m_pp            = right.m_pp;
00051     
00052     return *this;
00053 
00054   }
00055 
00056   SpeciesThermo *ConstDensityThermo::duplMyselfAsSpeciesThermo() const {
00057      ConstDensityThermo *cdt = new ConstDensityThermo(*this);
00058      return (SpeciesThermo *) cdt;
00059   }
00060     int ConstDensityThermo::
00061     eosType() const { return cIncompressible; }
00062 
00063     doublereal ConstDensityThermo::enthalpy_mole() const {
00064         doublereal p0 = m_spthermo->refPressure();
00065         return GasConstant * temperature() * 
00066             mean_X(&enthalpy_RT()[0]) 
00067             + (pressure() - p0)/molarDensity();
00068     }
00069 
00070     doublereal ConstDensityThermo::intEnergy_mole() const {
00071         doublereal p0 = m_spthermo->refPressure();
00072         return GasConstant * temperature() * 
00073             mean_X(&enthalpy_RT()[0]) 
00074             - p0/molarDensity();
00075     }
00076 
00077     doublereal ConstDensityThermo::entropy_mole() const {
00078         return GasConstant * (mean_X(&entropy_R()[0]) -
00079             sum_xlogx());
00080     }
00081 
00082     doublereal ConstDensityThermo::gibbs_mole() const {
00083         return enthalpy_mole() - temperature() * entropy_mole();
00084     }
00085 
00086     doublereal ConstDensityThermo::cp_mole() const {
00087         return GasConstant * mean_X(&cp_R()[0]);
00088     }
00089 
00090     doublereal ConstDensityThermo::cv_mole() const {
00091         return cp_mole();
00092     }
00093 
00094     doublereal ConstDensityThermo::pressure() const {
00095         return m_press;
00096     }
00097 
00098     void ConstDensityThermo::setPressure(doublereal p) {
00099         m_press = p;
00100     }
00101 
00102     void ConstDensityThermo::getActivityConcentrations(doublereal* c) const {
00103         getConcentrations(c);
00104     }
00105 
00106     void ConstDensityThermo::getActivityCoefficients(doublereal* ac) const {
00107         for (int k = 0; k < m_kk; k++) {
00108           ac[k] = 1.0;
00109         }
00110     }
00111 
00112     doublereal ConstDensityThermo::standardConcentration(int k) const {
00113         return molarDensity();
00114     }
00115 
00116     doublereal ConstDensityThermo::logStandardConc(int k) const {
00117         return log(molarDensity());
00118     }
00119 
00120     void ConstDensityThermo::getChemPotentials(doublereal* mu) const {
00121         doublereal vdp = (pressure() - m_spthermo->refPressure())/
00122                          molarDensity();
00123         doublereal xx;
00124         doublereal rt = temperature() * GasConstant;
00125         const array_fp& g_RT = gibbs_RT();
00126         for (int k = 0; k < m_kk; k++) {
00127             xx = fmaxx(SmallNumber, moleFraction(k));
00128             mu[k] = rt*(g_RT[k] + log(xx)) + vdp;
00129         }
00130     }
00131 
00132 
00133     void ConstDensityThermo::getStandardChemPotentials(doublereal* mu0) const {
00134         getPureGibbs(mu0);
00135     }
00136 
00137     void ConstDensityThermo::initThermo() {
00138         m_kk = nSpecies();
00139         m_mm = nElements();
00140         doublereal tmin = m_spthermo->minTemp();
00141         doublereal tmax = m_spthermo->maxTemp();
00142         if (tmin > 0.0) m_tmin = tmin;
00143         if (tmax > 0.0) m_tmax = tmax;
00144         m_p0 = refPressure();
00145 
00146         int leng = m_kk;
00147         m_h0_RT.resize(leng);
00148         m_g0_RT.resize(leng);
00149         m_expg0_RT.resize(leng);
00150         m_cp0_R.resize(leng);
00151         m_s0_R.resize(leng);
00152         m_pe.resize(leng, 0.0);
00153         m_pp.resize(leng);
00154     }
00155 
00156 
00157     void ConstDensityThermo::setToEquilState(const doublereal* lambda_RT) {
00158         throw CanteraError("setToEquilState","not yet impl.");
00159     }
00160 
00161     void ConstDensityThermo::_updateThermo() const {
00162         doublereal tnow = temperature();
00163         if (m_tlast != tnow) {
00164             m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], 
00165                 &m_s0_R[0]);
00166             m_tlast = tnow;
00167             int k;
00168             for (k = 0; k < m_kk; k++) {
00169                 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
00170             }
00171             m_tlast = tnow;
00172         }
00173     }
00174 
00175     void ConstDensityThermo::setParametersFromXML(const XML_Node& eosdata) {
00176         eosdata._require("model","Incompressible");
00177         doublereal rho = getFloat(eosdata, "density", "toSI");
00178         setDensity(rho);
00179     }
00180 
00181 }
00182 
00183 
00184 
00185 
Generated by  doxygen 1.6.3