Exemplo n.º 1
0
  /*
   * molecularWeight()
   *
   *  Returns the molecular weight of a species given the species index
   *
   *  units = kg / kmol.
   */
  doublereal Constituents::molecularWeight(int k) const {
    if (k < 0 || k >= nSpecies()) {
      throw SpeciesRangeError("Constituents::molecularWeight",
			      k, nSpecies());
    }
    return m_weight[k];
  }
void ThermoPhase::reportCSV(std::ofstream& csvFile) const
{
    int tabS = 15;
    int tabM = 30;
    csvFile.precision(8);
    vector_fp X(nSpecies());
    getMoleFractions(&X[0]);
    std::vector<std::string> pNames;
    std::vector<vector_fp> data;
    getCsvReportData(pNames, data);

    csvFile << setw(tabS) << "Species,";
    for (size_t i = 0; i < pNames.size(); i++) {
        csvFile << setw(tabM) << pNames[i] << ",";
    }
    csvFile << endl;
    for (size_t k = 0; k < nSpecies(); k++) {
        csvFile << setw(tabS) << speciesName(k) + ",";
        if (X[k] > SmallNumber) {
            for (size_t i = 0; i < pNames.size(); i++) {
                csvFile << setw(tabM) << data[i][k] << ",";
            }
            csvFile << endl;
        } else {
            for (size_t i = 0; i < pNames.size(); i++) {
                csvFile << setw(tabM) << 0 << ",";
            }
            csvFile << endl;
        }
    }
}
Exemplo n.º 3
0
 /*
  * Returns the number of atoms of element \c m in species \c k.
  */
 doublereal Constituents::nAtoms(int k, int m) const
 {
   const int m_mm = m_Elements->nElements();
   if (m < 0 || m >=m_mm)
     throw ElementRangeError("Constituents::nAtoms",m,nElements());
   if (k < 0 || k >= nSpecies())
     throw SpeciesRangeError("Constituents::nAtoms",k,nSpecies());
   return m_speciesComp[m_mm * k + m];
 }
Exemplo n.º 4
0
void Phase::restoreState(size_t lenstate, const doublereal* state)
{
    if (lenstate >= nSpecies() + 2) {
        setMassFractions_NoNorm(state + 2);
        setTemperature(state[0]);
        setDensity(state[1]);
    } else {
        throw ArraySizeError("Phase::restoreState",
                             lenstate,nSpecies()+2);
    }
}
Exemplo n.º 5
0
  /** 
   *  Finished adding species, prepare to use them for calculation
   *  of mixture properties.
   */
  void Phase::freezeSpecies() {
    Constituents::freezeSpecies();
    init(Constituents::molecularWeights());
    int kk = nSpecies();
    int nv = kk + 2;
    m_data.resize(nv,0.0);
    m_data[0] = 300.0;
    m_data[1] = 0.001;
    m_data[2] = 1.0;

    //setState_TRY(300.0, density(), &m_data[2]);

    m_kk = nSpecies();
  } 
Exemplo n.º 6
0
  void SurfPhase::
  setCoveragesByName(std::string cov) {
    int kk = nSpecies();
    int k;
    compositionMap cc;
    for (k = 0; k < kk; k++) { 
      cc[speciesName(k)] = -1.0;
    }
    parseCompString(cov, cc);
    doublereal c;
    vector_fp cv(kk, 0.0);
    bool ifound = false;
    for (k = 0; k < kk; k++) { 
      c = cc[speciesName(k)];
      if (c > 0.0) {
	ifound = true;
	cv[k] = c;
      }
    }
    if (!ifound) {
      throw CanteraError("SurfPhase::setCoveragesByName",
			 "Input coverages are all zero or negative");
    }
    setCoverages(DATA_PTR(cv));
  }
Exemplo n.º 7
0
  /**
   * @internal Initialize. This method is provided to allow
   * subclasses to perform any initialization required after all
   * species have been added. For example, it might be used to
   * resize internal work arrays that must have an entry for
   * each species.  The base class implementation does nothing,
   * and subclasses that do not require initialization do not
   * need to overload this method.  When importing a CTML phase
   * description, this method is called just prior to returning
   * from function importPhase.
   *
   * @see importCTML.cpp
   */
  void StoichSubstanceSSTP::initThermo() {
    /*
     * Make sure there is one and only one species in this phase.
     */
    m_kk = nSpecies();
    if (m_kk != 1) {
      throw CanteraError("initThermo",
			 "stoichiometric substances may only contain one species.");
    }
    doublereal tmin = m_spthermo->minTemp();
    doublereal tmax = m_spthermo->maxTemp();
    if (tmin > 0.0) m_tmin = tmin;
    if (tmax > 0.0) m_tmax = tmax;
    /*
     * Store the reference pressure in the variables for the class.
     */
    m_p0 = refPressure();

    /*
     * Resize temporary arrays.
     */
    int leng = 1;
    m_h0_RT.resize(leng);
    m_cp0_R.resize(leng);
    m_s0_R.resize(leng);
    /*
     * Call the base class thermo initializer
     */
    SingleSpeciesTP::initThermo();
  }
