Skip to content

Commit

Permalink
[Input] Handle options for setting molar volume in PDSS_ConstVol
Browse files Browse the repository at this point in the history
PDSS_ConstVol now converts 'density' and 'molar-density' fields from
the 'equation-of-state' field, making it consistent with other phases
that support these options.
  • Loading branch information
speth committed Mar 4, 2023
1 parent 4ff5950 commit 7f04d83
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/thermo/PDSS_ConstVol.cpp
Expand Up @@ -22,7 +22,11 @@ PDSS_ConstVol::PDSS_ConstVol()
void PDSS_ConstVol::initThermo()
{
PDSS::initThermo();
if (m_input.hasKey("molar-volume")) {
if (m_input.hasKey("density")) {
setMolarVolume(m_mw / m_input.convert("density", "kg/m^3"));
} else if (m_input.hasKey("molar-density")) {
setMolarVolume(1.0 / m_input.convert("molar-density", "kmol/m^3"));
} else if (m_input.hasKey("molar-volume")) {
setMolarVolume(m_input.convert("molar-volume", "m^3/kmol"));
}
m_minTemp = m_spthermo->minTemp();
Expand All @@ -36,7 +40,14 @@ void PDSS_ConstVol::getParameters(AnyMap &eosNode) const
{
PDSS::getParameters(eosNode);
eosNode["model"] = "constant-volume";
eosNode["molar-volume"].setQuantity(m_constMolarVolume, "m^3/kmol");
// Output volume information in a form consistent with the input
if (m_input.hasKey("density")) {
eosNode["density"].setQuantity(m_mw / m_constMolarVolume, "kg/m^3");
} else if (m_input.hasKey("molar-density")) {
eosNode["molar-density"].setQuantity(1.0 / m_constMolarVolume, "kmol/m^3");
} else {
eosNode["molar-volume"].setQuantity(m_constMolarVolume, "m^3/kmol");
}
}

doublereal PDSS_ConstVol::intEnergy_mole() const
Expand Down
4 changes: 2 additions & 2 deletions test/data/thermo-models.yaml
Expand Up @@ -439,7 +439,7 @@ ideal-molal-fake-species:
-917.935173, 0.683010238]
equation-of-state:
model: constant-volume
molar-volume: 0.1
molar-density: 10
- name: CH4(aq)
composition: {C: 1, H: 4}
thermo:
Expand All @@ -450,7 +450,7 @@ ideal-molal-fake-species:
-917.935173, 0.683010238]
equation-of-state:
model: constant-volume
molar-volume: 0.1
density: 160.43 g/L


dh-electrolyte-species:
Expand Down
8 changes: 8 additions & 0 deletions test/thermo/thermoFromYaml.cpp
Expand Up @@ -148,6 +148,14 @@ TEST(ThermoFromYaml, IdealMolalSoln)
EXPECT_NEAR(thermo->enthalpy_mole(), 0.013282, 1e-6);
EXPECT_NEAR(thermo->gibbs_mole(), -3.8986e7, 1e3);
EXPECT_NEAR(thermo->density(), 12.058, 1e-3);

size_t N = thermo->nSpecies();
vector_fp mv(N);
double mvRef[] = {1.5, 1.3, 0.1, 0.1};
thermo->getPartialMolarVolumes(mv.data());
for (size_t k = 0; k < N; k++) {
EXPECT_NEAR(mv[k], mvRef[k], 1e-8) << k;
}
}

TEST(ThermoFromYaml, DebyeHuckel_bdot_ak)
Expand Down
5 changes: 4 additions & 1 deletion test/thermo/thermoToYaml.cpp
Expand Up @@ -301,7 +301,10 @@ TEST_F(ThermoToYaml, IdealMolalSolution)
EXPECT_DOUBLE_EQ(cutoff["gamma_o"].asDouble(), 0.0001);

EXPECT_EQ(eosData[2]["model"], "constant-volume");
EXPECT_DOUBLE_EQ(eosData[2]["molar-volume"].asDouble(), 0.1);
EXPECT_DOUBLE_EQ(eosData[2]["molar-density"].asDouble(), 10);

EXPECT_EQ(eosData[3]["model"], "constant-volume");
EXPECT_DOUBLE_EQ(eosData[3]["density"].asDouble(), 160.43);
}

TEST_F(ThermoToYaml, IsotropicElectronEnergyPlasma)
Expand Down

0 comments on commit 7f04d83

Please sign in to comment.