diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index 49d81807c..2ce92c0e9 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -647,8 +647,6 @@ void RedlichKwongMFTP::initThermoXML(XML_Node& phaseNode, const std::string& id) vector 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 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 diff --git a/test/thermo/phaseConstructors.cpp b/test/thermo/phaseConstructors.cpp index c9ae697e5..c4b2c758a 100644 --- a/test/thermo/phaseConstructors.cpp +++ b/test/thermo/phaseConstructors.cpp @@ -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;