Exemplo n.º 8
0
 /**
  * Get the mole fractions by name. 
  */
 void Phase::getMoleFractionsByName(compositionMap& x) const {
   x.clear();
   int kk = nSpecies();
   for (int k = 0; k < kk; k++) {
     x[speciesName(k)] = State::moleFraction(k);
   }
 }
void ThermoPhase::getActivities(doublereal* a) const
{
    getActivityConcentrations(a);
    for (size_t k = 0; k < nSpecies(); k++) {
        a[k] /= standardConcentration(k);
    }
}
Exemplo n.º 10
0
void SingleSpeciesTP::initThermo()
{
    /*
     * Make sure there is one and only one species in this phase.
     */
    if (nSpecies() != 1) {
        throw CanteraError("initThermo",
                           "stoichiometric substances may only contain one species.");
    }

    /*
     * Resize temporary arrays.
     */
    m_h0_RT.resize(1);
    m_cp0_R.resize(1);
    m_s0_R.resize(1);

    /*
     *  Make sure the species mole fraction is equal to 1.0;
     */
    double x = 1.0;
    ThermoPhase::setMoleFractions(&x);
    /*
     * Call the base class initThermo object.
     */
    ThermoPhase::initThermo();
}
Exemplo n.º 11
0
 void Phase::setMassFractionsByName(const std::string& y) {
   compositionMap yy;
   int kk = nSpecies();
   for (int k = 0; k < kk; k++) { 
     yy[speciesName(k)] = -1.0;
   }
   parseCompString(y, yy);
   setMassFractionsByName(yy);
 }
Exemplo n.º 12
0
 doublereal Phase::chargeDensity() const {
   int k;
   int nsp = nSpecies();
   doublereal cdens = 0.0;
   for (k = 0; k < nsp; k++) 
     cdens += charge(k)*State::moleFraction(k);
   cdens *= Faraday;
   return cdens;
 }
Exemplo n.º 13
0
void Phase::setMassFractionsByName(const compositionMap& yMap)
{
    size_t kk = nSpecies();
    vector_fp mf(kk, 0.0);
    for (size_t k = 0; k < kk; k++) {
        mf[k] = std::max(getValue(yMap, speciesName(k), 0.0), 0.0);
    }
    setMassFractions(&mf[0]);
}
Exemplo n.º 14
0
/*
 * setMolalitiesByNames()
 *
 *   Set the molalities of the solutes by name
 */
void MolalityVPSSTP::setMolalitiesByName(const std::string& x)
{
    compositionMap xx;
    for (size_t k = 0; k < nSpecies(); k++) {
        xx[speciesName(k)] = -1.0;
    }
    parseCompString(x, xx);
    setMolalitiesByName(xx);
}
Exemplo n.º 15
0
 void Phase::setMoleFractionsByName(compositionMap& xMap) {
   int kk = nSpecies();
   doublereal x;
   vector_fp mf(kk, 0.0);
   for (int k = 0; k < kk; k++) {
     x = xMap[speciesName(k)];
     if (x > 0.0) mf[k] = x;
   }
   setMoleFractions(&mf[0]);
 }
Exemplo n.º 16
0
doublereal Phase::chargeDensity() const
{
    size_t kk = nSpecies();
    doublereal cdens = 0.0;
    for (size_t k = 0; k < kk; k++) {
        cdens += charge(k)*moleFraction(k);
    }
    cdens *= Faraday;
    return cdens;
}
void MixtureFugacityTP::initLengths()
{
    m_kk = nSpecies();
    moleFractions_.resize(m_kk, 0.0);
    moleFractions_[0] = 1.0;
    m_h0_RT.resize(m_kk, 0.0);
    m_cp0_R.resize(m_kk, 0.0);
    m_g0_RT.resize(m_kk, 0.0);
    m_s0_R.resize(m_kk, 0.0);
}
Exemplo n.º 18
0
 void Phase::setMassFractionsByName(compositionMap& yMap) {
   int kk = nSpecies();
   doublereal y;
   vector_fp mf(kk, 0.0);
   for (int k = 0; k < kk; k++) { 
     y = yMap[speciesName(k)];
     if (y > 0.0) mf[k] = y;
   }
   setMassFractions(&mf[0]);
 }
