From e42b8a0ba2c315dcb5b8017cc5f3ddf28e1ff612 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 21 Dec 2021 23:22:48 -0500 Subject: [PATCH 1/6] [SCons] Use specified compiler options for configuration checks --- SConstruct | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index 6b34c1da00..f665a1a463 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.') From 069fb636cd0e380f64f2db322c7d1967344f09ad Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 21 Dec 2021 23:23:38 -0500 Subject: [PATCH 2/6] [SCons] Require a working implementation of std::isnan Fixes #1155 --- SConstruct | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SConstruct b/SConstruct index f665a1a463..c53e0fdad8 100644 --- a/SConstruct +++ b/SConstruct @@ -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'): From 895225d69e29204058216dcd99d77ad0097775b2 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 22 Dec 2021 00:04:25 -0500 Subject: [PATCH 3/6] [Test] Avoid exact float comparisons --- interfaces/cython/cantera/test/test_kinetics.py | 5 ++--- interfaces/cython/cantera/test/test_reaction.py | 6 +++--- test/kinetics/kineticsFromYaml.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) 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/test/kinetics/kineticsFromYaml.cpp b/test/kinetics/kineticsFromYaml.cpp index 97de849cf6..4e57b291c8 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; From b2ebb7012dc327dabc16434dabb3aa67d9a1c61a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 22 Dec 2021 00:04:28 -0500 Subject: [PATCH 4/6] [Test] Relax some test tolerances This allows the test suite to pass even when using unsafe math optimizations --- test/kinetics/kineticsFromYaml.cpp | 8 ++++---- test/thermo/PengRobinson_Test.cpp | 6 +++--- test/thermo/water_iapws.cpp | 2 +- test_problems/SConscript | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/kinetics/kineticsFromYaml.cpp b/test/kinetics/kineticsFromYaml.cpp index 4e57b291c8..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_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]); + 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'), From 0da13017e985739efc3f6c9d0a4bb8b49ba28408 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 22 Dec 2021 00:08:15 -0500 Subject: [PATCH 5/6] [CI] Run some CI builds with unsafe math optimizations --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 71a0ffa054ccaad903c546a9e33a9c53c9782bf2 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 22 Dec 2021 11:06:49 -0500 Subject: [PATCH 6/6] [Test] Impove consistency of VCS-LiSi-verbose output --- src/equil/vcs_solve_TP.cpp | 20 +++---------------- .../LatticeSolid_LiSi/verbose_blessed.txt | 6 +++--- 2 files changed, 6 insertions(+), 20 deletions(-) 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_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