From 615b7ceca285760359ec76ed483474b799bbb729 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 10:58:29 -0500 Subject: [PATCH] Simplify EXPECT_FORCES() utility function --- unittest/force-styles/test_main.cpp | 7 +++- unittest/force-styles/test_main.h | 5 ++- unittest/force-styles/test_pair_style.cpp | 50 +++++++++++------------ 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index 6204f60f46..f0cba47287 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -21,6 +21,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "lammps.h" +#include "atom.h" #include #include @@ -30,6 +31,7 @@ #include using LAMMPS_NS::LAMMPS; +using LAMMPS_NS::Atom; using LAMMPS_NS::utils::split_words; using LAMMPS_NS::utils::trim; using LAMMPS_NS::tagint; @@ -46,7 +48,10 @@ void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & e if (print_stats) std::cerr << name << " stats" << stats << std::endl; } -void EXPECT_FORCES(const std::string & name, double ** f, tagint * tag, int nlocal, const std::vector & f_ref, double epsilon) { +void EXPECT_FORCES(const std::string & name, Atom * atom, const std::vector & f_ref, double epsilon) { + double ** f = atom->f; + tagint * tag = atom->tag; + const int nlocal = atom->nlocal; ASSERT_EQ(nlocal + 1, f_ref.size()); ErrorStats stats; for (int i = 0; i < nlocal; ++i) { diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index cf602b5bb4..6e08235eae 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -15,7 +15,8 @@ #define TEST_MAIN_H #include "test_config.h" -#include "lmptype.h" +#include "lammps.h" +#include "atom.h" #include #include @@ -37,6 +38,6 @@ void write_yaml_header(class YamlWriter *writer, TestConfig *cfg, const char *ve } while (0); void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon); -void EXPECT_FORCES(const std::string & name, double ** f, LAMMPS_NS::tagint * tag, int nlocal, const std::vector & f_ref, double epsilon); +void EXPECT_FORCES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector & f_ref, double epsilon); #endif diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index d177b8cefb..df497b0b33 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -358,7 +358,7 @@ TEST(PairStyle, plain) #endif auto pair = lmp->force->pair; - EXPECT_FORCES("init_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, epsilon); ErrorStats stats; @@ -371,7 +371,7 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, epsilon); stats.reset(); @@ -393,7 +393,7 @@ TEST(PairStyle, plain) if (lmp->force->newton_pair == 0) { pair = lmp->force->pair; - EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 3 * epsilon); stats.reset(); @@ -405,7 +405,7 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, epsilon); stats.reset(); @@ -425,7 +425,7 @@ TEST(PairStyle, plain) pair = lmp->force->pair; - EXPECT_FORCES("restart_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("restart_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); @@ -441,7 +441,7 @@ TEST(PairStyle, plain) pair = lmp->force->pair; - EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); @@ -455,7 +455,7 @@ TEST(PairStyle, plain) if (!verbose) ::testing::internal::GetCapturedStdout(); pair = lmp->force->pair; - EXPECT_FORCES("data_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("data_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); @@ -477,7 +477,7 @@ TEST(PairStyle, plain) pair = lmp->force->pair; if (pair->ncoultablebits) epsilon *= 5.0e6; - EXPECT_FORCES("run_forces (r-RESPA)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces (r-RESPA)", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (r-RESPA)", pair->virial, test_config.run_stress, epsilon); stats.reset(); @@ -539,7 +539,7 @@ TEST(PairStyle, omp) auto pair = lmp->force->pair; ErrorStats stats; - EXPECT_FORCES("init_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -551,7 +551,7 @@ TEST(PairStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5* epsilon); + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 5* epsilon); EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -572,7 +572,7 @@ TEST(PairStyle, omp) pair = lmp->force->pair; - EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, epsilon); + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -584,7 +584,7 @@ TEST(PairStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -602,7 +602,7 @@ TEST(PairStyle, omp) pair = lmp->force->pair; - EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, 5 * epsilon); + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, 5 * epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -662,7 +662,7 @@ TEST(PairStyle, kokkos_omp) auto pair = lmp->force->pair; ErrorStats stats; - EXPECT_FORCES("init_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -674,7 +674,7 @@ TEST(PairStyle, kokkos_omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -695,7 +695,7 @@ TEST(PairStyle, kokkos_omp) pair = lmp->force->pair; - EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -707,7 +707,7 @@ TEST(PairStyle, kokkos_omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -725,7 +725,7 @@ TEST(PairStyle, kokkos_omp) pair = lmp->force->pair; - EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, 5 * epsilon); + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, 5 * epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -805,7 +805,7 @@ TEST(PairStyle, gpu) ErrorStats stats; auto pair = lmp->force->pair; - EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -817,7 +817,7 @@ TEST(PairStyle, gpu) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -889,7 +889,7 @@ TEST(PairStyle, intel) ErrorStats stats; auto pair = lmp->force->pair; - EXPECT_FORCES("init_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -901,7 +901,7 @@ TEST(PairStyle, intel) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -963,7 +963,7 @@ TEST(PairStyle, opt) ErrorStats stats; auto pair = lmp->force->pair; - EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -975,7 +975,7 @@ TEST(PairStyle, opt) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_FORCES("run_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); + EXPECT_FORCES("run_forces", lmp->atom, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -992,7 +992,7 @@ TEST(PairStyle, opt) pair = lmp->force->pair; - EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, 5 * epsilon); + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, 5 * epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset();