Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jan 21, 2025
1 parent 53a2d7e commit 10d7754
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 54 deletions.
5 changes: 4 additions & 1 deletion include/cantera/base/Solution.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ class Solution : public std::enable_shared_from_this<Solution>

//! Get the number of adjacent phases
size_t nAdjacent() const {
return m_adjacent.size();
return m_adjacent.size();
}

//! Get the name of an adjacent phase by index
string adjacentName(size_t i) const {
if (i < 0 || i >= m_adjacent.size()) {
throw CanteraError("Solution::adjacentName", "Invalid index {}.", i);
}
return m_adjacent.at(i)->name();
}

Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/Phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ class Phase
bool m_caseSensitiveSpecies = false;

//! Vector of size m_kk, used as a temporary holding area.
mutable vector<double> m_tmpV;
mutable vector<double> m_workS;

private:
//! Find lowercase species name in m_speciesIndices when case sensitive
Expand Down
36 changes: 16 additions & 20 deletions include/cantera/thermo/ThermoPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,13 @@ class ThermoPhase : public Phase
/**
* Returns the amount of enthalpy per mole,
* @f[
* \bar{h}(T, P, X_k) = \sum_k X_k \bar{h}_k(T)
* \hat{h} = \sum_k X_k \hat{h}_k
* @f]
* The formula is written in terms of the partial molar enthalpies.
* @f$ \bar{h}_k(T, p, m_k) @f$.
* @relates getPartialMolarEnthalpies()
* @see getPartialMolarEnthalpies()
*/
virtual double enthalpy_mole() const {
getPartialMolarEnthalpies(m_tmpV.data());
return mean_X(m_tmpV);
getPartialMolarEnthalpies(m_workS.data());
return mean_X(m_workS);
}

//! Molar internal energy. Units: J/kmol.
Expand All @@ -547,40 +545,38 @@ class ThermoPhase : public Phase
/**
* Returns the amount of entropy per mole,
* @f[
* \bar{s}(T, P, X_k) = \sum_k X_k \bar{s}_k(T)
* \hat{s} = \sum_k X_k \hat{s}_k
* @f]
* The formula is written in terms of the partial molar entropies.
* @f$ \bar{s}_k(T, p, m_k) @f$.
* @relates getPartialMolarEnthalpies()
* @see getPartialMolarEnthalpies()
*/
virtual double entropy_mole() const {
getPartialMolarEntropies(m_tmpV.data());
return mean_X(m_tmpV);
getPartialMolarEntropies(m_workS.data());
return mean_X(m_workS);
}

//! Molar Gibbs function. Units: J/kmol.
/*!
* Returns the Gibbs free energy per mole,
* @f[
* \bar{g}(T, P, X_k) = \sum_k X_k \mu_k(T)
* \hat{g} = \sum_k X_k \mu_k
* @f]
* @relates getChemPotentials()
* @see getChemPotentials()
*/
virtual double gibbs_mole() const {
getChemPotentials(m_tmpV.data());
return mean_X(m_tmpV);
getChemPotentials(m_workS.data());
return mean_X(m_workS);
}

//! Molar heat capacity at constant pressure. Units: J/kmol/K.
/*!
* @f[
* \bar{c}_p(T, P, X_k) = \sum_k X_k \bar{c}_{p,k}(T)
* \hat{c}_p = \sum_k X_k \hat{c}_{p,k}
* @f]
* @relates getPartialMolarCp()
* @see getPartialMolarCp()
*/
virtual double cp_mole() const {
getPartialMolarCp(m_tmpV.data());
return mean_X(m_tmpV);
getPartialMolarCp(m_workS.data());
return mean_X(m_workS);
}

//! Molar heat capacity at constant volume. Units: J/kmol/K.
Expand Down
22 changes: 11 additions & 11 deletions src/thermo/HMWSoln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ HMWSoln::HMWSoln(const string& inputFile, const string& id_) :