Exemplo n.º 19
0
void Phase::setMoleFractionsByName(const std::string& x)
{
    size_t kk = nSpecies();
    compositionMap xx;
    for (size_t k = 0; k < kk; k++) {
        xx[speciesName(k)] = -1.0;
    }
    parseCompString(x, xx);
    setMoleFractionsByName(xx);
}
Exemplo n.º 20
0
void ThermoPhase::resetHf298(size_t k) {
    if (k != npos) {
        m_spthermo->resetHf298(k);
    } else {
        for (size_t k = 0; k < nSpecies(); k++) {
            m_spthermo->resetHf298(k);
        }
    }
    invalidateCache();
}
Exemplo n.º 21
0
 //   Initialize lengths of local variables after all species have
 //   been identified.
 void  GibbsExcessVPSSTP::initLengths() {
   m_kk = nSpecies();
   moleFractions_.resize(m_kk);
   lnActCoeff_Scaled_.resize(m_kk);
   dlnActCoeffdT_Scaled_.resize(m_kk);
   d2lnActCoeffdT2_Scaled_.resize(m_kk);
   dlnActCoeffdlnX_diag_.resize(m_kk);
   dlnActCoeffdlnN_diag_.resize(m_kk);
   dlnActCoeffdlnN_.resize(m_kk, m_kk);
   m_pp.resize(m_kk);
 }
Exemplo n.º 22
0
void IdealMolalSoln::initThermo()
{
    MolalityVPSSTP::initThermo();
    for (size_t k = 0; k < nSpecies(); k++) {
        m_speciesMolarVolume[k] = providePDSS(k)->molarVolume();
    }
    if (IMS_typeCutoff_ == 2) {
        calcIMSCutoffParams_();
    }
    setMoleFSolventMin(1.0E-5);
}
Exemplo n.º 23
0
doublereal MixedSolventElectrolyte::cp_mole() const
{
    size_t kk = nSpecies();
    double cp = 0;
    vector_fp cpbar(kk);
    getPartialMolarCp(&cpbar[0]);
    for (size_t i = 0; i < kk; i++) {
        cp += moleFractions_[i]*cpbar[i];
    }
    return cp;
}
Exemplo n.º 24
0
doublereal MixedSolventElectrolyte::entropy_mole() const
{
    size_t kk = nSpecies();
    double s = 0;
    vector_fp sbar(kk);
    getPartialMolarEntropies(&sbar[0]);
    for (size_t i = 0; i < kk; i++) {
        s += moleFractions_[i]*sbar[i];
    }
    return s;
}
Exemplo n.º 25
0
doublereal MixedSolventElectrolyte::enthalpy_mole() const
{
    size_t kk = nSpecies();
    double h = 0;
    vector_fp hbar(kk);
    getPartialMolarEnthalpies(&hbar[0]);
    for (size_t i = 0; i < kk; i++) {
        h += moleFractions_[i]*hbar[i];
    }
    return h;
}
Exemplo n.º 26
0
void Phase::getMoleFractionsByName(compositionMap& x) const
{
    warn_deprecated("void Phase::getMoleFractionsByName(compositionMap&)",
                    "To be removed after Cantera 2.2. Use"
                    " 'compositionMap getMoleFractionsByName(double threshold)'"
                    " instead");
    x.clear();
    size_t kk = nSpecies();
    for (size_t k = 0; k < kk; k++) {
        x[speciesName(k)] = Phase::moleFraction(k);
    }
}
Exemplo n.º 27
0
  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();

    m_h0_RT.resize(m_kk);
    m_g0_RT.resize(m_kk);
    m_cp0_R.resize(m_kk);
    m_s0_R.resize(m_kk);
    setMolarDensity(m_molar_density);
  }
Exemplo n.º 28
0
 void Phase::setMoleFractionsByName(const std::string& x) {
   compositionMap xx;
   int kk = nSpecies();
   for (int k = 0; k < kk; k++) { 
     xx[speciesName(k)] = -1.0;
   }
   parseCompString(x, xx);
   setMoleFractionsByName(xx);
   //int kk = nSpecies();
   //vector_fp mf(kk);
   //for (int k = 0; k < kk; k++) { 
   //    mf[k] = xx[speciesName(k)];
   //}
   //setMoleFractions(mf.begin());
 }
Exemplo n.º 29
0
    void LatticeSolidPhase::initThermo() {
        m_kk = nSpecies();
        m_mm = nElements();
        m_x.resize(m_kk);
        int n, nsp, k, loc = 0;
        doublereal ndens;
        m_molar_density = 0.0;
        for (n = 0; n < m_nlattice; n++) {
            nsp = m_lattice[n]->nSpecies();
            ndens = m_lattice[n]->molarDensity();
            for (k = 0; k < nsp; k++) {
                m_x[loc] = ndens * m_lattice[n]->moleFraction(k);
                loc++;
            }
            m_molar_density += ndens;
        }
        setMoleFractions(DATA_PTR(m_x));

//          const vector<string>& 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));
    }
Exemplo n.º 30
0
    void ConstDensityThermo::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();

        m_h0_RT.resize(m_kk);
        m_g0_RT.resize(m_kk);
        m_expg0_RT.resize(m_kk);
        m_cp0_R.resize(m_kk);
        m_s0_R.resize(m_kk);
        m_pe.resize(m_kk, 0.0);
        m_pp.resize(m_kk);
    }