Add test utility method EXPECT_STRESS()

This commit is contained in:
Richard Berger
2021-11-22 15:24:31 -05:00
parent bb127603ff
commit 3d650a6bf7
8 changed files with 96 additions and 715 deletions

View File

@ -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<coord_t> &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<coord_t> &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");