From e29e943ae6e478779cb8847810ab862fbc9ff40b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 25 Sep 2024 18:15:49 -0400 Subject: [PATCH] apply clang-format --- src/fix_efield.cpp | 2 -- unittest/force-styles/test_dihedral_style.cpp | 15 ++++---- unittest/force-styles/test_fix_timestep.cpp | 35 ++++++++++--------- unittest/force-styles/test_main.cpp | 2 +- unittest/force-styles/test_main.h | 16 ++++----- unittest/utils/test_fmtlib.cpp | 6 ++-- 6 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/fix_efield.cpp b/src/fix_efield.cpp index 646ef43460..615f13fcdc 100644 --- a/src/fix_efield.cpp +++ b/src/fix_efield.cpp @@ -518,6 +518,4 @@ void FixEfield::update_efield_variables() input->variable->compute_atom(evar, igroup, &efield[0][3], 4, 0); modify->addstep_compute(update->ntimestep + 1); - } - diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 656a45861e..deda7ffbfd 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -364,7 +364,7 @@ TEST(DihedralStyle, plain) stats.reset(); auto *icompute = lmp->modify->get_compute_by_id("sum"); - double energy = 0.0; + double energy = 0.0; if (icompute) energy = icompute->compute_scalar(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(dihedral->energy, energy, epsilon); @@ -486,7 +486,7 @@ TEST(DihedralStyle, omp) stats.reset(); auto *icompute = lmp->modify->get_compute_by_id("sum"); - double energy = 0.0; + double energy = 0.0; if (icompute) energy = icompute->compute_scalar(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for OPENMP with dihedral style hybrid @@ -542,8 +542,9 @@ TEST(DihedralStyle, kokkos_omp) if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); - LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite", - "-k", "on", "t", "4", "-sf", "kk"}; + LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", + "-nocite", "-k", "on", "t", "4", + "-sf", "kk"}; ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(args, test_config, true); @@ -595,9 +596,9 @@ TEST(DihedralStyle, kokkos_omp) // FIXME: this is currently broken ??? for KOKKOS with dihedral style hybrid // needs to be fixed in the main code somewhere. Not sure where, though. - //if (test_config.dihedral_style.substr(0, 6) != "hybrid") + // if (test_config.dihedral_style.substr(0, 6) != "hybrid") // EXPECT_FP_LE_WITH_EPS(dihedral->energy, energy, epsilon); - //if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; + // if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); @@ -631,7 +632,7 @@ TEST(DihedralStyle, kokkos_omp) // FIXME: this is currently broken ??? for KOKKOS with dihedral style hybrid // needs to be fixed in the main code somewhere. Not sure where, though. - //if (test_config.dihedral_style.substr(0, 6) != "hybrid") + // if (test_config.dihedral_style.substr(0, 6) != "hybrid") // EXPECT_FP_LE_WITH_EPS(dihedral->energy, energy, epsilon); if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index 486277d770..7d12d0b20c 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -247,14 +247,15 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_torque - if(lmp->atom->torque_flag) { - block.clear(); - auto *t = lmp->atom->torque; - for (int i = 1; i <= natoms; ++i) { - const int j = lmp->atom->map(i); - block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, t[j][0], t[j][1], t[j][2]); - } - writer.emit_block("run_torque", block); + if (lmp->atom->torque_flag) { + block.clear(); + auto *t = lmp->atom->torque; + for (int i = 1; i <= natoms; ++i) { + const int j = lmp->atom->map(i); + block += + fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, t[j][0], t[j][1], t[j][2]); + } + writer.emit_block("run_torque", block); } cleanup_lammps(lmp, config); @@ -301,9 +302,9 @@ TEST(FixTimestep, plain) EXPECT_POSITIONS("run_pos (normal run, verlet)", lmp->atom, test_config.run_pos, epsilon); EXPECT_VELOCITIES("run_vel (normal run, verlet)", lmp->atom, test_config.run_vel, epsilon); - if(lmp->atom->torque_flag) - EXPECT_TORQUES("run_torques (normal run, verlet)", lmp->atom, test_config.run_torque, epsilon); - + if (lmp->atom->torque_flag) + EXPECT_TORQUES("run_torques (normal run, verlet)", lmp->atom, test_config.run_torque, + epsilon); auto *ifix = lmp->modify->get_fix_by_id("test"); if (!ifix) { @@ -353,7 +354,7 @@ TEST(FixTimestep, plain) EXPECT_POSITIONS("run_pos (restart, verlet)", lmp->atom, test_config.run_pos, epsilon); EXPECT_VELOCITIES("run_vel (restart, verlet)", lmp->atom, test_config.run_vel, epsilon); - if(lmp->atom->torque_flag) + if (lmp->atom->torque_flag) EXPECT_TORQUES("run_torque (restart, verlet)", lmp->atom, test_config.run_torque, epsilon); ifix = lmp->modify->get_fix_by_id("test"); @@ -858,7 +859,7 @@ TEST(FixTimestep, kokkos_omp) if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite", - "-k", "on", "t", "4", "-sf", "kk"}; + "-k", "on", "t", "4", "-sf", "kk"}; ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(args, test_config); @@ -892,8 +893,9 @@ TEST(FixTimestep, kokkos_omp) EXPECT_POSITIONS("run_pos (normal run, verlet)", lmp->atom, test_config.run_pos, epsilon); EXPECT_VELOCITIES("run_vel (normal run, verlet)", lmp->atom, test_config.run_vel, epsilon); - if(lmp->atom->torque_flag) - EXPECT_TORQUES("run_torque (normal run, verlet)", lmp->atom, test_config.run_torque, epsilon); + if (lmp->atom->torque_flag) + EXPECT_TORQUES("run_torque (normal run, verlet)", lmp->atom, test_config.run_torque, + epsilon); auto *ifix = lmp->modify->get_fix_by_id("test"); @@ -945,7 +947,7 @@ TEST(FixTimestep, kokkos_omp) EXPECT_POSITIONS("run_pos (restart, verlet)", lmp->atom, test_config.run_pos, epsilon); EXPECT_VELOCITIES("run_vel (restart, verlet)", lmp->atom, test_config.run_vel, epsilon); - if(lmp->atom->torque_flag) + if (lmp->atom->torque_flag) EXPECT_TORQUES("run_torque (restart, verlet)", lmp->atom, test_config.run_torque, epsilon); ifix = lmp->modify->get_fix_by_id("test"); @@ -1023,4 +1025,3 @@ TEST(FixTimestep, kokkos_omp) cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; - diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index b45c6cf723..bdaae81512 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -102,7 +102,7 @@ void EXPECT_VELOCITIES(const std::string &name, Atom *atom, const std::vector &t_ref, - double epsilon) + double epsilon) { SCOPED_TRACE("EXPECT_TORQUES: " + name); double **t = atom->torque; diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index 7ec3955fcb..3aadf7b791 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -28,13 +28,13 @@ extern std::string INPUT_FOLDER; // convenience method to write out common entries void write_yaml_header(class YamlWriter *writer, TestConfig *cfg, const char *version); -#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \ - do { \ - const double diff = fabs(val1 - val2); \ - const double div = std::min(fabs(val1), fabs(val2)); \ - const double err = (div==0.0) ? diff : diff/div; \ - stats.add(err); \ - EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ +#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \ + do { \ + const double diff = fabs(val1 - val2); \ + const double div = std::min(fabs(val1), fabs(val2)); \ + const double err = (div == 0.0) ? diff : diff / div; \ + stats.add(err); \ + EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ } while (0); void EXPECT_STRESS(const std::string &name, double *stress, const stress_t &expected_stress, @@ -46,6 +46,6 @@ void EXPECT_POSITIONS(const std::string &name, LAMMPS_NS::Atom *atom, void EXPECT_VELOCITIES(const std::string &name, LAMMPS_NS::Atom *atom, const std::vector &v_ref, double epsilon); void EXPECT_TORQUES(const std::string &name, LAMMPS_NS::Atom *atom, - const std::vector &t_ref, double epsilon); + const std::vector &t_ref, double epsilon); #endif diff --git a/unittest/utils/test_fmtlib.cpp b/unittest/utils/test_fmtlib.cpp index 1f30a76529..b78dbc0680 100644 --- a/unittest/utils/test_fmtlib.cpp +++ b/unittest/utils/test_fmtlib.cpp @@ -126,13 +126,11 @@ TEST(FmtLib, insert_neg_double) TEST(FmtLib, int_for_double) { const double val = -1.5; - std::string text; - ASSERT_THROW( text = fmt::format("word {:d}", val), std::exception); + ASSERT_THROW(auto text = fmt::format("word {:d}", val), std::exception); } TEST(FmtLib, double_for_int) { const int val = 15; - std::string text; - ASSERT_THROW( text = fmt::format("word {:g}", val), std::exception); + ASSERT_THROW(auto text = fmt::format("word {:g}", val), std::exception); }