Skip to content

Commit

Permalink
[Thermo] Correct RedlichKwong::getPartialMolarIntEnergies
Browse files Browse the repository at this point in the history
Fixes #998
  • Loading branch information
speth committed Mar 15, 2022
1 parent b7f40b2 commit c72f095
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/thermo/RedlichKwongMFTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,13 @@ void RedlichKwongMFTP::getPartialMolarEntropies(doublereal* sbar) const

void RedlichKwongMFTP::getPartialMolarIntEnergies(doublereal* ubar) const
{
getIntEnergy_RT(ubar);
scale(ubar, ubar+m_kk, ubar, RT());
// u_k = h_k - P * v_k
getPartialMolarVolumes(m_partialMolarVolumes.data());
getPartialMolarEnthalpies(ubar);
double p = pressure();
for (size_t k = 0; k < nSpecies(); k++) {
ubar[k] -= p * m_partialMolarVolumes[k];
}
}

void RedlichKwongMFTP::getPartialMolarVolumes(doublereal* vbar) const
Expand Down
18 changes: 18 additions & 0 deletions test/thermo/RedlichKwongMFTP_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,22 @@ TEST_F(RedlichKwongMFTP_Test, localCritProperties)
EXPECT_NEAR(test_phase->critPressure(), 22.064e6, 1e-4);
}

TEST_F(RedlichKwongMFTP_Test, partialMolarIntEnergy)
{
// Check that sum(X_k * u) = u
set_r(0.4);
test_phase->setState_TP(400, 1.3e7);
double u_ref = test_phase->intEnergy_mole();
size_t kk = test_phase->nSpecies();
vector_fp uk(kk);
vector_fp X(kk);
test_phase->getMoleFractions(X.data());
test_phase->getPartialMolarIntEnergies(uk.data());
double u_test = 0;
for (size_t k = 0; k < kk; k++) {
u_test += uk[k] * X[k];
}
EXPECT_NEAR(u_ref, u_test, 1e-13 * std::abs(u_ref));
}

};

0 comments on commit c72f095

Please sign in to comment.