diff --git a/include/cantera/base/ct_defs.h b/include/cantera/base/ct_defs.h index 534e2c83a..943a49ccd 100644 --- a/include/cantera/base/ct_defs.h +++ b/include/cantera/base/ct_defs.h @@ -35,6 +35,7 @@ namespace Cantera using std::shared_ptr; using std::make_shared; +using std::isnan; // workaround for bug in libstdc++ 4.8 /*! * All physical constants are stored here. diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index 7be94f43a..49d81807c 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -80,12 +80,11 @@ void RedlichKwongMFTP::setSpeciesCoeffs(const std::string& species, continue; } - // a_coeff_vec is initialized to -1, so screen for unidentified species to prevent - // imaginary numbers on the off-diagonals: - if (a_coeff_vec(0, j + m_kk * j) < 0 || a_coeff_vec(1, j + m_kk * j) < 0){ + // a_coeff_vec(0) is initialized to NaN to mark uninitialized species + if (isnan(a_coeff_vec(0, j + m_kk * j))) { // The diagonal element of the jth species has not yet been defined. continue; - } else if (a_coeff_vec(0, j + m_kk * k) == -1) { + } else if (isnan(a_coeff_vec(0, j + m_kk * k))) { // Only use the mixing rules if the off-diagonal element has not already been defined by a // user-specified crossFluidParameters entry: double a0kj = sqrt(a_coeff_vec(0, j + m_kk * j) * a0); @@ -555,10 +554,10 @@ bool RedlichKwongMFTP::addSpecies(shared_ptr spec) if (added) { a_vec_Curr_.resize(m_kk * m_kk, 0.0); - // Initialize a_vec and b_vec to -1, to screen for species with + // Initialize a_vec and b_vec to NaN, to screen for species with // pureFluidParameters which are undefined in the input file: - b_vec_Curr_.push_back(-1); - a_coeff_vec.resize(2, m_kk * m_kk, -1); + b_vec_Curr_.push_back(NAN); + a_coeff_vec.resize(2, m_kk * m_kk, NAN); m_pp.push_back(0.0); m_tmpV.push_back(0.0); @@ -614,8 +613,7 @@ void RedlichKwongMFTP::initThermoXML(XML_Node& phaseNode, const std::string& id) size_t counter = iSpecies + m_kk * iSpecies; // If not, then search the database: - if (a_coeff_vec(0, counter) == -1 || - b_vec_Curr_[iSpecies] == -1) { + if (isnan(a_coeff_vec(0, counter))) { vector coeffArray; @@ -626,7 +624,7 @@ void RedlichKwongMFTP::initThermoXML(XML_Node& phaseNode, const std::string& id) // Check if species was found in the database of critical properties, // and assign the results - if (coeffArray[0] != -1 || coeffArray[1] != -1) { + if (!isnan(coeffArray[0])) { //Assuming no temperature dependence (i,e a1 = 0) setSpeciesCoeffs(iName, coeffArray[0], 0.0, coeffArray[1]); } @@ -651,9 +649,7 @@ vector RedlichKwongMFTP::getCoeff(const std::string& iName) { vector_fp vParams; bool found = false; - vector spCoeff(2); - spCoeff[0] = -1; - spCoeff[1] = -1; + vector_fp spCoeff{NAN, NAN}; // Get number of species in the database // open xml file critProperties.xml diff --git a/test/thermo/phaseConstructors.cpp b/test/thermo/phaseConstructors.cpp index bfdaa3ee3..c9ae697e5 100644 --- a/test/thermo/phaseConstructors.cpp +++ b/test/thermo/phaseConstructors.cpp @@ -323,6 +323,11 @@ TEST_F(ConstructFromScratch, RedlichKwongMFTP) // Arbitrary regression test values EXPECT_NEAR(p.density(), 892.421, 2e-3); EXPECT_NEAR(p.enthalpy_mole(), -404848642.3797, 1e-3); + + p.setMoleFractionsByName("CO2:.6, H2O:0.02, H2:0.38"); + p.setState_TP(350, 180*OneAtm); + EXPECT_NEAR(p.density(), 181.568, 2e-3); + EXPECT_NEAR(p.gibbs_mass(), -1.0607e7, 2e3); } TEST_F(ConstructFromScratch, IdealSolnGasVPSS_gas)