From 780cf82bb0848573b077cd6c73f76552d2580b4c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Nov 2021 16:23:05 -0500 Subject: [PATCH 01/21] First version of kokkos_omp test variant --- unittest/force-styles/test_pair_style.cpp | 212 ++++++++++++++++++++++ 1 file changed, 212 insertions(+) diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 898fb8e412..bbea62c9c7 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -852,6 +852,218 @@ TEST(PairStyle, omp) if (!verbose) ::testing::internal::GetCapturedStdout(); }; +TEST(PairStyle, kokkos_omp) +{ + if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); + if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", + "-k", "on", "t", "4", "-sf", "kk"}; + + // cannot run dpd styles with more than 1 thread due to using multiple pRNGs + if (utils::strmatch(test_config.pair_style, "^dpd")) args[8] = "1"; + + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + + ::testing::internal::CaptureStdout(); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + + if (!lmp) { + std::cerr << "One or more prerequisite styles with /kk suffix\n" + "are not available in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); + } + + EXPECT_THAT(output, StartsWith("LAMMPS (")); + EXPECT_THAT(output, HasSubstr("Loop time")); + + // abort if running in parallel and not all atoms are local + const int nlocal = lmp->atom->nlocal; + ASSERT_EQ(lmp->atom->natoms, nlocal); + + // relax error a bit for KOKKOS package + double epsilon = 5.0 * test_config.epsilon; + // relax test precision when using pppm and single precision FFTs +#if defined(FFT_SINGLE) + if (lmp->force->kspace && lmp->force->kspace->compute_flag) + if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; +#endif + auto f = lmp->atom->f; + auto tag = lmp->atom->tag; + + const std::vector &f_ref = test_config.init_forces; + ErrorStats stats; + stats.reset(); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; + + auto pair = lmp->force->pair; + auto stress = pair->virial; + stats.reset(); + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + + stats.reset(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; + + if (!verbose) ::testing::internal::CaptureStdout(); + run_lammps(lmp); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + f = lmp->atom->f; + stress = pair->virial; + tag = lmp->atom->tag; + + const std::vector &f_run = test_config.run_forces; + ASSERT_EQ(nlocal + 1, f_run.size()); + stats.reset(); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); + } + if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; + + stress = pair->virial; + stats.reset(); + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + + stats.reset(); + int id = lmp->modify->find_compute("sum"); + double energy = lmp->modify->compute[id]->compute_scalar(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; + + // skip over these tests if newton pair is forced to be on + if (lmp->force->newton_pair == 0) { + + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + f = lmp->atom->f; + tag = lmp->atom->tag; + stats.reset(); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; + + pair = lmp->force->pair; + stress = pair->virial; + stats.reset(); + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + stats.reset(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; + + if (!verbose) ::testing::internal::CaptureStdout(); + run_lammps(lmp); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + f = lmp->atom->f; + tag = lmp->atom->tag; + stats.reset(); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); + } + if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; + + stress = pair->virial; + stats.reset(); + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + + stats.reset(); + id = lmp->modify->find_compute("sum"); + energy = lmp->modify->compute[id]->compute_scalar(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; + } + + if (!verbose) ::testing::internal::CaptureStdout(); + restart_lammps(lmp, test_config, true); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + f = lmp->atom->f; + tag = lmp->atom->tag; + stats.reset(); + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, 5 * epsilon); + } + if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; + + pair = lmp->force->pair; + stress = pair->virial; + stats.reset(); + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + + stats.reset(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, 5 * epsilon); + if (print_stats) std::cerr << "nofdotr_energy stats:" << stats << std::endl; + + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +}; + TEST(PairStyle, gpu) { if (!LAMMPS::is_installed_pkg("GPU")) GTEST_SKIP(); From a354a763bbdc2e7dbd467da6098cf9bf9d30f8eb Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Nov 2021 17:14:52 -0500 Subject: [PATCH 02/21] Fix output capture mismatch --- unittest/formats/test_potential_file_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 7cd61d25a4..7a6e41da79 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -283,7 +283,7 @@ TEST_F(OpenPotentialTest, Sw_conv) { int convert_flag = utils::get_supported_conversions(utils::ENERGY); ASSERT_EQ(convert_flag, utils::METAL2REAL | utils::REAL2METAL); - BEGIN_HIDE_OUTPUT(); + BEGIN_CAPTURE_OUTPUT(); command("units real"); FILE *fp = utils::open_potential("Si.sw", lmp, &convert_flag); auto text = END_CAPTURE_OUTPUT(); From a6ccdd72ec249c56c9841edcb2dbacd32ccde2d8 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 22 Nov 2021 11:49:09 -0500 Subject: [PATCH 03/21] Move platform::rmdir docstring to right location --- src/platform.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/platform.h b/src/platform.h index c079fd2cd1..45f74ee4ea 100644 --- a/src/platform.h +++ b/src/platform.h @@ -277,19 +277,19 @@ namespace platform { int mkdir(const std::string &path); /*! Delete a directory - * - * \param path directory path - * \return -1 if unsuccessful, otherwise >= 0 */ - - int rmdir(const std::string &path); - - /*! Delete a directory and its contents * * Unlike the the ``rmdir()`` or ``_rmdir()`` function of the * C library, this function will check for the contents of the * folder and recurse into any sub-folders, if necessary and * delete all contained folders and their contents before * deleting the folder *path*. + * + * \param path directory path + * \return -1 if unsuccessful, otherwise >= 0 */ + + int rmdir(const std::string &path); + + /*! Delete a file * * \param path path to file to be deleted * \return 0 on success, -1 on error */ From bb127603ffa3c2604e6c2e46b3c16b3cd440e367 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 22 Nov 2021 14:40:51 -0500 Subject: [PATCH 04/21] Use platform::unlink in unittests --- unittest/force-styles/test_angle_style.cpp | 12 ++++-------- unittest/force-styles/test_bond_style.cpp | 12 ++++-------- unittest/force-styles/test_dihedral_style.cpp | 12 ++++-------- unittest/force-styles/test_fix_timestep.cpp | 8 +------- unittest/force-styles/test_improper_style.cpp | 12 ++++-------- unittest/force-styles/test_pair_style.cpp | 13 ++++--------- 6 files changed, 21 insertions(+), 48 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index b4300218b7..368ccb19ff 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index f4c151a394..6eed92082b 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 8cae5d5f7c..a009f5f9a6 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index ac83ff9573..27ad3ce203 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -54,16 +54,10 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".restart"); delete lmp; - lmp = nullptr; } LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool use_respa = false) diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index b6d6b9a06b..4eebe8013e 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index bbea62c9c7..6e4a22152e 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -34,6 +34,7 @@ #include "pair.h" #include "universe.h" #include "utils.h" +#include "platform.h" #include #include @@ -51,18 +52,12 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; - lmp = nullptr; } LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) From 3d650a6bf7bb75ec510e472777542937d981092c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 22 Nov 2021 15:24:31 -0500 Subject: [PATCH 05/21] Add test utility method EXPECT_STRESS() --- unittest/force-styles/test_angle_style.cpp | 105 +------ unittest/force-styles/test_bond_style.cpp | 103 +------ unittest/force-styles/test_dihedral_style.cpp | 104 +------ unittest/force-styles/test_fix_timestep.cpp | 123 +-------- unittest/force-styles/test_improper_style.cpp | 103 +------ unittest/force-styles/test_main.cpp | 15 + unittest/force-styles/test_main.h | 2 + unittest/force-styles/test_pair_style.cpp | 256 ++---------------- 8 files changed, 96 insertions(+), 715 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 368ccb19ff..ca0573840e 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -300,6 +300,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) return; } + TEST(AngleStyle, plain) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); @@ -347,15 +348,7 @@ TEST(AngleStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto angle = lmp->force->angle; - auto stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", angle->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -367,7 +360,6 @@ TEST(AngleStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = angle->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -379,15 +371,7 @@ TEST(AngleStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", angle->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -415,15 +399,7 @@ TEST(AngleStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", angle->virial, test_config.init_stress, 2*epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -435,7 +411,6 @@ TEST(AngleStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = angle->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); @@ -444,15 +419,7 @@ TEST(AngleStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", angle->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -478,15 +445,7 @@ TEST(AngleStyle, plain) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + EXPECT_STRESS("restart_stress", angle->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -508,15 +467,7 @@ TEST(AngleStyle, plain) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + EXPECT_STRESS("data_stress", angle->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -577,16 +528,7 @@ TEST(AngleStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto angle = lmp->force->angle; - auto stress = angle->virial; - - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", angle->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -598,7 +540,6 @@ TEST(AngleStyle, omp) f = lmp->atom->f; tag = lmp->atom->tag; - stress = angle->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -610,15 +551,7 @@ TEST(AngleStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", angle->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -649,15 +582,7 @@ TEST(AngleStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", angle->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -677,15 +602,7 @@ TEST(AngleStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", angle->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 6eed92082b..a8f5ba3044 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -347,15 +347,7 @@ TEST(BondStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto bond = lmp->force->bond; - auto stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", bond->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -367,7 +359,6 @@ TEST(BondStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = bond->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -379,15 +370,7 @@ TEST(BondStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", bond->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -415,15 +398,7 @@ TEST(BondStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", bond->virial, test_config.init_stress, 2 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -435,7 +410,6 @@ TEST(BondStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = bond->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); @@ -444,15 +418,7 @@ TEST(BondStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", bond->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -478,15 +444,7 @@ TEST(BondStyle, plain) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + EXPECT_STRESS("restart_stress", bond->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -508,15 +466,7 @@ TEST(BondStyle, plain) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + EXPECT_STRESS("data_stress", bond->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -577,15 +527,7 @@ TEST(BondStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto bond = lmp->force->bond; - auto stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", bond->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -597,7 +539,6 @@ TEST(BondStyle, omp) f = lmp->atom->f; tag = lmp->atom->tag; - stress = bond->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -609,15 +550,7 @@ TEST(BondStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", bond->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -648,15 +581,7 @@ TEST(BondStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", bond->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -676,15 +601,7 @@ TEST(BondStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", bond->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index a009f5f9a6..e26b066485 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -350,15 +350,7 @@ TEST(DihedralStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto dihedral = lmp->force->dihedral; - auto stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -370,7 +362,6 @@ TEST(DihedralStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = dihedral->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -382,15 +373,7 @@ TEST(DihedralStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", dihedral->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -418,15 +401,7 @@ TEST(DihedralStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -438,7 +413,6 @@ TEST(DihedralStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = dihedral->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); @@ -447,15 +421,7 @@ TEST(DihedralStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", dihedral->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -481,15 +447,7 @@ TEST(DihedralStyle, plain) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + EXPECT_STRESS("restart_stress", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -511,15 +469,7 @@ TEST(DihedralStyle, plain) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + EXPECT_STRESS("data_stress", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -580,16 +530,7 @@ TEST(DihedralStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto dihedral = lmp->force->dihedral; - auto stress = dihedral->virial; - - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", dihedral->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -601,7 +542,6 @@ TEST(DihedralStyle, omp) f = lmp->atom->f; tag = lmp->atom->tag; - stress = dihedral->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -613,15 +553,7 @@ TEST(DihedralStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", dihedral->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -652,15 +584,7 @@ TEST(DihedralStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", dihedral->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -680,15 +604,7 @@ TEST(DihedralStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", dihedral->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index 27ad3ce203..8c6ffeb617 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -37,6 +37,7 @@ #include "universe.h" #include "utils.h" #include "variable.h" +#include "platform.h" #include #include @@ -311,15 +312,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress normal run, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -386,15 +379,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress restart, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -450,15 +435,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress rmass, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -528,16 +505,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) - std::cerr << "run_stress normal run, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -592,15 +560,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress restart, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -656,15 +616,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress rmass, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -763,15 +715,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress normal run, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -838,15 +782,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress restart, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -902,15 +838,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress rmass, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -980,16 +908,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) - std::cerr << "run_stress normal run, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -1044,15 +963,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress restart, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -1108,15 +1019,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress rmass, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 4eebe8013e..749f8be53f 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -341,15 +341,7 @@ TEST(ImproperStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto improper = lmp->force->improper; - auto stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", improper->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -361,7 +353,6 @@ TEST(ImproperStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = improper->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -373,15 +364,7 @@ TEST(ImproperStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", improper->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -409,15 +392,7 @@ TEST(ImproperStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", improper->virial, test_config.init_stress, 2 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -429,7 +404,6 @@ TEST(ImproperStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = improper->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); @@ -438,15 +412,7 @@ TEST(ImproperStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", improper->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -472,15 +438,7 @@ TEST(ImproperStyle, plain) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + EXPECT_STRESS("restart_stress", improper->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -502,15 +460,7 @@ TEST(ImproperStyle, plain) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + EXPECT_STRESS("data_stress", improper->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -571,16 +521,8 @@ TEST(ImproperStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto improper = lmp->force->improper; - auto stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", improper->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -592,7 +534,6 @@ TEST(ImproperStyle, omp) f = lmp->atom->f; tag = lmp->atom->tag; - stress = improper->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -604,15 +545,7 @@ TEST(ImproperStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", improper->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -643,15 +576,7 @@ TEST(ImproperStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", improper->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -671,15 +596,7 @@ TEST(ImproperStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", improper->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index 1ad0b79455..cac385f844 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -15,10 +15,12 @@ #include "pointers.h" #include "test_config.h" #include "test_config_reader.h" +#include "error_stats.h" #include "utils.h" #include "yaml_writer.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "lammps.h" #include #include @@ -27,9 +29,22 @@ #include #include +using LAMMPS_NS::LAMMPS; using LAMMPS_NS::utils::split_words; using LAMMPS_NS::utils::trim; +void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon) +{ + ErrorStats stats; + EXPECT_FP_LE_WITH_EPS(stress[0], expected_stress.xx, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], expected_stress.yy, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], expected_stress.zz, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], expected_stress.xy, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], expected_stress.xz, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], expected_stress.yz, epsilon); + if (print_stats) std::cerr << name << " stats" << stats << std::endl; +} + // common read_yaml_file function bool read_yaml_file(const char *infile, TestConfig &config) { diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index 3a9651e621..4fe0422318 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -34,6 +34,8 @@ void write_yaml_header(class YamlWriter *writer, TestConfig *cfg, const char *ve EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ } while (0); +void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon); + #if defined _WIN32 static const char PATH_SEP = '\\'; #else diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 6e4a22152e..205f709c92 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -370,15 +370,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto pair = lmp->force->pair; - auto stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -391,7 +383,6 @@ TEST(PairStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = pair->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -403,15 +394,7 @@ TEST(PairStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -442,15 +425,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 3 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 3 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -463,7 +438,6 @@ TEST(PairStyle, plain) f = lmp->atom->f; tag = lmp->atom->tag; - stress = pair->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); @@ -472,15 +446,7 @@ TEST(PairStyle, plain) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -509,15 +475,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + EXPECT_STRESS("restart_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -542,15 +500,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -574,15 +524,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + EXPECT_STRESS("data_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -613,15 +555,7 @@ TEST(PairStyle, plain) } if (print_stats) std::cerr << "run_forces stats, r-RESPA:" << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, r-RESPA:" << stats << std::endl; + EXPECT_STRESS("run_stress (r-RESPA)", pair->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -693,15 +627,7 @@ TEST(PairStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto pair = lmp->force->pair; - auto stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -713,7 +639,6 @@ TEST(PairStyle, omp) if (!verbose) ::testing::internal::GetCapturedStdout(); f = lmp->atom->f; - stress = pair->virial; tag = lmp->atom->tag; const std::vector &f_run = test_config.run_forces; @@ -726,15 +651,7 @@ TEST(PairStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -763,15 +680,7 @@ TEST(PairStyle, omp) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -792,15 +701,7 @@ TEST(PairStyle, omp) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -827,15 +728,7 @@ TEST(PairStyle, omp) if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, 5 * epsilon); @@ -905,15 +798,7 @@ TEST(PairStyle, kokkos_omp) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; auto pair = lmp->force->pair; - auto stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -925,7 +810,6 @@ TEST(PairStyle, kokkos_omp) if (!verbose) ::testing::internal::GetCapturedStdout(); f = lmp->atom->f; - stress = pair->virial; tag = lmp->atom->tag; const std::vector &f_run = test_config.run_forces; @@ -938,15 +822,7 @@ TEST(PairStyle, kokkos_omp) } if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -975,15 +851,7 @@ TEST(PairStyle, kokkos_omp) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -1004,15 +872,7 @@ TEST(PairStyle, kokkos_omp) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -1039,15 +899,7 @@ TEST(PairStyle, kokkos_omp) if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, 5 * epsilon); @@ -1138,15 +990,7 @@ TEST(PairStyle, gpu) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; auto pair = lmp->force->pair; - auto stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -1167,15 +1011,7 @@ TEST(PairStyle, gpu) } if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); auto id = lmp->modify->find_compute("sum"); @@ -1257,15 +1093,7 @@ TEST(PairStyle, intel) if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; Pair *pair = lmp->force->pair; - double *stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl; + EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -1278,7 +1106,6 @@ TEST(PairStyle, intel) f = lmp->atom->f; tag = lmp->atom->tag; - stress = pair->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); @@ -1290,15 +1117,7 @@ TEST(PairStyle, intel) } if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; + EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -1370,15 +1189,7 @@ TEST(PairStyle, opt) if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; Pair *pair = lmp->force->pair; - double *stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl; + EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -1391,7 +1202,6 @@ TEST(PairStyle, opt) f = lmp->atom->f; tag = lmp->atom->tag; - stress = pair->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -1402,15 +1212,7 @@ TEST(PairStyle, opt) } if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; + EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -1436,15 +1238,7 @@ TEST(PairStyle, opt) if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, 5 * epsilon); From 62b236a7cd9a8ee9a102189264f31b5c2a11d5a1 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 22 Nov 2021 15:34:23 -0500 Subject: [PATCH 06/21] Use platform::path_join in unittest tree and remove redundant code --- unittest/c-library/test_library_properties.cpp | 12 +++++++----- unittest/c-library/test_library_scatter_gather.cpp | 6 ++++-- unittest/c-library/test_main.h | 6 ------ unittest/force-styles/test_angle_style.cpp | 4 ++-- unittest/force-styles/test_bond_style.cpp | 4 ++-- unittest/force-styles/test_dihedral_style.cpp | 4 ++-- unittest/force-styles/test_fix_timestep.cpp | 2 +- unittest/force-styles/test_improper_style.cpp | 4 ++-- unittest/force-styles/test_main.h | 6 ------ unittest/force-styles/test_pair_style.cpp | 4 ++-- 10 files changed, 22 insertions(+), 30 deletions(-) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 754c6df77f..192c6897e9 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -3,6 +3,7 @@ #include "lammps.h" #include "library.h" #include "lmptype.h" +#include "platform.h" #include #include "gmock/gmock.h" @@ -13,6 +14,7 @@ #define STRINGIFY(val) XSTR(val) #define XSTR(val) #val +using ::LAMMPS_NS::platform::path_join; using ::LAMMPS_NS::tagint; using ::testing::HasSubstr; using ::testing::StartsWith; @@ -82,7 +84,7 @@ TEST_F(LibraryProperties, get_mpi_comm) TEST_F(LibraryProperties, natoms) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -92,7 +94,7 @@ TEST_F(LibraryProperties, natoms) TEST_F(LibraryProperties, thermo) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); @@ -108,7 +110,7 @@ TEST_F(LibraryProperties, thermo) TEST_F(LibraryProperties, box) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); @@ -248,7 +250,7 @@ TEST_F(LibraryProperties, setting) EXPECT_EQ(lammps_extract_setting(lmp, "UNKNOWN"), -1); if (lammps_has_style(lmp, "atom", "full")) { - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); @@ -289,7 +291,7 @@ TEST_F(LibraryProperties, global) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); diff --git a/unittest/c-library/test_library_scatter_gather.cpp b/unittest/c-library/test_library_scatter_gather.cpp index 7ee1cfc9eb..6144516ac2 100644 --- a/unittest/c-library/test_library_scatter_gather.cpp +++ b/unittest/c-library/test_library_scatter_gather.cpp @@ -3,6 +3,7 @@ #include "lammps.h" #include "library.h" #include "lmptype.h" +#include "platform.h" #include #include "gmock/gmock.h" @@ -13,6 +14,7 @@ #define STRINGIFY(val) XSTR(val) #define XSTR(val) #val +using ::LAMMPS_NS::platform::path_join; using ::LAMMPS_NS::bigint; using ::LAMMPS_NS::tagint; using ::testing::HasSubstr; @@ -55,7 +57,7 @@ protected: TEST_F(GatherProperties, gather_bonds_newton_on) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_command(lmp, "newton on on"); lammps_file(lmp, input.c_str()); @@ -95,7 +97,7 @@ TEST_F(GatherProperties, gather_bonds_newton_on) TEST_F(GatherProperties, gather_bonds_newton_off) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_command(lmp, "newton off off"); lammps_file(lmp, input.c_str()); diff --git a/unittest/c-library/test_main.h b/unittest/c-library/test_main.h index 567b913d27..9a719e4b88 100644 --- a/unittest/c-library/test_main.h +++ b/unittest/c-library/test_main.h @@ -25,9 +25,3 @@ extern bool verbose; } while (0); #endif - -#if defined _WIN32 -static const char PATH_SEP = '\\'; -#else -static const char PATH_SEP = '/'; -#endif diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index ca0573840e..002ea58a24 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -108,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("angle_style " + cfg.angle_style); @@ -194,7 +194,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable angle_style index '" + cfg.angle_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &angle_coeff : cfg.angle_coeff) { diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index a8f5ba3044..b913c121e1 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -108,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("bond_style " + cfg.bond_style); @@ -194,7 +194,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable bond_style index '" + cfg.bond_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &bond_coeff : cfg.bond_coeff) { diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index e26b066485..c98f97d260 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -108,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("dihedral_style " + cfg.dihedral_style); @@ -203,7 +203,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable pair_style index 'lj/charmmfsw/coul/charmmfsh 7.0 8.0'"); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &dihedral_coeff : cfg.dihedral_coeff) { diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index 8c6ffeb617..6a8ccdb948 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -99,7 +99,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool use for (auto &pre_command : cfg.pre_commands) command(pre_command); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); lmp->input->file(input_file.c_str()); if (use_respa) command("run_style respa 2 1 bond 1 pair 2"); diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 749f8be53f..cef703d614 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -108,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("improper_style " + cfg.improper_style); @@ -194,7 +194,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable improper_style index '" + cfg.improper_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &improper_coeff : cfg.improper_coeff) { diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index 4fe0422318..f940f7dd3c 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -36,10 +36,4 @@ void write_yaml_header(class YamlWriter *writer, TestConfig *cfg, const char *ve void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon); -#if defined _WIN32 -static const char PATH_SEP = '\\'; -#else -static const char PATH_SEP = '/'; -#endif - #endif diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 205f709c92..3a23b655e9 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -109,7 +109,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("pair_style " + cfg.pair_style); @@ -207,7 +207,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable pair_style index '" + cfg.pair_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &pair_coeff : cfg.pair_coeff) { From 68360b9335d273c9cc82c64745aae3ca54acee85 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 22 Nov 2021 16:27:18 -0500 Subject: [PATCH 07/21] Add test utility method EXPECT_FORCES() --- unittest/force-styles/test_main.cpp | 12 + unittest/force-styles/test_main.h | 3 + unittest/force-styles/test_pair_style.cpp | 329 +++------------------- 3 files changed, 57 insertions(+), 287 deletions(-) diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index cac385f844..6204f60f46 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -32,6 +32,7 @@ using LAMMPS_NS::LAMMPS; using LAMMPS_NS::utils::split_words; using LAMMPS_NS::utils::trim; +using LAMMPS_NS::tagint; void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon) { @@ -45,6 +46,17 @@ 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) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + ErrorStats stats; + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << name << " stats, newton on: " << stats << std::endl; +} + // common read_yaml_file function bool read_yaml_file(const char *infile, TestConfig &config) { diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index f940f7dd3c..cf602b5bb4 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -15,7 +15,9 @@ #define TEST_MAIN_H #include "test_config.h" +#include "lmptype.h" #include +#include extern TestConfig test_config; extern bool print_stats; @@ -35,5 +37,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); #endif diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 3a23b655e9..d177b8cefb 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -356,22 +356,12 @@ TEST(PairStyle, plain) if (lmp->force->kspace && lmp->force->kspace->compute_flag) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto pair = lmp->force->pair; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, epsilon); + ErrorStats stats; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); @@ -381,19 +371,7 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, epsilon); stats.reset(); @@ -413,18 +391,9 @@ TEST(PairStyle, plain) // skip over these tests if newton pair is forced to be on if (lmp->force->newton_pair == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 3 * epsilon); stats.reset(); @@ -436,16 +405,7 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, epsilon); stats.reset(); @@ -463,18 +423,9 @@ TEST(PairStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("restart_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("restart_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); @@ -488,18 +439,9 @@ TEST(PairStyle, plain) restart_lammps(lmp, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); @@ -512,18 +454,8 @@ TEST(PairStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + EXPECT_FORCES("data_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("data_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); @@ -545,16 +477,7 @@ TEST(PairStyle, plain) pair = lmp->force->pair; if (pair->ncoultablebits) epsilon *= 5.0e6; - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, r-RESPA:" << stats << std::endl; - + EXPECT_FORCES("run_forces (r-RESPA)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (r-RESPA)", pair->virial, test_config.run_stress, epsilon); stats.reset(); @@ -613,20 +536,10 @@ TEST(PairStyle, omp) if (lmp->force->kspace && lmp->force->kspace->compute_flag) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; - ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - 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_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -638,19 +551,7 @@ TEST(PairStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5* epsilon); EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -669,17 +570,9 @@ TEST(PairStyle, omp) lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -691,16 +584,7 @@ TEST(PairStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -716,18 +600,9 @@ TEST(PairStyle, omp) restart_lammps(lmp, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, 5 * epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -784,20 +659,10 @@ TEST(PairStyle, kokkos_omp) if (lmp->force->kspace && lmp->force->kspace->compute_flag) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; - ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - 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_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -809,19 +674,7 @@ TEST(PairStyle, kokkos_omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -840,17 +693,9 @@ TEST(PairStyle, kokkos_omp) lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -862,16 +707,7 @@ TEST(PairStyle, kokkos_omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -887,18 +723,9 @@ TEST(PairStyle, kokkos_omp) restart_lammps(lmp, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, 5 * epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -975,21 +802,10 @@ TEST(PairStyle, gpu) Info::has_accelerator_feature("GPU", "precision", "double")) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - const std::vector &f_ref = test_config.init_forces; - const std::vector &f_run = test_config.run_forces; ErrorStats stats; - - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - auto pair = lmp->force->pair; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -1001,16 +817,7 @@ TEST(PairStyle, gpu) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -1079,20 +886,10 @@ TEST(PairStyle, intel) const int nlocal = lmp->atom->nlocal; ASSERT_EQ(lmp->atom->natoms, nlocal); - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; + auto pair = lmp->force->pair; - Pair *pair = lmp->force->pair; + EXPECT_FORCES("init_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -1104,19 +901,7 @@ TEST(PairStyle, intel) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; - + EXPECT_FORCES("run_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -1175,20 +960,10 @@ TEST(PairStyle, opt) if (lmp->force->kspace && lmp->force->kspace->compute_flag) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; + auto pair = lmp->force->pair; - Pair *pair = lmp->force->pair; + EXPECT_FORCES("init_forces (newton off)", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -1200,18 +975,7 @@ TEST(PairStyle, opt) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; - + EXPECT_FORCES("run_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.run_forces, 5 * epsilon); EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -1226,18 +990,9 @@ TEST(PairStyle, opt) restart_lammps(lmp, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + + EXPECT_FORCES("nofdotr_forces", lmp->atom->f, lmp->atom->tag, nlocal, test_config.init_forces, 5 * epsilon); EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); From 946fd6fb5544237fe4732a079b729454f7a0f9dc Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 10:37:37 -0500 Subject: [PATCH 08/21] Update CMake utility function get_lammps_version() With the introduction of LAMMPS_UPDATE, version.h is no longer a single line file. With this change the CMake utility will only process the LAMMPS_VERSION line. Fixes issue #3038 --- cmake/Modules/LAMMPSUtils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 28ad99fa31..943c3d851e 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -25,7 +25,7 @@ function(validate_option name values) endfunction(validate_option) function(get_lammps_version version_header variable) - file(READ ${version_header} line) + file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\1" day "${line}") string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\2" month "${line}") From 615b7ceca285760359ec76ed483474b799bbb729 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 10:58:29 -0500 Subject: [PATCH 09/21] 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(); From 32a53a1ae304a44df2d94d9fc7ca0d32c3eb67d9 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 11:46:33 -0500 Subject: [PATCH 10/21] Use EXPECT_FORCES() in more testers --- unittest/force-styles/test_angle_style.cpp | 128 ++--------------- unittest/force-styles/test_bond_style.cpp | 130 +++--------------- unittest/force-styles/test_dihedral_style.cpp | 130 +++--------------- unittest/force-styles/test_improper_style.cpp | 129 ++--------------- 4 files changed, 61 insertions(+), 456 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 002ea58a24..86050acb37 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -334,20 +334,10 @@ TEST(AngleStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto angle = lmp->force->angle; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", angle->virial, test_config.init_stress, epsilon); stats.reset(); @@ -358,19 +348,7 @@ TEST(AngleStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", angle->virial, test_config.run_stress, epsilon); stats.reset(); @@ -387,18 +365,9 @@ TEST(AngleStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - angle = lmp->force->angle; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", angle->virial, test_config.init_stress, 2*epsilon); stats.reset(); @@ -409,16 +378,7 @@ TEST(AngleStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", angle->virial, test_config.run_stress, epsilon); stats.reset(); @@ -433,18 +393,8 @@ TEST(AngleStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - angle = lmp->force->angle; + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("restart_stress", angle->virial, test_config.init_stress, epsilon); stats.reset(); @@ -455,18 +405,8 @@ TEST(AngleStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - angle = lmp->force->angle; + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("data_stress", angle->virial, test_config.init_stress, epsilon); stats.reset(); @@ -514,20 +454,10 @@ TEST(AngleStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto angle = lmp->force->angle; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", angle->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -538,19 +468,7 @@ TEST(AngleStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", angle->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -570,18 +488,9 @@ TEST(AngleStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - angle = lmp->force->angle; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", angle->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -592,16 +501,7 @@ TEST(AngleStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", angle->virial, test_config.run_stress, 10 * epsilon); stats.reset(); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index b913c121e1..f00e45b0aa 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -333,20 +333,10 @@ TEST(BondStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto bond = lmp->force->bond; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", bond->virial, test_config.init_stress, epsilon); stats.reset(); @@ -357,19 +347,7 @@ TEST(BondStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", bond->virial, test_config.run_stress, epsilon); stats.reset(); @@ -386,18 +364,9 @@ TEST(BondStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - bond = lmp->force->bond; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", bond->virial, test_config.init_stress, 2 * epsilon); stats.reset(); @@ -408,16 +377,7 @@ TEST(BondStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", bond->virial, test_config.run_stress, epsilon); stats.reset(); @@ -432,18 +392,9 @@ TEST(BondStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - bond = lmp->force->bond; + + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("restart_stress", bond->virial, test_config.init_stress, epsilon); stats.reset(); @@ -454,18 +405,9 @@ TEST(BondStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - bond = lmp->force->bond; + + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("data_stress", bond->virial, test_config.init_stress, epsilon); stats.reset(); @@ -513,20 +455,10 @@ TEST(BondStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto bond = lmp->force->bond; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", bond->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -537,19 +469,7 @@ TEST(BondStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", bond->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -569,18 +489,9 @@ TEST(BondStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - bond = lmp->force->bond; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", bond->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -591,16 +502,7 @@ TEST(BondStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", bond->virial, test_config.run_stress, 10 * epsilon); stats.reset(); diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index c98f97d260..e87f2c0f07 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -336,20 +336,10 @@ TEST(DihedralStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto dihedral = lmp->force->dihedral; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); @@ -360,19 +350,7 @@ TEST(DihedralStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", dihedral->virial, test_config.run_stress, epsilon); stats.reset(); @@ -389,18 +367,9 @@ TEST(DihedralStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - dihedral = lmp->force->dihedral; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); @@ -411,16 +380,7 @@ TEST(DihedralStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", dihedral->virial, test_config.run_stress, epsilon); stats.reset(); @@ -435,18 +395,9 @@ TEST(DihedralStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - dihedral = lmp->force->dihedral; + + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("restart_stress", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); @@ -457,18 +408,9 @@ TEST(DihedralStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - dihedral = lmp->force->dihedral; + + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("data_stress", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); @@ -516,20 +458,10 @@ TEST(DihedralStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto dihedral = lmp->force->dihedral; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", dihedral->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -540,19 +472,7 @@ TEST(DihedralStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", dihedral->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -572,18 +492,9 @@ TEST(DihedralStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - dihedral = lmp->force->dihedral; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", dihedral->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -594,16 +505,7 @@ TEST(DihedralStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", dihedral->virial, test_config.run_stress, 10 * epsilon); stats.reset(); diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index cef703d614..9e2a71e6ef 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -327,20 +327,10 @@ TEST(ImproperStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto improper = lmp->force->improper; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", improper->virial, test_config.init_stress, epsilon); stats.reset(); @@ -351,19 +341,7 @@ TEST(ImproperStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", improper->virial, test_config.run_stress, epsilon); stats.reset(); @@ -380,18 +358,9 @@ TEST(ImproperStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - improper = lmp->force->improper; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", improper->virial, test_config.init_stress, 2 * epsilon); stats.reset(); @@ -402,16 +371,7 @@ TEST(ImproperStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", improper->virial, test_config.run_stress, epsilon); stats.reset(); @@ -426,18 +386,9 @@ TEST(ImproperStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - improper = lmp->force->improper; + + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("restart_stress", improper->virial, test_config.init_stress, epsilon); stats.reset(); @@ -448,18 +399,9 @@ TEST(ImproperStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - improper = lmp->force->improper; + + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("data_stress", improper->virial, test_config.init_stress, epsilon); stats.reset(); @@ -507,21 +449,10 @@ TEST(ImproperStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto improper = lmp->force->improper; + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton on)", improper->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -532,19 +463,7 @@ TEST(ImproperStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton on)", improper->virial, test_config.run_stress, 10 * epsilon); stats.reset(); @@ -564,18 +483,9 @@ TEST(ImproperStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - improper = lmp->force->improper; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); EXPECT_STRESS("init_stress (newton off)", improper->virial, test_config.init_stress, 10 * epsilon); stats.reset(); @@ -586,16 +496,7 @@ TEST(ImproperStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); EXPECT_STRESS("run_stress (newton off)", improper->virial, test_config.run_stress, 10 * epsilon); stats.reset(); From 073b586eeee1a703b9bd222fb951cb624500c3c2 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 12:21:27 -0500 Subject: [PATCH 11/21] Add EXPECT_POSITIONS() and EXPECT_VELOCITIES() test utils --- unittest/force-styles/test_fix_timestep.cpp | 267 ++------------------ unittest/force-styles/test_main.cpp | 30 ++- unittest/force-styles/test_main.h | 2 + 3 files changed, 55 insertions(+), 244 deletions(-) diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index 6a8ccdb948..6d91231d74 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -282,29 +282,10 @@ TEST(FixTimestep, plain) double epsilon = test_config.epsilon; - auto tag = lmp->atom->tag; - auto x = lmp->atom->x; - auto v = lmp->atom->v; ErrorStats stats; - stats.reset(); - const std::vector &x_ref = test_config.run_pos; - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, verlet: " << stats << std::endl; - const std::vector &v_ref = test_config.run_vel; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, verlet: " << stats << std::endl; + 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); int ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -352,26 +333,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, false, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, verlet: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, verlet: " << stats << std::endl; + 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); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -408,26 +371,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, true, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, verlet: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, verlet)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -478,26 +423,8 @@ TEST(FixTimestep, plain) // lower required precision by two orders of magnitude to accommodate respa epsilon *= 100.0; - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, respa: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (normal run, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (normal run, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -533,26 +460,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, false, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, respa: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (restart, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (restart, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -589,26 +498,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, true, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, respa: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -685,29 +576,10 @@ TEST(FixTimestep, omp) double epsilon = test_config.epsilon; - auto tag = lmp->atom->tag; - auto x = lmp->atom->x; - auto v = lmp->atom->v; ErrorStats stats; - stats.reset(); - const std::vector &x_ref = test_config.run_pos; - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, verlet: " << stats << std::endl; - const std::vector &v_ref = test_config.run_vel; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, verlet: " << stats << std::endl; + 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); int ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -755,26 +627,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, false, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, verlet: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, verlet: " << stats << std::endl; + 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); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -811,26 +665,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, true, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, verlet: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, verlet)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -880,27 +716,8 @@ TEST(FixTimestep, omp) // lower required precision by two orders of magnitude to accommodate respa epsilon *= 100.0; - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, respa: " << stats << std::endl; - printf("x1\n"); - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (normal run, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (normal run, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -936,26 +753,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, false, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, respa: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (restart, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (restart, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -992,26 +791,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, true, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, respa: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index f0cba47287..5f469f9f01 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -59,7 +59,35 @@ void EXPECT_FORCES(const std::string & name, Atom * atom, const std::vector & x_ref, double epsilon) { + double ** x = atom->x; + tagint * tag = atom->tag; + const int nlocal = atom->nlocal; + ASSERT_EQ(nlocal + 1, x_ref.size()); + ErrorStats stats; + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << name << " stats" << stats << std::endl; +} + +void EXPECT_VELOCITIES(const std::string & name, Atom * atom, const std::vector & v_ref, double epsilon) { + double ** v = atom->v; + tagint * tag = atom->tag; + const int nlocal = atom->nlocal; + ASSERT_EQ(nlocal + 1, v_ref.size()); + ErrorStats stats; + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << name << " stats" << stats << std::endl; } // common read_yaml_file function diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index 6e08235eae..ff373e5174 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -39,5 +39,7 @@ void write_yaml_header(class YamlWriter *writer, TestConfig *cfg, const char *ve void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon); void EXPECT_FORCES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector & f_ref, double epsilon); +void EXPECT_POSITIONS(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector & x_ref, double epsilon); +void EXPECT_VELOCITIES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector & v_ref, double epsilon); #endif From 51c627df767cf22c5a3a25cb86096cbabb86cc13 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 12:22:01 -0500 Subject: [PATCH 12/21] Add SCOPED_TRACE for better test error messages --- unittest/force-styles/test_main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index 5f469f9f01..b4271975e4 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -38,6 +38,7 @@ using LAMMPS_NS::tagint; void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon) { + SCOPED_TRACE("EXPECT_STRESS: " + name); ErrorStats stats; EXPECT_FP_LE_WITH_EPS(stress[0], expected_stress.xx, epsilon); EXPECT_FP_LE_WITH_EPS(stress[1], expected_stress.yy, epsilon); @@ -49,6 +50,7 @@ void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & e } void EXPECT_FORCES(const std::string & name, Atom * atom, const std::vector & f_ref, double epsilon) { + SCOPED_TRACE("EXPECT_FORCES: " + name); double ** f = atom->f; tagint * tag = atom->tag; const int nlocal = atom->nlocal; @@ -63,6 +65,7 @@ void EXPECT_FORCES(const std::string & name, Atom * atom, const std::vector & x_ref, double epsilon) { + SCOPED_TRACE("EXPECT_POSITIONS: " + name); double ** x = atom->x; tagint * tag = atom->tag; const int nlocal = atom->nlocal; @@ -77,6 +80,7 @@ void EXPECT_POSITIONS(const std::string & name, Atom * atom, const std::vector & v_ref, double epsilon) { + SCOPED_TRACE("EXPECT_VELOCITIES: " + name); double ** v = atom->v; tagint * tag = atom->tag; const int nlocal = atom->nlocal; From b603346a0d2705d2049e1895197228a1d3e86b7f Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 13:56:19 -0500 Subject: [PATCH 13/21] Skip kspace-pppm_ad test for kokkos_omp --- unittest/force-styles/tests/kspace-pppm_ad.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/kspace-pppm_ad.yaml b/unittest/force-styles/tests/kspace-pppm_ad.yaml index 5eb711c089..0f77e7b208 100644 --- a/unittest/force-styles/tests/kspace-pppm_ad.yaml +++ b/unittest/force-styles/tests/kspace-pppm_ad.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:29 2021 epsilon: 7.5e-14 -skip_tests: gpu +skip_tests: gpu kokkos_omp prerequisites: ! | atom full pair coul/long From d365cc7dfc2612ef3eb030d38e275a96d669973e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 13:57:53 -0500 Subject: [PATCH 14/21] Add missing destroy_kokkos() calls in pair_lj_gromacs_kokkos.cpp --- src/KOKKOS/pair_lj_gromacs_kokkos.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp index 0764a35fac..4647b14ade 100644 --- a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp +++ b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp @@ -61,6 +61,8 @@ PairLJGromacsKokkos::~PairLJGromacsKokkos() memoryKK->destroy_kokkos(k_eatom,eatom); memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->destroy_kokkos(k_cutsq,cutsq); + memoryKK->destroy_kokkos(k_cut_inner,cut_inner); + memoryKK->destroy_kokkos(k_cut_inner_sq,cut_inner_sq); } } From 2f6bf29adf94aa09fb81eb3194f2ce216d93af42 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 14:05:58 -0500 Subject: [PATCH 15/21] Fixup kokkos_omp test for dpd --- unittest/force-styles/test_pair_style.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index df497b0b33..4b1175455f 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -625,7 +625,7 @@ TEST(PairStyle, kokkos_omp) "-k", "on", "t", "4", "-sf", "kk"}; // cannot run dpd styles with more than 1 thread due to using multiple pRNGs - if (utils::strmatch(test_config.pair_style, "^dpd")) args[8] = "1"; + if (utils::strmatch(test_config.pair_style, "^dpd")) args[9] = "1"; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); From 0b87039fbb86ca075dad765e17bf4a7c9a37d93b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 14:28:31 -0500 Subject: [PATCH 16/21] Skip MolPairStyle:hybrid-scaled test for kokkos_omp --- unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml b/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml index e9a036b545..814f3780fe 100644 --- a/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml +++ b/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml @@ -2,7 +2,7 @@ lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:07 2021 epsilon: 5e-14 -skip_tests: gpu intel omp +skip_tests: gpu intel omp kokkos_omp prerequisites: ! | atom full pair lj/cut From 9517467113be71888e9e9e40990aaa6b9f833612 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 14:56:35 -0500 Subject: [PATCH 17/21] Add missing KOKKOS suffix in PairTersoffZBLKokkos --- src/KOKKOS/pair_tersoff_zbl_kokkos.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp index f2e6752f07..47eb0e200f 100644 --- a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp @@ -31,6 +31,7 @@ #include "memory_kokkos.h" #include "error.h" #include "atom_masks.h" +#include "suffix.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -44,6 +45,7 @@ template PairTersoffZBLKokkos::PairTersoffZBLKokkos(LAMMPS *lmp) : PairTersoffZBL(lmp) { respa_enable = 0; + suffix_flag |= Suffix::KOKKOS; kokkosable = 1; atomKK = (AtomKokkos *) atom; From 2c5441257ecadd17aacb926dc239e4f19dd91c08 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Nov 2021 15:03:48 -0500 Subject: [PATCH 18/21] Disable tersoff with shift flag tests for kokkos_omp --- .../force-styles/tests/manybody-pair-tersoff_mod_shift.yaml | 2 +- unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml | 2 +- .../force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml b/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml index a9390a4fd3..34706e4b25 100644 --- a/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml +++ b/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:20 2021 epsilon: 5e-11 -skip_tests: gpu intel +skip_tests: gpu intel kokkos_omp prerequisites: ! | pair tersoff/mod pre_commands: ! | diff --git a/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml b/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml index 9808d348a7..3d98f221b0 100644 --- a/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml +++ b/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:20 2021 epsilon: 5e-13 -skip_tests: gpu intel +skip_tests: gpu intel kokkos_omp prerequisites: ! | pair tersoff pre_commands: ! | diff --git a/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml b/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml index 69b63cf259..1bf994e7b2 100644 --- a/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml +++ b/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:21 2021 epsilon: 5e-11 -skip_tests: gpu intel +skip_tests: gpu intel kokkos_omp prerequisites: ! | pair tersoff/zbl pre_commands: ! | From 735d6926a1a52ef94ea778b2fbb8d222818d0974 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 27 Jan 2022 14:36:38 -0500 Subject: [PATCH 19/21] Update to KK tersoff styles for consistent nofdotr Inspired by f82096c46ccf7e284c6f3d1c3b8af2eaa2bd4e1d --- src/KOKKOS/pair_tersoff_kokkos.cpp | 29 ++++++++++++++++---------- src/KOKKOS/pair_tersoff_mod_kokkos.cpp | 29 ++++++++++++++++---------- src/KOKKOS/pair_tersoff_zbl_kokkos.cpp | 29 ++++++++++++++++---------- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/src/KOKKOS/pair_tersoff_kokkos.cpp b/src/KOKKOS/pair_tersoff_kokkos.cpp index 2aa58f2415..8700bd356f 100644 --- a/src/KOKKOS/pair_tersoff_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_kokkos.cpp @@ -171,7 +171,7 @@ void PairTersoffKokkos::compute(int eflag_in, int vflag_in) memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); d_eatom = k_eatom.view(); } - if (vflag_atom) { + if (vflag_either) { memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); d_vatom = k_vatom.view(); @@ -271,7 +271,7 @@ void PairTersoffKokkos::compute(int eflag_in, int vflag_in) k_eatom.template sync(); } - if (vflag_atom) { + if (vflag_either) { if (need_dup) Kokkos::Experimental::contribute(d_vatom, dup_vatom); k_vatom.template modify(); @@ -480,7 +480,7 @@ void PairTersoffKokkos::operator()(TagPairTersoffComputeHalf::operator()(TagPairTersoffComputeFullA::operator()(TagPairTersoffComputeFullB::v_tally3(EV_FLOAT &ev, const int &i, const i F_FLOAT v[6]; - v[0] = THIRD * (drij[0]*fj[0] + drik[0]*fk[0]); - v[1] = THIRD * (drij[1]*fj[1] + drik[1]*fk[1]); - v[2] = THIRD * (drij[2]*fj[2] + drik[2]*fk[2]); - v[3] = THIRD * (drij[0]*fj[1] + drik[0]*fk[1]); - v[4] = THIRD * (drij[0]*fj[2] + drik[0]*fk[2]); - v[5] = THIRD * (drij[1]*fj[2] + drik[1]*fk[2]); + v[0] = (drij[0]*fj[0] + drik[0]*fk[0]); + v[1] = (drij[1]*fj[1] + drik[1]*fk[1]); + v[2] = (drij[2]*fj[2] + drik[2]*fk[2]); + v[3] = (drij[0]*fj[1] + drik[0]*fk[1]); + v[4] = (drij[0]*fj[2] + drik[0]*fk[2]); + v[5] = (drij[1]*fj[2] + drik[1]*fk[2]); if (vflag_global) { ev.v[0] += v[0]; @@ -1233,6 +1233,13 @@ void PairTersoffKokkos::v_tally3(EV_FLOAT &ev, const int &i, const i } if (vflag_atom) { + v[0] *= THIRD; + v[1] *= THIRD; + v[2] *= THIRD; + v[3] *= THIRD; + v[4] *= THIRD; + v[5] *= THIRD; + a_vatom(i,0) += v[0]; a_vatom(i,1) += v[1]; a_vatom(i,2) += v[2]; a_vatom(i,3) += v[3]; a_vatom(i,4) += v[4]; a_vatom(i,5) += v[5]; if (NEIGHFLAG != FULL) { diff --git a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp index 82d0fa4628..51800cd1a1 100644 --- a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp @@ -171,7 +171,7 @@ void PairTersoffMODKokkos::compute(int eflag_in, int vflag_in) memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); d_eatom = k_eatom.view(); } - if (vflag_atom) { + if (vflag_either) { memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); d_vatom = k_vatom.view(); @@ -271,7 +271,7 @@ void PairTersoffMODKokkos::compute(int eflag_in, int vflag_in) k_eatom.template sync(); } - if (vflag_atom) { + if (vflag_either) { if (need_dup) Kokkos::Experimental::contribute(d_vatom, dup_vatom); k_vatom.template modify(); @@ -480,7 +480,7 @@ void PairTersoffMODKokkos::operator()(TagPairTersoffMODComputeHalf::operator()(TagPairTersoffMODComputeFullA< f_y += fi[1]; f_z += fi[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrij[3], delrik[3]; delrij[0] = -delx1; delrij[1] = -dely1; delrij[2] = -delz1; delrik[0] = -delx2; delrik[1] = -dely2; delrik[2] = -delz2; @@ -764,7 +764,7 @@ void PairTersoffMODKokkos::operator()(TagPairTersoffMODComputeFullB< f_y += fj[1]; f_z += fj[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrji[3], delrjk[3]; delrji[0] = -delx1; delrji[1] = -dely1; delrji[2] = -delz1; delrjk[0] = -delx2; delrjk[1] = -dely2; delrjk[2] = -delz2; @@ -1219,12 +1219,12 @@ void PairTersoffMODKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons F_FLOAT v[6]; - v[0] = THIRD * (drij[0]*fj[0] + drik[0]*fk[0]); - v[1] = THIRD * (drij[1]*fj[1] + drik[1]*fk[1]); - v[2] = THIRD * (drij[2]*fj[2] + drik[2]*fk[2]); - v[3] = THIRD * (drij[0]*fj[1] + drik[0]*fk[1]); - v[4] = THIRD * (drij[0]*fj[2] + drik[0]*fk[2]); - v[5] = THIRD * (drij[1]*fj[2] + drik[1]*fk[2]); + v[0] = (drij[0]*fj[0] + drik[0]*fk[0]); + v[1] = (drij[1]*fj[1] + drik[1]*fk[1]); + v[2] = (drij[2]*fj[2] + drik[2]*fk[2]); + v[3] = (drij[0]*fj[1] + drik[0]*fk[1]); + v[4] = (drij[0]*fj[2] + drik[0]*fk[2]); + v[5] = (drij[1]*fj[2] + drik[1]*fk[2]); if (vflag_global) { ev.v[0] += v[0]; @@ -1236,6 +1236,13 @@ void PairTersoffMODKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons } if (vflag_atom) { + v[0] *= THIRD; + v[1] *= THIRD; + v[2] *= THIRD; + v[3] *= THIRD; + v[4] *= THIRD; + v[5] *= THIRD; + a_vatom(i,0) += v[0]; a_vatom(i,1) += v[1]; a_vatom(i,2) += v[2]; a_vatom(i,3) += v[3]; a_vatom(i,4) += v[4]; a_vatom(i,5) += v[5]; if (NEIGHFLAG != FULL) { diff --git a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp index 47eb0e200f..3f9beb6041 100644 --- a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp @@ -187,7 +187,7 @@ void PairTersoffZBLKokkos::compute(int eflag_in, int vflag_in) memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); d_eatom = k_eatom.view(); } - if (vflag_atom) { + if (vflag_either) { memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); d_vatom = k_vatom.view(); @@ -287,7 +287,7 @@ void PairTersoffZBLKokkos::compute(int eflag_in, int vflag_in) k_eatom.template sync(); } - if (vflag_atom) { + if (vflag_either) { if (need_dup) Kokkos::Experimental::contribute(d_vatom, dup_vatom); k_vatom.template modify(); @@ -526,7 +526,7 @@ void PairTersoffZBLKokkos::operator()(TagPairTersoffZBLComputeHalf::operator()(TagPairTersoffZBLComputeFullA< f_y += fi[1]; f_z += fi[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrij[3], delrik[3]; delrij[0] = -delx1; delrij[1] = -dely1; delrij[2] = -delz1; delrik[0] = -delx2; delrik[1] = -dely2; delrik[2] = -delz2; @@ -840,7 +840,7 @@ void PairTersoffZBLKokkos::operator()(TagPairTersoffZBLComputeFullB< f_y += fj[1]; f_z += fj[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrji[3], delrjk[3]; delrji[0] = -delx1; delrji[1] = -dely1; delrji[2] = -delz1; delrjk[0] = -delx2; delrjk[1] = -dely2; delrjk[2] = -delz2; @@ -1315,12 +1315,12 @@ void PairTersoffZBLKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons F_FLOAT v[6]; - v[0] = THIRD * (drij[0]*fj[0] + drik[0]*fk[0]); - v[1] = THIRD * (drij[1]*fj[1] + drik[1]*fk[1]); - v[2] = THIRD * (drij[2]*fj[2] + drik[2]*fk[2]); - v[3] = THIRD * (drij[0]*fj[1] + drik[0]*fk[1]); - v[4] = THIRD * (drij[0]*fj[2] + drik[0]*fk[2]); - v[5] = THIRD * (drij[1]*fj[2] + drik[1]*fk[2]); + v[0] = (drij[0]*fj[0] + drik[0]*fk[0]); + v[1] = (drij[1]*fj[1] + drik[1]*fk[1]); + v[2] = (drij[2]*fj[2] + drik[2]*fk[2]); + v[3] = (drij[0]*fj[1] + drik[0]*fk[1]); + v[4] = (drij[0]*fj[2] + drik[0]*fk[2]); + v[5] = (drij[1]*fj[2] + drik[1]*fk[2]); if (vflag_global) { ev.v[0] += v[0]; @@ -1332,6 +1332,13 @@ void PairTersoffZBLKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons } if (vflag_atom) { + v[0] *= THIRD; + v[1] *= THIRD; + v[2] *= THIRD; + v[3] *= THIRD; + v[4] *= THIRD; + v[5] *= THIRD; + a_vatom(i,0) += v[0]; a_vatom(i,1) += v[1]; a_vatom(i,2) += v[2]; a_vatom(i,3) += v[3]; a_vatom(i,4) += v[4]; a_vatom(i,5) += v[5]; if (NEIGHFLAG != FULL) { From 265588d480cbb92ea9eed6fc3ff5fb3bdada6214 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 27 Jan 2022 16:14:46 -0500 Subject: [PATCH 20/21] Reduce differences between original pair hybrid and kokkos variant --- src/KOKKOS/pair_hybrid_kokkos.cpp | 42 +++++++++++--- src/KOKKOS/pair_hybrid_overlay_kokkos.cpp | 69 ++++++++++++++++++++--- src/KOKKOS/pair_hybrid_overlay_kokkos.h | 3 + 3 files changed, 97 insertions(+), 17 deletions(-) diff --git a/src/KOKKOS/pair_hybrid_kokkos.cpp b/src/KOKKOS/pair_hybrid_kokkos.cpp index b1d3e0259f..00abc36768 100644 --- a/src/KOKKOS/pair_hybrid_kokkos.cpp +++ b/src/KOKKOS/pair_hybrid_kokkos.cpp @@ -1,4 +1,5 @@ // clang-format off + /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -52,10 +53,10 @@ PairHybridKokkos::~PairHybridKokkos() /* ---------------------------------------------------------------------- call each sub-style's compute() or compute_outer() function accumulate sub-style global/peratom energy/virial in hybrid - for global vflag = 1: + for global vflag = VIRIAL_PAIR: each sub-style computes own virial[6] sum sub-style virial[6] to hybrid's virial[6] - for global vflag = 2: + for global vflag = VIRIAL_FDOTR: call sub-style with adjusted vflag to prevent it calling virial_fdotr_compute() hybrid calls virial_fdotr_compute() on final accumulated f @@ -65,24 +66,25 @@ void PairHybridKokkos::compute(int eflag, int vflag) { int i,j,m,n; - // if no_virial_fdotr_compute is set and global component of - // incoming vflag = VIRIAL_FDOTR, then - // reset vflag as if global component were VIRIAL_PAIR + // check if no_virial_fdotr_compute is set and global component of + // incoming vflag = VIRIAL_FDOTR + // if so, reset vflag as if global component were VIRIAL_PAIR // necessary since one or more sub-styles cannot compute virial as F dot r int neighflag = lmp->kokkos->neighflag; if (neighflag == FULL) no_virial_fdotr_compute = 1; - if (no_virial_fdotr_compute && vflag & VIRIAL_FDOTR) vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); + if (no_virial_fdotr_compute && (vflag & VIRIAL_FDOTR)) + vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); ev_init(eflag,vflag); // check if global component of incoming vflag = VIRIAL_FDOTR - // if so, reset vflag passed to substyle as if it were VIRIAL_NONE + // if so, reset vflag passed to substyle so VIRIAL_FDOTR is turned off // necessary so substyle will not invoke virial_fdotr_compute() int vflag_substyle; - if (vflag & VIRIAL_FDOTR) vflag_substyle = VIRIAL_NONE | (vflag & ~VIRIAL_FDOTR); + if (vflag & VIRIAL_FDOTR) vflag_substyle = vflag & ~VIRIAL_FDOTR; else vflag_substyle = vflag; double *saved_special = save_special(); @@ -140,6 +142,30 @@ void PairHybridKokkos::compute(int eflag, int vflag) for (j = 0; j < 6; j++) vatom[i][j] += vatom_substyle[i][j]; } + + // substyles may be CENTROID_SAME or CENTROID_AVAIL + + if (cvflag_atom) { + n = atom->nlocal; + if (force->newton_pair) n += atom->nghost; + if (styles[m]->centroidstressflag == CENTROID_AVAIL) { + double **cvatom_substyle = styles[m]->cvatom; + for (i = 0; i < n; i++) + for (j = 0; j < 9; j++) + cvatom[i][j] += cvatom_substyle[i][j]; + } else { + double **vatom_substyle = styles[m]->vatom; + for (i = 0; i < n; i++) { + for (j = 0; j < 6; j++) { + cvatom[i][j] += vatom_substyle[i][j]; + } + for (j = 6; j < 9; j++) { + cvatom[i][j] += vatom_substyle[i][j-3]; + } + } + } + } + } delete [] saved_special; diff --git a/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp b/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp index c815e2ad72..7b0e79075d 100644 --- a/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp +++ b/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp @@ -13,12 +13,11 @@ ------------------------------------------------------------------------- */ #include "pair_hybrid_overlay_kokkos.h" -#include -#include + #include "atom.h" -#include "force.h" #include "error.h" +#include using namespace LAMMPS_NS; @@ -43,7 +42,7 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) // 4th arg = pair sub-style index if name used multiple times // allow for "none" as valid sub-style name - int multflag; + int multflag = 0; int m; for (m = 0; m < nstyles; m++) { @@ -52,10 +51,7 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) if (multiple[m]) { multflag = 1; if (narg < 4) error->all(FLERR,"Incorrect args for pair coefficients"); - if (!isdigit(arg[3][0])) - error->all(FLERR,"Incorrect args for pair coefficients"); - int index = utils::inumeric(FLERR,arg[3],false,lmp); - if (index == multiple[m]) break; + if (multiple[m] == utils::inumeric(FLERR,arg[3],false,lmp)) break; else continue; } else break; } @@ -74,9 +70,15 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) arg[2+multflag] = arg[1]; arg[1+multflag] = arg[0]; + // ensure that one_coeff flag is honored + + if (!none && styles[m]->one_coeff) + if ((strcmp(arg[0],"*") != 0) || (strcmp(arg[1],"*") != 0)) + error->all(FLERR,"Incorrect args for pair coefficients"); + // invoke sub-style coeff() starting with 1st remaining arg - if (!none) styles[m]->coeff(narg-1-multflag,&arg[1+multflag]); + if (!none) styles[m]->coeff(narg-1-multflag,arg+1+multflag); // set setflag and which type pairs map to which sub-style // if sub-style is none: set hybrid subflag, wipe out map @@ -104,3 +106,52 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } + + +/* ---------------------------------------------------------------------- + we need to handle Pair::svector special for hybrid/overlay +------------------------------------------------------------------------- */ + +void PairHybridOverlayKokkos::init_svector() +{ + // single_extra = list all sub-style single_extra + // allocate svector + + single_extra = 0; + for (int m = 0; m < nstyles; m++) + single_extra += styles[m]->single_extra; + + if (single_extra) { + delete [] svector; + svector = new double[single_extra]; + } +} + +/* ---------------------------------------------------------------------- + we need to handle Pair::svector special for hybrid/overlay +------------------------------------------------------------------------- */ + +void PairHybridOverlayKokkos::copy_svector(int itype, int jtype) +{ + int n=0; + Pair *this_style = nullptr; + + // fill svector array. + // copy data from active styles and use 0.0 for inactive ones + for (int m = 0; m < nstyles; m++) { + for (int k = 0; k < nmap[itype][jtype]; ++k) { + if (m == map[itype][jtype][k]) { + this_style = styles[m]; + } else { + this_style = nullptr; + } + } + for (int l = 0; l < styles[m]->single_extra; ++l) { + if (this_style) { + svector[n++] = this_style->svector[l]; + } else { + svector[n++] = 0.0; + } + } + } +} diff --git a/src/KOKKOS/pair_hybrid_overlay_kokkos.h b/src/KOKKOS/pair_hybrid_overlay_kokkos.h index fc8efd038b..795c7e40ff 100644 --- a/src/KOKKOS/pair_hybrid_overlay_kokkos.h +++ b/src/KOKKOS/pair_hybrid_overlay_kokkos.h @@ -30,6 +30,9 @@ class PairHybridOverlayKokkos : public PairHybridKokkos { PairHybridOverlayKokkos(class LAMMPS *); virtual ~PairHybridOverlayKokkos() {} void coeff(int, char **); + + void init_svector() override; + void copy_svector(int, int) override; }; } From 35a4c0f5010e877385b1fa0deb610681d4d66736 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 7 Feb 2022 16:15:32 -0500 Subject: [PATCH 21/21] skip tests that fail with Kokkos+OpenMP --- unittest/force-styles/tests/mol-pair-coul_dsf.yaml | 1 + unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml | 1 + unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml | 2 +- unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml | 1 + unittest/force-styles/tests/mol-pair-table.yaml | 1 + unittest/force-styles/tests/mol-pair-zbl.yaml | 1 + 6 files changed, 6 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/mol-pair-coul_dsf.yaml b/unittest/force-styles/tests/mol-pair-coul_dsf.yaml index 9bc59e4431..5e47bd6c79 100644 --- a/unittest/force-styles/tests/mol-pair-coul_dsf.yaml +++ b/unittest/force-styles/tests/mol-pair-coul_dsf.yaml @@ -2,6 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:42 2021 epsilon: 1e-12 +skip_tests: kokkos_omp prerequisites: ! | atom full pair coul/dsf diff --git a/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml b/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml index 68f23ae526..6559e2d53c 100644 --- a/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml +++ b/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml @@ -1,6 +1,7 @@ --- lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:07 2021 +skip_tests: kokkos_omp epsilon: 5e-13 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml b/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml index 59a5098238..c46ee40b93 100644 --- a/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml +++ b/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml @@ -2,7 +2,7 @@ lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:08 2021 epsilon: 5e-14 -skip_tests: gpu +skip_tests: gpu kokkos_omp prerequisites: ! | atom full pair lj/cut diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml index 109e347449..1e3e4249a6 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml @@ -1,6 +1,7 @@ --- lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:48 2021 +skip_tests: kokkos_omp epsilon: 8e-14 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-table.yaml b/unittest/force-styles/tests/mol-pair-table.yaml index fb9e647677..1b75119519 100644 --- a/unittest/force-styles/tests/mol-pair-table.yaml +++ b/unittest/force-styles/tests/mol-pair-table.yaml @@ -2,6 +2,7 @@ lammps_version: 10 Feb 2021 tags: slow date_generated: Fri Feb 26 23:08:56 2021 +skip_tests: kokkos_omp epsilon: 5e-14 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-zbl.yaml b/unittest/force-styles/tests/mol-pair-zbl.yaml index 113072816e..2f29826e67 100644 --- a/unittest/force-styles/tests/mol-pair-zbl.yaml +++ b/unittest/force-styles/tests/mol-pair-zbl.yaml @@ -2,6 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:57 2021 epsilon: 1e-12 +skip_tests: kokkos_omp prerequisites: ! | atom full pair zbl