void IdealMolalSoln::getPartialMolarEntropies(doublereal* sbar) const { getEntropy_R(sbar); calcMolalities(); if (IMS_typeCutoff_ == 0) { for (size_t k = 1; k < m_kk; k++) { doublereal mm = std::max(SmallNumber, m_molalities[k]); sbar[k] -= GasConstant * log(mm); } double xmolSolvent = moleFraction(0); sbar[0] -= (GasConstant * (xmolSolvent - 1.0) / xmolSolvent); } else { // Update the activity coefficients, This also update the internally // stored molalities. s_updateIMS_lnMolalityActCoeff(); // First we will add in the obvious dependence on the T term out front // of the log activity term doublereal mm; for (size_t k = 1; k < m_kk; k++) { mm = std::max(SmallNumber, m_molalities[k]); sbar[k] -= GasConstant * (log(mm) + IMS_lnActCoeffMolal_[k]); } double xmolSolvent = moleFraction(0); mm = std::max(SmallNumber, xmolSolvent); sbar[0] -= GasConstant *(log(mm) + IMS_lnActCoeffMolal_[0]); } }
void IdealMolalSoln::getActivities(doublereal* ac) const { _updateStandardStateThermo(); // Update the molality array, m_molalities(). This requires an update due to // mole fractions if (IMS_typeCutoff_ == 0) { calcMolalities(); for (size_t k = 0; k < m_kk; k++) { ac[k] = m_molalities[k]; } double xmolSolvent = moleFraction(0); // Limit the activity coefficient to be finite as the solvent mole // fraction goes to zero. xmolSolvent = std::max(m_xmolSolventMIN, xmolSolvent); ac[0] = exp((xmolSolvent - 1.0)/xmolSolvent); } else { s_updateIMS_lnMolalityActCoeff(); // Now calculate the array of activities. for (size_t k = 1; k < m_kk; k++) { ac[k] = m_molalities[k] * exp(IMS_lnActCoeffMolal_[k]); } double xmolSolvent = moleFraction(0); ac[0] = exp(IMS_lnActCoeffMolal_[0]) * xmolSolvent; } }
void IdealSolnGasVPSS::getActivityConcentrations(doublereal* c) const { if (m_idealGas) { getConcentrations(c); } else { int k; const vector_fp& vss = m_VPSS_ptr->standardVolumes(); switch (m_formGC) { case 0: for (k = 0; k < m_kk; k++) { c[k] = moleFraction(k); } break; case 1: for (k = 0; k < m_kk; k++) { c[k] = moleFraction(k) / vss[k]; } break; case 2: for (k = 0; k < m_kk; k++) { c[k] = moleFraction(k) / vss[0]; } break; } } }
/*! * \brief Return the molar density of a fluid phase [mol/m^3]. */ Scalar molarDensity(unsigned phaseIdx) const { const auto& rho = density(phaseIdx); if (phaseIdx == waterPhaseIdx) return rho/FluidSystem::molarMass(waterCompIdx, pvtRegionIdx_); return rho*(moleFraction(phaseIdx, gasCompIdx)/FluidSystem::molarMass(gasCompIdx, pvtRegionIdx_) + moleFraction(phaseIdx, oilCompIdx)/FluidSystem::molarMass(oilCompIdx, pvtRegionIdx_)); }
/*! * \brief Return the fugacity of a component in a fluid phase [Pa]. */ Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const { return fugacityCoefficient(phaseIdx, compIdx) *moleFraction(phaseIdx, compIdx) *pressure(phaseIdx); }
/*! * \brief Return the partial molar density of a fluid phase [kg / mol]. */ Scalar averageMolarMass(unsigned phaseIdx) const { Scalar result(0.0); for (unsigned compIdx = 0; compIdx < numComponents; ++ compIdx) result += FluidSystem::molarMass(compIdx, pvtRegionIdx_)*moleFraction(phaseIdx, compIdx); return result; }
void MaskellSolidSolnPhase::getActivityConcentrations(doublereal* c) const { getActivityCoefficients(c); for (size_t sp = 0; sp < m_kk; ++sp) { c[sp] *= moleFraction(sp); } }
doublereal Phase::chargeDensity() const { doublereal cdens = 0.0; for (size_t k = 0; k < m_kk; k++) { cdens += charge(k)*moleFraction(k); } return cdens * Faraday; }
void IdealGasPhase::getChemPotentials(doublereal* mu) const { getStandardChemPotentials(mu); for (size_t k = 0; k < m_kk; k++) { double xx = std::max(SmallNumber, moleFraction(k)); mu[k] += RT() * log(xx); } }
doublereal MaskellSolidSolnPhase::enthalpy_mole() const { _updateThermo(); const doublereal h0 = RT() * mean_X(m_h0_RT); const doublereal r = moleFraction(product_species_index); const doublereal fmval = fm(r); return h0 + r * fmval * h_mixing; }
doublereal Phase::elementalMoleFraction(const size_t m) const { checkElementIndex(m); double denom = 0; for (size_t k = 0; k < m_kk; k++) { double atoms = 0; for (size_t j = 0; j < nElements(); j++) { atoms += nAtoms(k, j); } denom += atoms * moleFraction(k); } doublereal numerator = 0.0; for (size_t k = 0; k != m_kk; ++k) { numerator += nAtoms(k, m) * moleFraction(k); } return numerator / denom; }
void LatticePhase::getPartialMolarEntropies(doublereal* sbar) const { const vector_fp& _s = entropy_R_ref(); for (size_t k = 0; k < m_kk; k++) { double xx = std::max(SmallNumber, moleFraction(k)); sbar[k] = GasConstant * (_s[k] - log(xx)); } }
void MolalityVPSSTP::getActivityCoefficients(doublereal* ac) const { getMolalityActivityCoefficients(ac); AssertThrow(m_indexSolvent==0, "MolalityVPSSTP::getActivityCoefficients"); double xmolSolvent = std::max(moleFraction(m_indexSolvent), m_xmolSolventMIN); for (size_t k = 1; k < m_kk; k++) { ac[k] /= xmolSolvent; } }
void IdealSolnGasVPSS::getPartialMolarEntropies(doublereal* sbar) const { getEntropy_R(sbar); doublereal r = GasConstant; scale(sbar, sbar+m_kk, sbar, r); for (int k = 0; k < m_kk; k++) { doublereal xx = fmaxx(SmallNumber, moleFraction(k)); sbar[k] += r * ( - log(xx)); } }
void IdealGasPhase::getChemPotentials(doublereal* mu) const { getStandardChemPotentials(mu); doublereal rt = temperature() * GasConstant; for (size_t k = 0; k < m_kk; k++) { double xx = std::max(SmallNumber, moleFraction(k)); mu[k] += rt * (log(xx)); } }
doublereal MaskellSolidSolnPhase::entropy_mole() const { _updateThermo(); const doublereal s0 = GasConstant * mean_X(m_s0_R); const doublereal r = moleFraction(product_species_index); const doublereal fmval = fm(r); const doublereal rfm = r * fmval; return s0 + GasConstant * (xlogx(1-rfm) - xlogx(rfm) - xlogx(1-r-rfm) - xlogx((1-fmval)*r) - xlogx(1-r) - xlogx(r)); }
doublereal Phase::moleFraction(const std::string& nameSpec) const { size_t iloc = speciesIndex(nameSpec); if (iloc != npos) { return moleFraction(iloc); } else { return 0.0; } }
void IdealSolnGasVPSS::getChemPotentials(doublereal* mu) const { getStandardChemPotentials(mu); doublereal xx; doublereal rt = temperature() * GasConstant; for (int k = 0; k < m_kk; k++) { xx = fmaxx(SmallNumber, moleFraction(k)); mu[k] += rt*(log(xx)); } }
/* * Get the array of partial molar entropies of the species * units = J / kmol / K */ void PecosGasPhase::getPartialMolarEntropies(doublereal* sbar) const { const array_fp& _s = entropy_R_ref(); doublereal r = GasConstant; scale(_s.begin(), _s.end(), sbar, r); doublereal logp = log(pressure()/m_spthermo->refPressure()); for (int k = 0; k < m_kk; k++) { doublereal xx = fmaxx(SmallNumber, moleFraction(k)); sbar[k] += r * (- logp - log(xx)); } }
void LatticePhase::getChemPotentials(doublereal* mu) const { doublereal delta_p = m_Pcurrent - m_Pref; const vector_fp& g_RT = gibbs_RT_ref(); for (size_t k = 0; k < m_kk; k++) { double xx = std::max(SmallNumber, moleFraction(k)); mu[k] = RT() * (g_RT[k] + log(xx)) + delta_p * m_speciesMolarVolume[k]; } }
doublereal SurfPhase::entropy_mole() const { _updateThermo(); doublereal s = 0.0; for (size_t k = 0; k < m_kk; k++) { s += moleFraction(k) * (m_s0[k] - GasConstant * log(std::max(concentration(k) * size(k)/m_n0, SmallNumber))); } return s; }
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 IdealGasPhase::getPartialMolarEntropies(doublereal* sbar) const { const vector_fp& _s = entropy_R_ref(); scale(_s.begin(), _s.end(), sbar, GasConstant); doublereal logp = log(pressure() / m_spthermo->refPressure()); for (size_t k = 0; k < m_kk; k++) { doublereal xx = std::max(SmallNumber, moleFraction(k)); sbar[k] += GasConstant * (-logp - log(xx)); } }
void IdealSolidSolnPhase::getChemPotentials_RT(doublereal* mu) const { doublereal delta_pdRT = (m_Pcurrent - m_Pref) / (temperature() * GasConstant); const vector_fp& g_RT = gibbs_RT_ref(); for (size_t k = 0; k < m_kk; k++) { double xx = std::max(SmallNumber, moleFraction(k)); mu[k] = (g_RT[k] + log(xx)) + delta_pdRT * m_speciesMolarVolume[k]; } }
void PecosGasPhase::getChemPotentials(doublereal* mu) const { getStandardChemPotentials(mu); //doublereal logp = log(pressure()/m_spthermo->refPressure()); doublereal xx; doublereal rt = temperature() * GasConstant; //const array_fp& g_RT = gibbs_RT_ref(); for (int k = 0; k < m_kk; k++) { xx = fmaxx(SmallNumber, moleFraction(k)); mu[k] += rt*(log(xx)); } }
compositionMap Phase::getMoleFractionsByName(double threshold) const { compositionMap comp; for (size_t k = 0; k < m_kk; k++) { double x = moleFraction(k); if (x > threshold) { comp[speciesName(k)] = x; } } return comp; }
void ConstDensityThermo::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 MaskellSolidSolnPhase::getChemPotentials(doublereal* mu) const { _updateThermo(); const doublereal r = moleFraction(product_species_index); const doublereal pval = p(r); const doublereal rfm = r * fm(r); const doublereal DgbarDr = pval * h_mixing + RT() * std::log( (std::pow(1 - rfm, pval) * std::pow(rfm, pval) * std::pow(r - rfm, 1 - pval) * r) / (std::pow(1 - r - rfm, 1 + pval) * (1 - r)) ); mu[product_species_index] = RT() * m_g0_RT[product_species_index] + DgbarDr; mu[reactant_species_index] = RT() * m_g0_RT[reactant_species_index] - DgbarDr; }
void MaskellSolidSolnPhase::getActivityCoefficients(doublereal* ac) const { _updateThermo(); static const int cacheId = m_cache.getId(); CachedArray cached = m_cache.getArray(cacheId); if (!cached.validate(temperature(), pressure(), stateMFNumber())) { cached.value.resize(2); const doublereal r = moleFraction(product_species_index); const doublereal pval = p(r); const doublereal rfm = r * fm(r); const doublereal A = (std::pow(1 - rfm, pval) * std::pow(rfm, pval) * std::pow(r - rfm, 1 - pval)) / (std::pow(1 - r - rfm, 1 + pval) * (1 - r)); const doublereal B = pval * h_mixing / RT(); cached.value[product_species_index] = A * std::exp(B); cached.value[reactant_species_index] = 1 / (A * r * (1-r) ) * std::exp(-B); } std::copy(cached.value.begin(), cached.value.end(), ac); }
void IdealMolalSoln::getMolalityActivityCoefficients(doublereal* acMolality) const { if (IMS_typeCutoff_ == 0) { for (size_t k = 0; k < m_kk; k++) { acMolality[k] = 1.0; } double xmolSolvent = moleFraction(0); // Limit the activity coefficient to be finite as the solvent mole // fraction goes to zero. xmolSolvent = std::max(m_xmolSolventMIN, xmolSolvent); acMolality[0] = exp((xmolSolvent - 1.0)/xmolSolvent) / xmolSolvent; } else { s_updateIMS_lnMolalityActCoeff(); std::copy(IMS_lnActCoeffMolal_.begin(), IMS_lnActCoeffMolal_.end(), acMolality); for (size_t k = 0; k < m_kk; k++) { acMolality[k] = exp(acMolality[k]); } } }