void GibbsExcessVPSSTP::getActivities(doublereal* ac) const { getActivityCoefficients(ac); getMoleFractions(DATA_PTR(moleFractions_)); for (int k = 0; k < m_kk; k++) { ac[k] *= moleFractions_[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; } } }
void ThermoPhase::initThermoXML(XML_Node& phaseNode, const std::string& id) { if (phaseNode.hasChild("state")) { setStateFromXML(phaseNode.child("state")); } xMol_Ref.resize(m_kk); getMoleFractions(&xMol_Ref[0]); }
void MolalityVPSSTP::calcMolalities() const { getMoleFractions(m_molalities.data()); double xmolSolvent = std::max(m_molalities[m_indexSolvent], m_xmolSolventMIN); double denomInv = 1.0/ (m_Mnaught * xmolSolvent); for (size_t k = 0; k < m_kk; k++) { m_molalities[k] *= denomInv; } }
std::string MolarityIonicVPSSTP::report(bool show_thermo, doublereal threshold) const { fmt::MemoryWriter b; try { if (name() != "") { b.write("\n {}:\n", name()); } b.write("\n"); b.write(" temperature {:12.6g} K\n", temperature()); b.write(" pressure {:12.6g} Pa\n", pressure()); b.write(" density {:12.6g} kg/m^3\n", density()); b.write(" mean mol. weight {:12.6g} amu\n", meanMolecularWeight()); doublereal phi = electricPotential(); b.write(" potential {:12.6g} V\n", phi); vector_fp x(m_kk); vector_fp molal(m_kk); vector_fp mu(m_kk); vector_fp muss(m_kk); vector_fp acMolal(m_kk); vector_fp actMolal(m_kk); getMoleFractions(&x[0]); getChemPotentials(&mu[0]); getStandardChemPotentials(&muss[0]); getActivities(&actMolal[0]); if (show_thermo) { b.write("\n"); b.write(" 1 kg 1 kmol\n"); b.write(" ----------- ------------\n"); b.write(" enthalpy {:12.6g} {:12.4g} J\n", enthalpy_mass(), enthalpy_mole()); b.write(" internal energy {:12.6g} {:12.4g} J\n", intEnergy_mass(), intEnergy_mole()); b.write(" entropy {:12.6g} {:12.4g} J/K\n", entropy_mass(), entropy_mole()); b.write(" Gibbs function {:12.6g} {:12.4g} J\n", gibbs_mass(), gibbs_mole()); b.write(" heat capacity c_p {:12.6g} {:12.4g} J/K\n", cp_mass(), cp_mole()); try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); } catch (NotImplementedError& e) { b.write(" heat capacity c_v <not implemented>\n"); } } } catch (CanteraError& e) { return b.str() + e.what(); } return b.str(); }
void ThermoPhase::getdlnActCoeffdlnN_numderiv(const size_t ld, doublereal* const dlnActCoeffdlnN) { double deltaMoles_j = 0.0; double pres = pressure(); // Evaluate the current base activity coefficients if necessary vector_fp ActCoeff_Base(m_kk); getActivityCoefficients(ActCoeff_Base.data()); vector_fp Xmol_Base(m_kk); getMoleFractions(Xmol_Base.data()); // Make copies of ActCoeff and Xmol_ for use in taking differences vector_fp ActCoeff(m_kk); vector_fp Xmol(m_kk); double v_totalMoles = 1.0; double TMoles_base = v_totalMoles; // Loop over the columns species to be deltad for (size_t j = 0; j < m_kk; j++) { // Calculate a value for the delta moles of species j // -> Note Xmol_[] and Tmoles are always positive or zero quantities. // -> experience has shown that you always need to make the deltas // greater than needed to change the other mole fractions in order // to capture some effects. double moles_j_base = v_totalMoles * Xmol_Base[j]; deltaMoles_j = 1.0E-7 * moles_j_base + v_totalMoles * 1.0E-13 + 1.0E-150; // Now, update the total moles in the phase and all of the mole // fractions based on this. v_totalMoles = TMoles_base + deltaMoles_j; for (size_t k = 0; k < m_kk; k++) { Xmol[k] = Xmol_Base[k] * TMoles_base / v_totalMoles; } Xmol[j] = (moles_j_base + deltaMoles_j) / v_totalMoles; // Go get new values for the activity coefficients. // -> Note this calls setState_PX(); setState_PX(pres, Xmol.data()); getActivityCoefficients(ActCoeff.data()); // Calculate the column of the matrix double* const lnActCoeffCol = dlnActCoeffdlnN + ld * j; for (size_t k = 0; k < m_kk; k++) { lnActCoeffCol[k] = (2*moles_j_base + deltaMoles_j) *(ActCoeff[k] - ActCoeff_Base[k]) / ((ActCoeff[k] + ActCoeff_Base[k]) * deltaMoles_j); } // Revert to the base case Xmol_, v_totalMoles v_totalMoles = TMoles_base; Xmol = Xmol_Base; } setState_PX(pres, Xmol_Base.data()); }
/* * calcMolalities(): * We calculate the vector of molalities of the species * in the phase and store the result internally: * \f[ * m_i = (n_i) / (1000 * M_o * n_{o,p}) * \f] * where * - \f$ M_o \f$ is the molecular weight of the solvent * - \f$ n_o \f$ is the mole fraction of the solvent * - \f$ n_i \f$ is the mole fraction of the solute. * - \f$ n_{o,p} = max (n_{o, min}, n_o) \f$ * - \f$ n_{o,min} \f$ = minimum mole fraction of solvent allowed * in the denominator. */ void MolalityVPSSTP::calcMolalities() const { getMoleFractions(DATA_PTR(m_molalities)); double xmolSolvent = m_molalities[m_indexSolvent]; if (xmolSolvent < m_xmolSolventMIN) { xmolSolvent = m_xmolSolventMIN; } double denomInv = 1.0/ (m_Mnaught * xmolSolvent); for (size_t k = 0; k < m_kk; k++) { m_molalities[k] *= denomInv; } }
dvec CanteraGas::calculateReactantMixture(const std::string& fuel, const std::string& oxidizer, double equivalenceRatio) { size_t mC = thermo.elementIndex("C"); size_t mO = thermo.elementIndex("O"); size_t mH = thermo.elementIndex("H"); double Cf(0), Hf(0), Of(0); // moles of C/H/O in fuel double Co(0), Ho(0), Oo(0); // moles of C/H/O in oxidizer dvec Xf(nSpec), Xo(nSpec), Xr(nSpec); thermo.setState_TPX(300.0, pressure, fuel); getMoleFractions(Xf); thermo.setState_TPX(300.0, pressure, oxidizer); getMoleFractions(Xo); dvec a(thermo.nElements()); for (size_t k=0; k<nSpec; k++) { thermo.getAtoms(k, &a[0]); if (mC != npos) { Cf += a[mC]*Xf[k]; Co += a[mC]*Xo[k]; } if (mH != npos) { Hf += a[mH]*Xf[k]; Ho += a[mH]*Xo[k]; } if (mO != npos) { Of += a[mO]*Xf[k]; Oo += a[mO]*Xo[k]; } } double stoichAirFuelRatio = -(Of-2*Cf-Hf/2)/(Oo-2*Co-Ho/2); Xr = Xf * equivalenceRatio + stoichAirFuelRatio * Xo; Xr /= Xr.sum(); return Xr; }
void MixtureFugacityTP::setState_TR(doublereal T, doublereal rho) { getMoleFractions(DATA_PTR(moleFractions_)); Phase::setTemperature(T); _updateReferenceStateThermo(); Phase::setDensity(rho); doublereal mv = molarVolume(); // depends on mole fraction and temperature updateMixingExpressions(); m_Pcurrent = pressureCalc(T, mv); iState_ = phaseState(true); }
void LatticeSolidPhase::_updateThermo() const { doublereal tnow = temperature(); if (m_tlast != tnow) { getMoleFractions(DATA_PTR(m_x)); size_t strt = 0; for (size_t n = 0; n < m_nlattice; n++) { m_lattice[n]->setTemperature(tnow); m_lattice[n]->setMoleFractions(DATA_PTR(m_x) + strt); m_lattice[n]->setPressure(m_press); strt += m_lattice[n]->nSpecies(); } m_tlast = tnow; } }
void ThermoPhase::setReferenceComposition(const doublereal* const x) { warn_deprecated("ThermoPhase::setReferenceComposition", "To be removed after Cantera 2.3."); xMol_Ref.resize(m_kk); if (x) { copy(x, x + m_kk, xMol_Ref.begin()); } else { getMoleFractions(&xMol_Ref[0]); } double sum = accumulate(xMol_Ref.begin(), xMol_Ref.end(), -1.0); if (fabs(sum) > 1.0E-11) { throw CanteraError("ThermoPhase::setReferenceComposition", "input mole fractions don't sum to 1.0"); } }
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) { int n; getMoleFractions(DATA_PTR(m_x)); int strt = 0; for (n = 0; n < m_nlattice; n++) { m_lattice[n]->setTemperature(tnow); m_lattice[n]->setMoleFractions(DATA_PTR(m_x) + strt); m_lattice[n]->setPressure(m_press); strt += m_lattice[n]->nSpecies(); } m_tlast = tnow; } }
void MolalityVPSSTP::getCsvReportData(std::vector<std::string>& names, std::vector<vector_fp>& data) const { names.clear(); data.assign(10, vector_fp(nSpecies())); names.push_back("X"); getMoleFractions(&data[0][0]); names.push_back("Molal"); getMolalities(&data[1][0]); names.push_back("Chem. Pot. (J/kmol)"); getChemPotentials(&data[2][0]); names.push_back("Chem. Pot. SS (J/kmol)"); getStandardChemPotentials(&data[3][0]); names.push_back("Molal Act. Coeff."); getMolalityActivityCoefficients(&data[4][0]); names.push_back("Molal Activity"); getActivities(&data[5][0]); names.push_back("Part. Mol Enthalpy (J/kmol)"); getPartialMolarEnthalpies(&data[5][0]); names.push_back("Part. Mol. Entropy (J/K/kmol)"); getPartialMolarEntropies(&data[6][0]); names.push_back("Part. Mol. Energy (J/kmol)"); getPartialMolarIntEnergies(&data[7][0]); names.push_back("Part. Mol. Cp (J/K/kmol"); getPartialMolarCp(&data[8][0]); names.push_back("Part. Mol. Cv (J/K/kmol)"); getPartialMolarVolumes(&data[9][0]); }
void MixtureFugacityTP::setMassFractions(const doublereal* const y) { Phase::setMassFractions(y); getMoleFractions(DATA_PTR(moleFractions_)); }
void MixtureFugacityTP::setMoleFractions_NoNorm(const doublereal* const x) { Phase::setMoleFractions_NoNorm(x); getMoleFractions(DATA_PTR(moleFractions_)); }
void MixtureFugacityTP::setState_TP(doublereal t, doublereal pres) { /* * A pretty tricky algorithm is needed here, due to problems involving * standard states of real fluids. For those cases you need * to combine the T and P specification for the standard state, or else * you may venture into the forbidden zone, especially when nearing the * triple point. * Therefore, we need to do the standard state thermo calc with the * (t, pres) combo. */ getMoleFractions(DATA_PTR(moleFractions_)); Phase::setTemperature(t); _updateReferenceStateThermo(); // Depends on the mole fractions and the temperature updateMixingExpressions(); m_Pcurrent = pres; if (forcedState_ == FLUID_UNDEFINED) { double rhoNow = Phase::density(); double rho = densityCalc(t, pres, iState_, rhoNow); if (rho > 0.0) { Phase::setDensity(rho); m_Pcurrent = pres; iState_ = phaseState(true); } else { if (rho < -1.5) { rho = densityCalc(t, pres, FLUID_UNDEFINED , rhoNow); if (rho > 0.0) { Phase::setDensity(rho); m_Pcurrent = pres; iState_ = phaseState(true); } else { throw CanteraError("MixtureFugacityTP::setState_TP()", "neg rho"); } } else { throw CanteraError("MixtureFugacityTP::setState_TP()", "neg rho"); } } } else if (forcedState_ == FLUID_GAS) { // Normal density calculation if (iState_ < FLUID_LIQUID_0) { double rhoNow = Phase::density(); double rho = densityCalc(t, pres, iState_, rhoNow); if (rho > 0.0) { Phase::setDensity(rho); m_Pcurrent = pres; iState_ = phaseState(true); if (iState_ >= FLUID_LIQUID_0) { throw CanteraError("MixtureFugacityTP::setState_TP()", "wrong state"); } } else { throw CanteraError("MixtureFugacityTP::setState_TP()", "neg rho"); } } } else if (forcedState_ > FLUID_LIQUID_0) { if (iState_ >= FLUID_LIQUID_0) { double rhoNow = Phase::density(); double rho = densityCalc(t, pres, iState_, rhoNow); if (rho > 0.0) { Phase::setDensity(rho); m_Pcurrent = pres; iState_ = phaseState(true); if (iState_ == FLUID_GAS) { throw CanteraError("MixtureFugacityTP::setState_TP()", "wrong state"); } } else { throw CanteraError("MixtureFugacityTP::setState_TP()", "neg rho"); } } } }
/* * Format a summary of the mixture state for output. */ void MolalityVPSSTP::reportCSV(std::ofstream& csvFile) const { csvFile.precision(3); int tabS = 15; int tabM = 30; int tabL = 40; try { if (name() != "") { csvFile << "\n"+name()+"\n\n"; } csvFile << setw(tabL) << "temperature (K) =" << setw(tabS) << temperature() << endl; csvFile << setw(tabL) << "pressure (Pa) =" << setw(tabS) << pressure() << endl; csvFile << setw(tabL) << "density (kg/m^3) =" << setw(tabS) << density() << endl; csvFile << setw(tabL) << "mean mol. weight (amu) =" << setw(tabS) << meanMolecularWeight() << endl; csvFile << setw(tabL) << "potential (V) =" << setw(tabS) << electricPotential() << endl; csvFile << endl; csvFile << setw(tabL) << "enthalpy (J/kg) = " << setw(tabS) << enthalpy_mass() << setw(tabL) << "enthalpy (J/kmol) = " << setw(tabS) << enthalpy_mole() << endl; csvFile << setw(tabL) << "internal E (J/kg) = " << setw(tabS) << intEnergy_mass() << setw(tabL) << "internal E (J/kmol) = " << setw(tabS) << intEnergy_mole() << endl; csvFile << setw(tabL) << "entropy (J/kg) = " << setw(tabS) << entropy_mass() << setw(tabL) << "entropy (J/kmol) = " << setw(tabS) << entropy_mole() << endl; csvFile << setw(tabL) << "Gibbs (J/kg) = " << setw(tabS) << gibbs_mass() << setw(tabL) << "Gibbs (J/kmol) = " << setw(tabS) << gibbs_mole() << endl; csvFile << setw(tabL) << "heat capacity c_p (J/K/kg) = " << setw(tabS) << cp_mass() << setw(tabL) << "heat capacity c_p (J/K/kmol) = " << setw(tabS) << cp_mole() << endl; csvFile << setw(tabL) << "heat capacity c_v (J/K/kg) = " << setw(tabS) << cv_mass() << setw(tabL) << "heat capacity c_v (J/K/kmol) = " << setw(tabS) << cv_mole() << endl; csvFile.precision(8); vector<std::string> pNames; vector<vector_fp> data; vector_fp temp(nSpecies()); getMoleFractions(&temp[0]); pNames.push_back("X"); data.push_back(temp); try { getMolalities(&temp[0]); pNames.push_back("Molal"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getChemPotentials(&temp[0]); pNames.push_back("Chem. Pot. (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getStandardChemPotentials(&temp[0]); pNames.push_back("Chem. Pot. SS (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getMolalityActivityCoefficients(&temp[0]); pNames.push_back("Molal Act. Coeff."); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getActivities(&temp[0]); pNames.push_back("Molal Activity"); data.push_back(temp); size_t iHp = speciesIndex("H+"); if (iHp != npos) { double pH = -log(temp[iHp]) / log(10.0); csvFile << setw(tabL) << "pH = " << setw(tabS) << pH << endl; } } catch (CanteraError& err) { err.save(); } try { getPartialMolarEnthalpies(&temp[0]); pNames.push_back("Part. Mol Enthalpy (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarEntropies(&temp[0]); pNames.push_back("Part. Mol. Entropy (J/K/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarIntEnergies(&temp[0]); pNames.push_back("Part. Mol. Energy (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarCp(&temp[0]); pNames.push_back("Part. Mol. Cp (J/K/kmol"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarVolumes(&temp[0]); pNames.push_back("Part. Mol. Cv (J/K/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } csvFile << endl << setw(tabS) << "Species,"; for (size_t i = 0; i < pNames.size(); i++) { csvFile << setw(tabM) << pNames[i] << ","; } csvFile << endl; /* csvFile.fill('-'); csvFile << setw(tabS+(tabM+1)*pNames.size()) << "-\n"; csvFile.fill(' '); */ for (size_t k = 0; k < nSpecies(); k++) { csvFile << setw(tabS) << speciesName(k) + ","; if (data[0][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; } } } catch (CanteraError& err) { err.save(); } }
/* * setMolalitiesByName() * * This routine sets the molalities by name * HKM -> Might need to be more complicated here, setting * neutrals so that the existing mole fractions are * preserved. */ void MolalityVPSSTP::setMolalitiesByName(compositionMap& mMap) { size_t kk = nSpecies(); doublereal x; /* * Get a vector of mole fractions */ vector_fp mf(kk, 0.0); getMoleFractions(DATA_PTR(mf)); double xmolS = mf[m_indexSolvent]; double xmolSmin = std::max(xmolS, m_xmolSolventMIN); compositionMap::iterator p; for (size_t k = 0; k < kk; k++) { p = mMap.find(speciesName(k)); if (p != mMap.end()) { x = mMap[speciesName(k)]; if (x > 0.0) { mf[k] = x * m_Mnaught * xmolSmin; } } } /* * check charge neutrality */ size_t largePos = npos; double cPos = 0.0; size_t largeNeg = npos; double cNeg = 0.0; double sum = 0.0; for (size_t k = 0; k < kk; k++) { double ch = charge(k); if (mf[k] > 0.0) { if (ch > 0.0) { if (ch * mf[k] > cPos) { largePos = k; cPos = ch * mf[k]; } } if (ch < 0.0) { if (fabs(ch) * mf[k] > cNeg) { largeNeg = k; cNeg = fabs(ch) * mf[k]; } } } sum += mf[k] * ch; } if (sum != 0.0) { if (sum > 0.0) { if (cPos > sum) { mf[largePos] -= sum / charge(largePos); } else { throw CanteraError("MolalityVPSSTP:setMolalitiesbyName", "unbalanced charges"); } } else { if (cNeg > (-sum)) { mf[largeNeg] -= (-sum) / fabs(charge(largeNeg)); } else { throw CanteraError("MolalityVPSSTP:setMolalitiesbyName", "unbalanced charges"); } } } sum = 0.0; for (size_t k = 0; k < kk; k++) { sum += mf[k]; } sum = 1.0/sum; for (size_t k = 0; k < kk; k++) { mf[k] *= sum; } setMoleFractions(DATA_PTR(mf)); /* * After we formally set the mole fractions, we * calculate the molalities again and store it in * this object. */ calcMolalities(); }
void MixtureFugacityTP::setConcentrations(const doublereal* const c) { Phase::setConcentrations(c); getMoleFractions(DATA_PTR(moleFractions_)); }
void GibbsExcessVPSSTP::setConcentrations(const doublereal* const c) { State::setConcentrations(c); getMoleFractions(DATA_PTR(moleFractions_)); calcDensity(); }
void GibbsExcessVPSSTP::setMoleFractions_NoNorm(const doublereal* const x) { State::setMoleFractions_NoNorm(x); getMoleFractions(DATA_PTR(moleFractions_)); calcDensity(); }
void GibbsExcessVPSSTP::setMassFractions(const doublereal* const y) { State::setMassFractions(y); getMoleFractions(DATA_PTR(moleFractions_)); calcDensity(); }
std::string MolarityIonicVPSSTP::report(bool show_thermo) const { char p[800]; string s = ""; try { if (name() != "") { sprintf(p, " \n %s:\n", name().c_str()); s += p; } sprintf(p, " \n temperature %12.6g K\n", temperature()); s += p; sprintf(p, " pressure %12.6g Pa\n", pressure()); s += p; sprintf(p, " density %12.6g kg/m^3\n", density()); s += p; sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight()); s += p; doublereal phi = electricPotential(); sprintf(p, " potential %12.6g V\n", phi); s += p; size_t kk = nSpecies(); vector_fp x(kk); vector_fp molal(kk); vector_fp mu(kk); vector_fp muss(kk); vector_fp acMolal(kk); vector_fp actMolal(kk); getMoleFractions(&x[0]); getChemPotentials(&mu[0]); getStandardChemPotentials(&muss[0]); getActivities(&actMolal[0]); if (show_thermo) { sprintf(p, " \n"); s += p; sprintf(p, " 1 kg 1 kmol\n"); s += p; sprintf(p, " ----------- ------------\n"); s += p; sprintf(p, " enthalpy %12.6g %12.4g J\n", enthalpy_mass(), enthalpy_mole()); s += p; sprintf(p, " internal energy %12.6g %12.4g J\n", intEnergy_mass(), intEnergy_mole()); s += p; sprintf(p, " entropy %12.6g %12.4g J/K\n", entropy_mass(), entropy_mole()); s += p; sprintf(p, " Gibbs function %12.6g %12.4g J\n", gibbs_mass(), gibbs_mole()); s += p; sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", cp_mass(), cp_mole()); s += p; try { sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", cv_mass(), cv_mole()); s += p; } catch (CanteraError& e) { e.save(); sprintf(p, " heat capacity c_v <not implemented> \n"); s += p; } } } catch (CanteraError& e) { e.save(); } return s; }
std::string ThermoPhase::report(bool show_thermo, doublereal threshold) const { fmt::MemoryWriter b; try { if (name() != "") { b.write("\n {}:\n", name()); } b.write("\n"); b.write(" temperature {:12.6g} K\n", temperature()); b.write(" pressure {:12.6g} Pa\n", pressure()); b.write(" density {:12.6g} kg/m^3\n", density()); b.write(" mean mol. weight {:12.6g} amu\n", meanMolecularWeight()); doublereal phi = electricPotential(); if (phi != 0.0) { b.write(" potential {:12.6g} V\n", phi); } if (show_thermo) { b.write("\n"); b.write(" 1 kg 1 kmol\n"); b.write(" ----------- ------------\n"); b.write(" enthalpy {:12.5g} {:12.4g} J\n", enthalpy_mass(), enthalpy_mole()); b.write(" internal energy {:12.5g} {:12.4g} J\n", intEnergy_mass(), intEnergy_mole()); b.write(" entropy {:12.5g} {:12.4g} J/K\n", entropy_mass(), entropy_mole()); b.write(" Gibbs function {:12.5g} {:12.4g} J\n", gibbs_mass(), gibbs_mole()); b.write(" heat capacity c_p {:12.5g} {:12.4g} J/K\n", cp_mass(), cp_mole()); try { b.write(" heat capacity c_v {:12.5g} {:12.4g} J/K\n", cv_mass(), cv_mole()); } catch (NotImplementedError&) { b.write(" heat capacity c_v <not implemented> \n"); } } vector_fp x(m_kk); vector_fp y(m_kk); vector_fp mu(m_kk); getMoleFractions(&x[0]); getMassFractions(&y[0]); getChemPotentials(&mu[0]); int nMinor = 0; doublereal xMinor = 0.0; doublereal yMinor = 0.0; b.write("\n"); if (show_thermo) { b.write(" X " " Y Chem. Pot. / RT\n"); b.write(" ------------- " "------------ ------------\n"); for (size_t k = 0; k < m_kk; k++) { if (abs(x[k]) >= threshold) { if (abs(x[k]) > SmallNumber) { b.write("{:>18s} {:12.6g} {:12.6g} {:12.6g}\n", speciesName(k), x[k], y[k], mu[k]/RT()); } else { b.write("{:>18s} {:12.6g} {:12.6g}\n", speciesName(k), x[k], y[k]); } } else { nMinor++; xMinor += x[k]; yMinor += y[k]; } } } else { b.write(" X Y\n"); b.write(" ------------- ------------\n"); for (size_t k = 0; k < m_kk; k++) { if (abs(x[k]) >= threshold) { b.write("{:>18s} {:12.6g} {:12.6g}\n", speciesName(k), x[k], y[k]); } else { nMinor++; xMinor += x[k]; yMinor += y[k]; } } } if (nMinor) { b.write(" [{:+5d} minor] {:12.6g} {:12.6g}\n", nMinor, xMinor, yMinor); } } catch (CanteraError& err) { return b.str() + err.what(); } return b.str(); }
std::string MolalityVPSSTP::report(bool show_thermo, doublereal threshold) const { fmt::MemoryWriter b; try { if (name() != "") { b.write("\n {}:\n", name()); } b.write("\n"); b.write(" temperature {:12.6g} K\n", temperature()); b.write(" pressure {:12.6g} Pa\n", pressure()); b.write(" density {:12.6g} kg/m^3\n", density()); b.write(" mean mol. weight {:12.6g} amu\n", meanMolecularWeight()); doublereal phi = electricPotential(); b.write(" potential {:12.6g} V\n", phi); vector_fp x(m_kk); vector_fp molal(m_kk); vector_fp mu(m_kk); vector_fp muss(m_kk); vector_fp acMolal(m_kk); vector_fp actMolal(m_kk); getMoleFractions(&x[0]); getMolalities(&molal[0]); getChemPotentials(&mu[0]); getStandardChemPotentials(&muss[0]); getMolalityActivityCoefficients(&acMolal[0]); getActivities(&actMolal[0]); size_t iHp = speciesIndex("H+"); if (iHp != npos) { double pH = -log(actMolal[iHp]) / log(10.0); b.write(" pH {:12.4g}\n", pH); } if (show_thermo) { b.write("\n"); b.write(" 1 kg 1 kmol\n"); b.write(" ----------- ------------\n"); b.write(" enthalpy {:12.6g} {:12.4g} J\n", enthalpy_mass(), enthalpy_mole()); b.write(" internal energy {:12.6g} {:12.4g} J\n", intEnergy_mass(), intEnergy_mole()); b.write(" entropy {:12.6g} {:12.4g} J/K\n", entropy_mass(), entropy_mole()); b.write(" Gibbs function {:12.6g} {:12.4g} J\n", gibbs_mass(), gibbs_mole()); b.write(" heat capacity c_p {:12.6g} {:12.4g} J/K\n", cp_mass(), cp_mole()); try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); } catch (NotImplementedError& e) { b.write(" heat capacity c_v <not implemented>\n"); } } b.write("\n"); int nMinor = 0; doublereal xMinor = 0.0; if (show_thermo) { b.write(" X " " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n"); b.write(" " " (J/kmol) (J/kmol)\n"); b.write(" ------------- " " ------------ ------------ ------------ ------------\n"); for (size_t k = 0; k < m_kk; k++) { if (x[k] > threshold) { if (x[k] > SmallNumber) { b.write("{:>18s} {:12.6g} {:12.6g} {:12.6g} {:12.6g} {:12.6g}\n", speciesName(k), x[k], molal[k], mu[k], muss[k], acMolal[k]); } else { b.write("{:>18s} {:12.6g} {:12.6g} N/A {:12.6g} {:12.6g}\n", speciesName(k), x[k], molal[k], muss[k], acMolal[k]); } } else { nMinor++; xMinor += x[k]; } } } else { b.write(" X" "Molalities\n"); b.write(" -------------" " ------------\n"); for (size_t k = 0; k < m_kk; k++) { if (x[k] > threshold) { b.write("{:>18s} {:12.6g} {:12.6g}\n", speciesName(k), x[k], molal[k]); } else { nMinor++; xMinor += x[k]; } } } if (nMinor) { b.write(" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor); } } catch (CanteraError& err) { return b.str() + err.what(); } return b.str(); }
/* * @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 GibbsExcessVPSSTP::initThermo() { initLengths(); VPStandardStateTP::initThermo(); getMoleFractions(DATA_PTR(moleFractions_)); }
/** * Format a summary of the mixture state for output. */ std::string MolalityVPSSTP::report(bool show_thermo) const { char p[800]; string s = ""; try { if (name() != "") { sprintf(p, " \n %s:\n", name().c_str()); s += p; } sprintf(p, " \n temperature %12.6g K\n", temperature()); s += p; sprintf(p, " pressure %12.6g Pa\n", pressure()); s += p; sprintf(p, " density %12.6g kg/m^3\n", density()); s += p; sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight()); s += p; doublereal phi = electricPotential(); sprintf(p, " potential %12.6g V\n", phi); s += p; size_t kk = nSpecies(); vector_fp x(kk); vector_fp molal(kk); vector_fp mu(kk); vector_fp muss(kk); vector_fp acMolal(kk); vector_fp actMolal(kk); getMoleFractions(&x[0]); getMolalities(&molal[0]); getChemPotentials(&mu[0]); getStandardChemPotentials(&muss[0]); getMolalityActivityCoefficients(&acMolal[0]); getActivities(&actMolal[0]); size_t iHp = speciesIndex("H+"); if (iHp != npos) { double pH = -log(actMolal[iHp]) / log(10.0); sprintf(p, " pH %12.4g \n", pH); s += p; } if (show_thermo) { sprintf(p, " \n"); s += p; sprintf(p, " 1 kg 1 kmol\n"); s += p; sprintf(p, " ----------- ------------\n"); s += p; sprintf(p, " enthalpy %12.6g %12.4g J\n", enthalpy_mass(), enthalpy_mole()); s += p; sprintf(p, " internal energy %12.6g %12.4g J\n", intEnergy_mass(), intEnergy_mole()); s += p; sprintf(p, " entropy %12.6g %12.4g J/K\n", entropy_mass(), entropy_mole()); s += p; sprintf(p, " Gibbs function %12.6g %12.4g J\n", gibbs_mass(), gibbs_mole()); s += p; sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", cp_mass(), cp_mole()); s += p; try { sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", cv_mass(), cv_mole()); s += p; } catch (CanteraError& err) { err.save(); sprintf(p, " heat capacity c_v <not implemented> \n"); s += p; } } sprintf(p, " \n"); s += p; if (show_thermo) { sprintf(p, " X " " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n"); s += p; sprintf(p, " " " (J/kmol) (J/kmol) \n"); s += p; sprintf(p, " ------------- " " ------------ ------------ ------------ ------------\n"); s += p; for (size_t k = 0; k < kk; k++) { if (x[k] > SmallNumber) { sprintf(p, "%18s %12.6g %12.6g %12.6g %12.6g %12.6g\n", speciesName(k).c_str(), x[k], molal[k], mu[k], muss[k], acMolal[k]); } else { sprintf(p, "%18s %12.6g %12.6g N/A %12.6g %12.6g \n", speciesName(k).c_str(), x[k], molal[k], muss[k], acMolal[k]); } s += p; } } else { sprintf(p, " X" "Molalities\n"); s += p; sprintf(p, " -------------" " ------------\n"); s += p; for (size_t k = 0; k < kk; k++) { sprintf(p, "%18s %12.6g %12.6g\n", speciesName(k).c_str(), x[k], molal[k]); s += p; } } } catch (CanteraError& err) { err.save(); } return s; }
void LatticePhase::getActivityConcentrations(doublereal* c) const { getMoleFractions(c); }
void GibbsExcessVPSSTP::setState_TPX(doublereal t, doublereal p, const doublereal* x) { State::setMoleFractions(x); getMoleFractions(DATA_PTR(moleFractions_)); setState_TP(t, p); }
void MixtureFugacityTP::setMoleFractions_NoState(const doublereal* const x) { Phase::setMoleFractions(x); getMoleFractions(DATA_PTR(moleFractions_)); updateMixingExpressions(); }