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()); }
void ThermoPhase::getLnActivityCoefficients(doublereal* lnac) const { getActivityCoefficients(lnac); for (size_t k = 0; k < m_kk; k++) { lnac[k] = std::log(lnac[k]); } }
void MaskellSolidSolnPhase::getActivityConcentrations(doublereal* c) const { getActivityCoefficients(c); for (size_t sp = 0; sp < m_kk; ++sp) { c[sp] *= moleFraction(sp); } }
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::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("Y"); getMassFractions(&data[1][0]); names.push_back("Chem. Pot (J/kmol)"); getChemPotentials(&data[2][0]); names.push_back("Activity"); getActivities(&data[3][0]); names.push_back("Act. Coeff."); getActivityCoefficients(&data[4][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]); }