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();