double HMWSoln::relative_enthalpy() const
{
getPartialMolarEnthalpies(m_tmpV.data());
double hbar = mean_X(m_tmpV);
getPartialMolarEnthalpies(m_workS.data());
double hbar = mean_X(m_workS);
getEnthalpy_RT(m_gamma_tmp.data());
for (size_t k = 0; k < m_kk; k++) {
m_gamma_tmp[k] *= RT();
Expand All @@ -66,20 +66,20 @@ double HMWSoln::relative_enthalpy() const
double HMWSoln::relative_molal_enthalpy() const
{
double L = relative_enthalpy();
getMoleFractions(m_tmpV.data());
getMoleFractions(m_workS.data());
double xanion = 0.0;
size_t kcation = npos;
double xcation = 0.0;
size_t kanion = npos;
for (size_t k = 0; k < m_kk; k++) {
if (charge(k) > 0.0) {
if (m_tmpV[k] > xanion) {
xanion = m_tmpV[k];
if (m_workS[k] > xanion) {
xanion = m_workS[k];
kanion = k;
}
} else if (charge(k) < 0.0) {
if (m_tmpV[k] > xcation) {
xcation = m_tmpV[k];
if (m_workS[k] > xcation) {
xcation = m_workS[k];
kcation = k;
}
}
Expand Down Expand Up @@ -144,8 +144,8 @@ void HMWSoln::getActivityConcentrations(double* c) const

double HMWSoln::standardConcentration(size_t k) const
{
getStandardVolumes(m_tmpV.data());
double mvSolvent = m_tmpV[0];
getStandardVolumes(m_workS.data());
double mvSolvent = m_workS[0];
if (k > 0) {
return m_Mnaught / mvSolvent;
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ double HMWSoln::d2A_DebyedT2_TP(double tempArg, double presArg) const

void HMWSoln::initLengths()
{
m_tmpV.resize(m_kk, 0.0);
m_workS.resize(m_kk, 0.0);
m_molalitiesCropped.resize(m_kk, 0.0);

size_t maxCounterIJlen = 1 + (m_kk-1) * (m_kk-2) / 2;
Expand Down Expand Up @@ -3936,7 +3936,7 @@ void HMWSoln::s_updateIMS_lnMolalityActCoeff() const
void HMWSoln::printCoeffs() const
{
calcMolalities();
vector<double>& moleF = m_tmpV;
vector<double>& moleF = m_workS;

// Update the coefficients wrt Temperature. Calculate the derivatives as well
s_updatePitzer_CoeffWRTemp(2);
Expand Down
4 changes: 2 additions & 2 deletions src/thermo/IdealMolalSoln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ IdealMolalSoln::IdealMolalSoln(const string& inputFile, const string& id_) :

double IdealMolalSoln::intEnergy_mole() const
{
getPartialMolarIntEnergies(m_tmpV.data());
return mean_X(m_tmpV);
getPartialMolarIntEnergies(m_workS.data());
return mean_X(m_workS);
}

// ------- Mechanical Equation of State Properties ------------------------
Expand Down
12 changes: 6 additions & 6 deletions src/thermo/PengRobinson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ double PengRobinson::pressure() const

double PengRobinson::standardConcentration(size_t k) const
{
getStandardVolumes(m_tmpV.data());
return 1.0 / m_tmpV[k];
getStandardVolumes(m_workS.data());
return 1.0 / m_workS[k];
}

void PengRobinson::getActivityCoefficients(double* ac) const
Expand Down Expand Up @@ -256,9 +256,9 @@ void PengRobinson::getPartialMolarEntropies(double* sbar) const
// Using the identity : (hk - T*sk) = gk
double T = temperature();
getPartialMolarEnthalpies(sbar);
getChemPotentials(m_tmpV.data());
getChemPotentials(m_workS.data());
for (size_t k = 0; k < m_kk; k++) {
sbar[k] = (sbar[k] - m_tmpV[k])/T;
sbar[k] = (sbar[k] - m_workS[k])/T;
}
}

Expand All @@ -267,9 +267,9 @@ void PengRobinson::getPartialMolarIntEnergies(double* ubar) const
// u_i = h_i - p*v_i
double p = pressure();
getPartialMolarEnthalpies(ubar);
getPartialMolarVolumes(m_tmpV.data());
getPartialMolarVolumes(m_workS.data());
for (size_t k = 0; k < m_kk; k++) {
ubar[k] = ubar[k] - p*m_tmpV[k];
ubar[k] = ubar[k] - p*m_workS[k];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/thermo/Phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ bool Phase::addSpecies(shared_ptr<Species> spec)
m_y.push_back(0.0);
m_ym.push_back(0.0);
}
m_tmpV.push_back(0.0);
m_workS.push_back(0.0);
invalidateCache();
return true;
}
Expand Down
20 changes: 10 additions & 10 deletions src/thermo/RedlichKwongMFTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ double RedlichKwongMFTP::pressure() const

double RedlichKwongMFTP::standardConcentration(size_t k) const
{
getStandardVolumes(m_tmpV.data());
return 1.0 / m_tmpV[k];
getStandardVolumes(m_workS.data());
return 1.0 / m_workS[k];
}

void RedlichKwongMFTP::getActivityCoefficients(double* ac) const
Expand Down Expand Up @@ -237,18 +237,18 @@ void RedlichKwongMFTP::getPartialMolarEnthalpies(double* hbar) const
double fac = TKelvin * dadt - 3.0 * m_a_current / 2.0;

for (size_t k = 0; k < m_kk; k++) {
m_tmpV[k] = 0.0;
m_workS[k] = 0.0;
for (size_t i = 0; i < m_kk; i++) {
size_t counter = k + m_kk*i;
m_tmpV[k] += 2.0 * moleFractions_[i] * TKelvin * a_coeff_vec(1,counter) - 3.0 * moleFractions_[i] * a_vec_Curr_[counter];
m_workS[k] += 2.0 * moleFractions_[i] * TKelvin * a_coeff_vec(1,counter) - 3.0 * moleFractions_[i] * a_vec_Curr_[counter];
}
}

pressureDerivatives();
double fac2 = mv + TKelvin * dpdT_ / dpdV_;
for (size_t k = 0; k < m_kk; k++) {
double hE_v = (mv * dpdni_[k] - RT() - b_vec_Curr_[k]/ (m_b_current * m_b_current * sqt) * log(vpb/mv)*fac
+ 1.0 / (m_b_current * sqt) * log(vpb/mv) * m_tmpV[k]
+ 1.0 / (m_b_current * sqt) * log(vpb/mv) * m_workS[k]
+ b_vec_Curr_[k] / vpb / (m_b_current * sqt) * fac);
hbar[k] = hbar[k] + hE_v;
hbar[k] -= fac2 * dpdni_[k];
Expand Down Expand Up @@ -276,10 +276,10 @@ void RedlichKwongMFTP::getPartialMolarEntropies(double* sbar) const
}
}
for (size_t k = 0; k < m_kk; k++) {
m_tmpV[k] = 0.0;
m_workS[k] = 0.0;
for (size_t i = 0; i < m_kk; i++) {
size_t counter = k + m_kk*i;
m_tmpV[k] += moleFractions_[i] * a_coeff_vec(1,counter);
m_workS[k] += moleFractions_[i] * a_coeff_vec(1,counter);
}
}

Expand All @@ -293,7 +293,7 @@ void RedlichKwongMFTP::getPartialMolarEntropies(double* sbar) const
+ GasConstant * log(mv/vmb)
+ GasConstant * b_vec_Curr_[k]/vmb
+ m_pp[k]/(m_b_current * TKelvin * sqt) * log(vpb/mv)
- 2.0 * m_tmpV[k]/(m_b_current * sqt) * log(vpb/mv)
- 2.0 * m_workS[k]/(m_b_current * sqt) * log(vpb/mv)
+ b_vec_Curr_[k] / (m_b_current * m_b_current * sqt) * log(vpb/mv) * fac
- 1.0 / (m_b_current * sqt) * b_vec_Curr_[k] / vpb * fac
);
Expand Down Expand Up @@ -327,10 +327,10 @@ void RedlichKwongMFTP::getPartialMolarVolumes(double* vbar) const
}
}
for (size_t k = 0; k < m_kk; k++) {
m_tmpV[k] = 0.0;
m_workS[k] = 0.0;
for (size_t i = 0; i < m_kk; i++) {
size_t counter = k + m_kk*i;
m_tmpV[k] += moleFractions_[i] * a_coeff_vec(1,counter);
m_workS[k] += moleFractions_[i] * a_coeff_vec(1,counter);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/thermo/VPStandardStateTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ void VPStandardStateTP::setPressure(double p)

void VPStandardStateTP::calcDensity()
{
getPartialMolarVolumes(m_tmpV.data());
double dd = meanMolecularWeight() / mean_X(m_tmpV);
getPartialMolarVolumes(m_workS.data());
double dd = meanMolecularWeight() / mean_X(m_workS);
Phase::assignDensity(dd);
}

Expand Down

0 comments on commit 10d7754

Please sign in to comment.