[Thermo] Generalize check for missing Redlich-Kwong coefficients

A check in the "updateAB" function will be executed regardless of how the phase
is instantiated.
This commit is contained in:
Ray Speth 2019-02-04 17:53:27 -05:00
parent f385f48190
commit 33e198f7e5
2 changed files with 28 additions and 10 deletions

View file

@ -647,8 +647,6 @@ void RedlichKwongMFTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
vector<double> RedlichKwongMFTP::getCoeff(const std::string& iName)
{
vector_fp vParams;
bool found = false;
vector_fp spCoeff{NAN, NAN};
// Get number of species in the database
@ -705,17 +703,9 @@ vector<double> RedlichKwongMFTP::getCoeff(const std::string& iName)
//Assuming no temperature dependence
spCoeff[0] = omega_a * pow(GasConstant, 2) * pow(T_crit, 2.5) / P_crit; //coeff a
spCoeff[1] = omega_b * GasConstant * T_crit / P_crit; // coeff b
found = true;
break;
}
}
if (!found) {
// Species is present in neither CTI/xml nor database: throw error
throw CanteraError("RedlichKwongMFTP::getCoeff",
"pureFluidParameters for species " +
iName + " are undefined");
}
return spCoeff;
}
@ -1026,6 +1016,21 @@ void RedlichKwongMFTP::updateAB()
m_a_current += a_vec_Curr_[i * m_kk + j] * moleFractions_[i] * moleFractions_[j];
}
}
if (isnan(m_b_current)) {
// One or more species do not have specified coefficients.
fmt::memory_buffer b;
for (size_t k = 0; k < m_kk; k++) {
if (isnan(b_vec_Curr_[k])) {
if (b.size() > 0) {
format_to(b, ", {}", speciesName(k));
} else {
format_to(b, "{}", speciesName(k));
}
}
}
throw CanteraError("RedlichKwongMFTP::updateAB",
"Missing Redlich-Kwong coefficients for species: {}", to_string(b));
}
}
void RedlichKwongMFTP::calculateAB(doublereal temp, doublereal& aCalc, doublereal& bCalc) const

View file

@ -330,6 +330,19 @@ TEST_F(ConstructFromScratch, RedlichKwongMFTP)
EXPECT_NEAR(p.gibbs_mass(), -1.0607e7, 2e3);
}
TEST_F(ConstructFromScratch, RedlichKwongMFTP_missing_coeffs)
{
RedlichKwongMFTP p;
p.addSpecies(sH2O);
p.addSpecies(sCO2);
p.addSpecies(sH2);
double fa = toSI("bar-cm6/mol2");
double fb = toSI("cm3/mol");
p.setSpeciesCoeffs("H2O", 1.7458e8 * fa, -8e4 * fa, 18.18 * fb);
p.setSpeciesCoeffs("H2", 30e7 * fa, -330e4 * fa, 31 * fb);
EXPECT_THROW(p.setState_TP(300, 200e5), CanteraError);
}
TEST_F(ConstructFromScratch, IdealSolnGasVPSS_gas)
{
IdealSolnGasVPSS p;