diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 84cd5ae713..3607600432 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -315,7 +315,8 @@ jobs: run: | scons build extra_inc_dirs=$CONDA_PREFIX/include:$CONDA_PREFIX/include/eigen3 \ extra_lib_dirs=$CONDA_PREFIX/lib system_fmt=y system_eigen=y system_yamlcpp=y \ - system_sundials=y blas_lapack_libs='lapack,blas' -j2 VERBOSE=True debug=n + system_sundials=y blas_lapack_libs='lapack,blas' -j2 VERBOSE=True debug=n \ + optimize_flags='-O3 -ffast-math -fno-finite-math-only' - name: Test Cantera run: scons test show_long_tests=yes verbose_tests=yes diff --git a/SConstruct b/SConstruct index 6b34c1da00..c53e0fdad8 100644 --- a/SConstruct +++ b/SConstruct @@ -960,8 +960,6 @@ int main(int argc, char** argv) { context.Result(result) return result -conf = Configure(env, custom_tests={'CheckStatement': CheckStatement}) - # Set up compiler options before running configuration tests env['CXXFLAGS'] = listify(env['cxx_flags']) env['CCFLAGS'] = listify(env['cc_flags']) + listify(env['thread_flags']) @@ -1007,6 +1005,8 @@ def config_error(message): print("See 'config.log' for details.") sys.exit(1) +conf = Configure(env, custom_tests={'CheckStatement': CheckStatement}) + # First, a sanity check: if not conf.CheckCXXHeader('cmath', '<>'): config_error('The C++ compiler is not correctly configured.') @@ -1027,6 +1027,16 @@ def get_expression_value(includes, expression, defines=()): '}\n')) return '\n'.join(s) +# Check that NaN is treated correctly +nan_check_source = get_expression_value([""], 'std::isnan(NAN + argc)') +retcode, nan_works = conf.TryRun(nan_check_source, ".cpp") +if nan_works.strip() != "1": + config_error( + "Cantera requires a working implementation of 'std::isnan'.\n" + "If you have specified '-ffast-math' or equivalent as an optimization option,\n" + "either remove this option or add the '-fno-finite-math-only option'." + ) + # Check for fmt library and checkout submodule if needed # Test for 'ostream.h' to ensure that version >= 3.0.0 is available if env['system_fmt'] in ('y', 'default'): diff --git a/interfaces/cython/cantera/test/test_kinetics.py b/interfaces/cython/cantera/test/test_kinetics.py index a359bcf8c7..844648cf75 100644 --- a/interfaces/cython/cantera/test/test_kinetics.py +++ b/interfaces/cython/cantera/test/test_kinetics.py @@ -255,8 +255,7 @@ def test_surface(self): r2.rate.pre_exponential_factor) self.assertEqual(r1.rate.temperature_exponent, r2.rate.temperature_exponent) - self.assertEqual(r1.rate.activation_energy, - r2.rate.activation_energy) + self.assertNear(r1.rate.activation_energy, r2.rate.activation_energy) self.assertArrayNear(surf1.delta_enthalpy, surf2.delta_enthalpy) @@ -1342,7 +1341,7 @@ def test_Blowers_Masel_change_enthalpy(self): species.thermo = ct.NasaPoly2(species.thermo.min_temp, species.thermo.max_temp, species.thermo.reference_pressure, perturbed_coeffs) gas.modify_species(index, species) - self.assertEqual(deltaH_high, gas.reaction(0).rate.activation_energy(deltaH_high)) + self.assertNear(deltaH_high, gas.reaction(0).rate.activation_energy(deltaH_high)) self.assertNear(A*gas.T**b*np.exp(-deltaH_high/ct.gas_constant/gas.T), gas.forward_rate_constants[0]) perturbed_coeffs = species.thermo.coeffs.copy() diff --git a/interfaces/cython/cantera/test/test_reaction.py b/interfaces/cython/cantera/test/test_reaction.py index a7c42f4f94..620cd3505a 100644 --- a/interfaces/cython/cantera/test/test_reaction.py +++ b/interfaces/cython/cantera/test/test_reaction.py @@ -231,7 +231,7 @@ def test_from_parts(self): rate = self.from_parts() self.assertEqual(self._parts["A"], rate.pre_exponential_factor) self.assertEqual(self._parts["b"], rate.temperature_exponent) - self.assertEqual(self._parts["Ea"], rate.activation_energy) + self.assertNear(self._parts["Ea"], rate.activation_energy) self.check_rate(rate) def test_negative_A(self): @@ -273,8 +273,8 @@ def test_from_parts(self): rate = self.from_parts() self.assertEqual(self._parts["A"], rate.pre_exponential_factor) self.assertEqual(self._parts["b"], rate.temperature_exponent) - self.assertEqual(self._parts["Ea0"], rate.intrinsic_activation_energy) - self.assertEqual(self._parts["w"], rate.bond_energy) + self.assertNear(self._parts["Ea0"], rate.intrinsic_activation_energy) + self.assertNear(self._parts["w"], rate.bond_energy) self.check_rate(rate) def test_negative_A(self): diff --git a/src/equil/vcs_solve_TP.cpp b/src/equil/vcs_solve_TP.cpp index 67e019a09b..e1e969a8bd 100644 --- a/src/equil/vcs_solve_TP.cpp +++ b/src/equil/vcs_solve_TP.cpp @@ -1943,20 +1943,8 @@ bool VCS_SOLVE::vcs_globStepDamp() plogf(" --- subroutine FORCE: End Slope = %g\n", s2); } - if (s1 > 0.0) { - if (m_debug_print_lvl >= 2) { - plogf(" --- subroutine FORCE produced no adjustments,"); - if (s1 < 1.0E-40) { - plogf(" s1 positive but really small\n"); - } else { - plogf(" failed s1 test\n"); - } - } - return false; - } - - if (s2 <= 0.0) { - debuglog(" --- subroutine FORCE produced no adjustments, s2 < 0\n", m_debug_print_lvl >= 2); + if (s1 > 0.0 || s2 <= 0.0) { + debuglog(" --- subroutine FORCE produced no adjustments\n", m_debug_print_lvl >= 2); return false; } @@ -1966,9 +1954,7 @@ bool VCS_SOLVE::vcs_globStepDamp() al = s1 / (s1 - s2); } if (al >= 0.95 || al < 0.0) { - if (m_debug_print_lvl >= 2) { - plogf(" --- subroutine FORCE produced no adjustments (al = %g)\n", al); - } + debuglog(" --- subroutine FORCE produced no adjustments\n", m_debug_print_lvl >= 2); return false; } if (m_debug_print_lvl >= 2) { diff --git a/test/kinetics/kineticsFromYaml.cpp b/test/kinetics/kineticsFromYaml.cpp index 97de849cf6..0b6c9c6c36 100644 --- a/test/kinetics/kineticsFromYaml.cpp +++ b/test/kinetics/kineticsFromYaml.cpp @@ -494,10 +494,10 @@ class ReactionToYaml : public testing::Test kin->getRevRateConstants(kr.data()); kin->getFwdRatesOfProgress(ropf.data()); kin->getRevRatesOfProgress(ropr.data()); - EXPECT_DOUBLE_EQ(kf[iOld], kf[iNew]); - EXPECT_DOUBLE_EQ(kr[iOld], kr[iNew]); - EXPECT_DOUBLE_EQ(ropf[iOld], ropf[iNew]); - EXPECT_DOUBLE_EQ(ropr[iOld], ropr[iNew]); + EXPECT_NEAR(kf[iOld], kf[iNew], 1e-13 * kf[iOld]); + EXPECT_NEAR(kr[iOld], kr[iNew], 1e-13 * kr[iOld]); + EXPECT_NEAR(ropf[iOld], ropf[iNew], 1e-13 * ropf[iOld]); + EXPECT_NEAR(ropr[iOld], ropr[iNew], 1e-13 * ropr[iOld]); } shared_ptr soln; diff --git a/test/thermo/PengRobinson_Test.cpp b/test/thermo/PengRobinson_Test.cpp index b0d33c1a47..61706e7cba 100644 --- a/test/thermo/PengRobinson_Test.cpp +++ b/test/thermo/PengRobinson_Test.cpp @@ -186,13 +186,13 @@ TEST_F(PengRobinson_Test, setTP) const double temp = 294 + i*2; set_r(0.999); test_phase->setState_TP(temp, 5542027.5); - EXPECT_NEAR(test_phase->density(),rho1[i],1.e-8); + EXPECT_NEAR(test_phase->density(), rho1[i], 1.e-8); test_phase->setState_TP(temp, 7388370.); - EXPECT_NEAR(test_phase->density(),rho2[i],1.e-8); + EXPECT_NEAR(test_phase->density(), rho2[i], 1.e-7); test_phase->setState_TP(temp, 9236712.5); - EXPECT_NEAR(test_phase->density(),rho3[i],1.e-8); + EXPECT_NEAR(test_phase->density(), rho3[i], 1.e-8); } } diff --git a/test/thermo/water_iapws.cpp b/test/thermo/water_iapws.cpp index 9705632c2a..03eceb341c 100644 --- a/test/thermo/water_iapws.cpp +++ b/test/thermo/water_iapws.cpp @@ -138,6 +138,6 @@ TEST_F(WaterPropsIAPWS_Test, expansion_coeffs) EXPECT_NEAR(water.coeffThermExp(), alpha[i], 2e-14); EXPECT_NEAR(water.coeffPresExp(), beta[i], beta[i] * 2e-12); EXPECT_NEAR(dPdT(TT[i], PP[i]) * 18.015268 / (8.314371E3 * rho), - beta_num[i], 2e-10 * beta_num[i]); + beta_num[i], 4e-10 * beta_num[i]); } } diff --git a/test_problems/SConscript b/test_problems/SConscript index d3f20e5f5e..fee77b20b6 100644 --- a/test_problems/SConscript +++ b/test_problems/SConscript @@ -253,7 +253,7 @@ Test('cxx-flamespeed', 'cxx_samples', '#build/samples/cxx/flamespeed/flamespeed' options='0.9 0 0') Test('cxx-kinetics1', 'cxx_samples', '#build/samples/cxx/kinetics1/kinetics1', None, comparisons=[('kin1_blessed.csv', 'kin1.csv')], - artifacts=['kin1.dat'], slow=True) + artifacts=['kin1.dat'], slow=True, tolerance=2e-4) Test('cxx-gas-transport', 'cxx_samples', '#build/samples/cxx/gas_transport/gas_transport', None, slow=True, comparisons=[('transport_mix_blessed.csv', 'transport_mix.csv'), diff --git a/test_problems/VCSnonideal/LatticeSolid_LiSi/verbose_blessed.txt b/test_problems/VCSnonideal/LatticeSolid_LiSi/verbose_blessed.txt index a00d6d864f..90abc0c082 100644 --- a/test_problems/VCSnonideal/LatticeSolid_LiSi/verbose_blessed.txt +++ b/test_problems/VCSnonideal/LatticeSolid_LiSi/verbose_blessed.txt @@ -227,7 +227,7 @@ VCS CALCULATION METHOD --- Total tentative Dimensionless Gibbs Free Energy = -4.1206752525561E+03 --- subroutine FORCE: Beginning Slope = -0.109397 --- subroutine FORCE: End Slope = -0.0989949 - --- subroutine FORCE produced no adjustments, s2 < 0 + --- subroutine FORCE produced no adjustments ------------------------------------------------------------------------------------------------------- --- Summary of the Update (all species): --- Species Status Initial_KMoles Final_KMoles Initial_Mu/RT Mu/RT Init_Del_G/RT Delta_G/RT @@ -285,7 +285,7 @@ VCS CALCULATION METHOD --- Total tentative Dimensionless Gibbs Free Energy = -4.1206857517346E+03 --- subroutine FORCE: Beginning Slope = -0.0109994 --- subroutine FORCE: End Slope = 5.0022e-07 - --- subroutine FORCE produced no adjustments (al = 0.999955) + --- subroutine FORCE produced no adjustments ------------------------------------------------------------------------------------------------------- --- Summary of the Update (all species): --- Species Status Initial_KMoles Final_KMoles Initial_Mu/RT Mu/RT Init_Del_G/RT Delta_G/RT @@ -342,7 +342,7 @@ VCS CALCULATION METHOD --- Total tentative Dimensionless Gibbs Free Energy = -4.1206857517346E+03 --- subroutine FORCE: Beginning Slope = -1.39826e-19 --- subroutine FORCE: End Slope = 9.31017e-32 - --- subroutine FORCE produced no adjustments, s2 < 0 + --- subroutine FORCE produced no adjustments ------------------------------------------------------------------------------------------------------- --- Summary of the Update (all species): --- Species Status Initial_KMoles Final_KMoles Initial_Mu/RT Mu/RT Init_Del_G/RT Delta_G/RT