From 1023b2bbcbc2e78a0483c18b6a22cdf6bba5b867 Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Fri, 26 May 2006 23:08:03 +0000 Subject: [PATCH] *** empty log message *** --- Cantera/src/LatticePhase.cpp | 127 +++++++++++++ Cantera/src/LatticePhase.cpp~ | 176 ------------------ .../src/{LatticePhase.h~ => LatticePhase.h} | 16 +- Cantera/src/mix_defs.h | 1 + Cantera/src/stringUtils.cpp | 27 +++ Cantera/src/stringUtils.h | 1 + Cantera/src/transport/MixTransport.cpp | 2 +- 7 files changed, 164 insertions(+), 186 deletions(-) create mode 100644 Cantera/src/LatticePhase.cpp delete mode 100644 Cantera/src/LatticePhase.cpp~ rename Cantera/src/{LatticePhase.h~ => LatticePhase.h} (90%) diff --git a/Cantera/src/LatticePhase.cpp b/Cantera/src/LatticePhase.cpp new file mode 100644 index 000000000..bc5e528bd --- /dev/null +++ b/Cantera/src/LatticePhase.cpp @@ -0,0 +1,127 @@ +/** + * + * @file LatticePhase.cpp + * + * $Id$ + */ + +#ifdef WIN32 +#pragma warning(disable:4786) +#pragma warning(disable:4503) +#endif + +#include "ct_defs.h" +#include "mix_defs.h" +#include "LatticePhase.h" +#include "SpeciesThermo.h" + +namespace Cantera { + + doublereal LatticePhase:: + enthalpy_mole() const { + doublereal p0 = m_spthermo->refPressure(); + return GasConstant * temperature() * + mean_X(&enthalpy_RT()[0]) + + (pressure() - p0)/molarDensity(); + } + + doublereal LatticePhase::intEnergy_mole() const { + doublereal p0 = m_spthermo->refPressure(); + return GasConstant * temperature() * + mean_X(&enthalpy_RT()[0]) + - p0/molarDensity(); + } + + doublereal LatticePhase::entropy_mole() const { + return GasConstant * (mean_X(&entropy_R()[0]) - + sum_xlogx()); + } + + doublereal LatticePhase::gibbs_mole() const { + return enthalpy_mole() - temperature() * entropy_mole(); + } + + doublereal LatticePhase::cp_mole() const { + return GasConstant * mean_X(&cp_R()[0]); + } + + void LatticePhase::getActivityConcentrations(doublereal* c) const { + getMoleFractions(c); + } + + void LatticePhase::getActivityCoefficients(doublereal* ac) const { + for (int k = 0; k < m_kk; k++) { + ac[k] = 1.0; + } + } + + doublereal LatticePhase::standardConcentration(int k) const { + return 1.0; + } + + doublereal LatticePhase::logStandardConc(int k) const { + return 0.0; + } + + void LatticePhase::getChemPotentials(doublereal* mu) const { + doublereal vdp = (pressure() - m_spthermo->refPressure())/ + molarDensity(); + doublereal xx; + doublereal rt = temperature() * GasConstant; + const array_fp& g_RT = gibbs_RT(); + for (int k = 0; k < m_kk; k++) { + xx = fmaxx(SmallNumber, moleFraction(k)); + mu[k] = rt*(g_RT[k] + log(xx)) + vdp; + } + } + + void LatticePhase::getStandardChemPotentials(doublereal* mu0) const { + getPureGibbs(mu0); + } + + void LatticePhase::initThermo() { + m_kk = nSpecies(); + m_mm = nElements(); + doublereal tmin = m_spthermo->minTemp(); + doublereal tmax = m_spthermo->maxTemp(); + if (tmin > 0.0) m_tmin = tmin; + if (tmax > 0.0) m_tmax = tmax; + m_p0 = refPressure(); + + int leng = m_kk; + m_h0_RT.resize(leng); + m_g0_RT.resize(leng); + m_cp0_R.resize(leng); + m_s0_R.resize(leng); + setMolarDensity(m_molar_density); + } + + + void LatticePhase::_updateThermo() const { + doublereal tnow = temperature(); + if (fabs(molarDensity() - m_molar_density)/m_molar_density > 0.0001) { + throw CanteraError("_updateThermo","molar density changed from " + +fp2str(m_molar_density)+" to "+fp2str(molarDensity())); + } + if (m_tlast != tnow) { + m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], + &m_s0_R[0]); + m_tlast = tnow; + int k; + for (k = 0; k < m_kk; k++) { + m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k]; + } + m_tlast = tnow; + } + } + + void LatticePhase::setParametersFromXML(const XML_Node& eosdata) { + eosdata._require("model","Lattice"); + m_molar_density = getFloat(i, "site_density", "-"); + m_vacancy = getString(i, "vacancy_species"); + } +} + + + + diff --git a/Cantera/src/LatticePhase.cpp~ b/Cantera/src/LatticePhase.cpp~ deleted file mode 100644 index 61bd55146..000000000 --- a/Cantera/src/LatticePhase.cpp~ +++ /dev/null @@ -1,176 +0,0 @@ -/** - * - * @file LatticeSolidPhase.cpp - * - * $Id$ - */ - -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#include "ct_defs.h" -#include "mix_defs.h" -#include "LatticeSolidPhase.h" -#include "SpeciesThermo.h" - -namespace Cantera { - - doublereal LatticeSolidPhase:: - enthalpy_mole() const { - doublereal p0 = m_spthermo->refPressure(); - return GasConstant * temperature() * - mean_X(&enthalpy_RT()[0]) - + (pressure() - p0)/molarDensity(); - } - - doublereal LatticeSolidPhase::intEnergy_mole() const { - doublereal p0 = m_spthermo->refPressure(); - return GasConstant * temperature() * - mean_X(&enthalpy_RT()[0]) - - p0/molarDensity(); - } - - doublereal LatticeSolidPhase::entropy_mole() const { - return GasConstant * (mean_X(&entropy_R()[0]) - - sum_xlogx()); - } - - doublereal LatticeSolidPhase::gibbs_mole() const { - return enthalpy_mole() - temperature() * entropy_mole(); - } - - doublereal LatticeSolidPhase::cp_mole() const { - return GasConstant * mean_X(&cp_R()[0]); - } - - void LatticeSolidPhase::getActivityConcentrations(doublereal* c) const { - getMoleFractions(c); - } - - void LatticeSolidPhase::getActivityCoefficients(doublereal* ac) const { - for (int k = 0; k < m_kk; k++) { - ac[k] = 1.0; - } - } - - doublereal LatticeSolidPhase::standardConcentration(int k) const { - return 1.0; - } - - doublereal LatticeSolidPhase::logStandardConc(int k) const { - return 0.0; - } - - void LatticeSolidPhase::getChemPotentials(doublereal* mu) const { - doublereal vdp = (pressure() - m_spthermo->refPressure())/ - molarDensity(); - doublereal xx; - doublereal rt = temperature() * GasConstant; - const array_fp& g_RT = gibbs_RT(); - for (int k = 0; k < m_kk; k++) { - xx = fmaxx(SmallNumber, moleFraction(k)); - mu[k] = rt*(g_RT[k] + log(xx)) + vdp; - } - } - - void LatticeSolidPhase::getStandardChemPotentials(doublereal* mu0) const { - getPureGibbs(mu0); - } - - void LatticeSolidPhase::initThermo() { - m_kk = nSpecies(); - m_mm = nElements(); - doublereal tmin = m_spthermo->minTemp(); - doublereal tmax = m_spthermo->maxTemp(); - if (tmin > 0.0) m_tmin = tmin; - if (tmax > 0.0) m_tmax = tmax; - m_p0 = refPressure(); - - int leng = m_kk; - m_h0_RT.resize(leng); - m_g0_RT.resize(leng); - m_cp0_R.resize(leng); - m_s0_R.resize(leng); - setMolarDensity(m_molar_density); - - const vector& spnames = speciesNames(); - int n, k, kl, namesize; - int nl = m_sitedens.size(); - string s; - m_lattice.resize(m_kk,-1); - vector_fp conc(m_kk, 0.0); - - compositionMap xx; - for (n = 0; n < nl; n++) { - for (k = 0; k < m_kk; k++) { - xx[speciesName(k)] = -1.0; - } - parseCompString(m_sp[n], xx); - for (k = 0; k < m_kk; k++) { - if (xx[speciesName(k)] != -1.0) { - conc[k] = m_sitedens[n]*xx[speciesName(k)]; - m_lattice[k] = n; - } - } - - } - for (k = 0; k < m_kk; k++) { - if (m_lattice[k] == -1) { - throw CanteraError("LatticeSolidPhase::" - "setParametersFromXML","Species "+speciesName(k) - +" not a member of any lattice."); - } - } - setMoleFractions(DATA_PTR(conc)); - } - - - void LatticeSolidPhase::_updateThermo() const { - doublereal tnow = temperature(); - if (fabs(molarDensity() - m_molar_density)/m_molar_density > 0.0001) { - throw CanteraError("_updateThermo","molar density changed from " - +fp2str(m_molar_density)+" to "+fp2str(molarDensity())); - } - if (m_tlast != tnow) { - m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], - &m_s0_R[0]); - m_tlast = tnow; - int k; - for (k = 0; k < m_kk; k++) { - m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k]; - } - m_tlast = tnow; - } - } - - void LatticeSolidPhase::setParametersFromXML(const XML_Node& eosdata) { - eosdata._require("model","LatticeSolid"); - XML_Node& la = eosdata.child("LatticeArray"); - vector lattices; - la.getChildren("Lattice",lattices); - int n; - int nl = lattices.size(); - doublereal site_density; - string vacancy; - doublereal sum = 0.0; - string s; - for (n = 0; n < nl; n++) { - XML_Node& i = *lattices[n]; - site_density = getFloat(i, "site_density", "-"); - vacancy = getString(i, "vacancy_species"); - s = getString(i, "species"); - m_sp.push_back(s); - m_vac.push_back(vacancy); - m_sitedens.push_back(site_density); - sum += site_density; - } - m_molar_density = sum; - } - -} - - - - diff --git a/Cantera/src/LatticePhase.h~ b/Cantera/src/LatticePhase.h similarity index 90% rename from Cantera/src/LatticePhase.h~ rename to Cantera/src/LatticePhase.h index bac65af91..04cfe779e 100644 --- a/Cantera/src/LatticePhase.h~ +++ b/Cantera/src/LatticePhase.h @@ -1,6 +1,6 @@ /** * - * @file LatticeSolidPhase.h + * @file LatticePhase.h */ /* $Author$ @@ -11,8 +11,8 @@ * */ -#ifndef CT_LATTICESOLID_H -#define CT_LATTICESOLID_H +#ifndef CT_LATTICE_H +#define CT_LATTICE_H #include "ct_defs.h" #include "mix_defs.h" @@ -23,18 +23,16 @@ namespace Cantera { /** - * Overloads the virtual methods of class Thermo to implement the - * incompressible equation of state. */ - class LatticeSolidPhase : public ThermoPhase { + class LatticePhase : public ThermoPhase { public: - LatticeSolidPhase() : m_tlast(0.0) {} + LatticePhase() : m_tlast(0.0) {} - virtual ~LatticeSolidPhase() {} + virtual ~LatticePhase() {} - virtual int eosType() const { return cLatticeSolid; } + virtual int eosType() const { return cLattice; } virtual doublereal enthalpy_mole() const; diff --git a/Cantera/src/mix_defs.h b/Cantera/src/mix_defs.h index 4d762223d..df6d4f0d6 100755 --- a/Cantera/src/mix_defs.h +++ b/Cantera/src/mix_defs.h @@ -42,6 +42,7 @@ namespace Cantera { const int cStoichSubstance = 5; // StoichSubstance.h const int cLatticeSolid = 20; // LatticeSolidPhase.h + const int cLattice = 21; // pure fluids with liquid/vapor eqs of state const int cPureFluid = 10; diff --git a/Cantera/src/stringUtils.cpp b/Cantera/src/stringUtils.cpp index 1657dfbab..8fd982152 100755 --- a/Cantera/src/stringUtils.cpp +++ b/Cantera/src/stringUtils.cpp @@ -124,6 +124,33 @@ namespace Cantera { while (s != ""); } + + + /** + * Parse a composition string. + */ + void split(const string ss, vector& w) { + string s = ss; + string::size_type icolon, ibegin, iend; + string name, num, nm; + do { + ibegin = s.find_first_not_of(", ;\n\t"); + if (ibegin != string::npos) { + s = s.substr(ibegin,s.size()); + iend = s.find_first_of(", ;\n\t"); + if (iend != string::npos) { + w.push_back(s.substr(0, iend)); + s = s.substr(iend+1, s.size()); + } + else { + w.push_back(s.substr(0, s.size())); + return; + } + } + } + while (s != ""); + } + int fillArrayFromString(const string& str, doublereal* a, char delim) { string::size_type iloc; int count = 0; diff --git a/Cantera/src/stringUtils.h b/Cantera/src/stringUtils.h index ebe4a0c7a..b95407615 100755 --- a/Cantera/src/stringUtils.h +++ b/Cantera/src/stringUtils.h @@ -23,6 +23,7 @@ namespace Cantera { string stripnonprint(string s); string lowercase(string s); void parseCompString(const string ss, compositionMap& x); + void split(const string ss, vector& w); int fillArrayFromString(const string& str, doublereal* a, char delim = ' '); string report(const ThermoPhase& th, bool show_thermo = true); string formatCompList(const Phase& mix, int xyc); diff --git a/Cantera/src/transport/MixTransport.cpp b/Cantera/src/transport/MixTransport.cpp index 79c9b3251..7bd332c39 100755 --- a/Cantera/src/transport/MixTransport.cpp +++ b/Cantera/src/transport/MixTransport.cpp @@ -133,7 +133,7 @@ namespace Cantera { * and * \f[ * \Phi_{k,j} = \frac{\left[1 - * + \sqrt\left(\frac{\mu_k}{\mu_j}\sqrt{\frac{M_j}{M_k}}\right)\right]^2} + * + \sqrt{\left(\frac{\mu_k}{\mu_j}\sqrt{\frac{M_j}{M_k}}\right)}\right]^2} * {\sqrt{8}\sqrt{1 + M_k/M_j}} * \f] * @see updateViscosity_T();