update unit tests

This commit is contained in:
Axel Kohlmeyer
2021-07-21 00:47:10 -04:00
parent 9615867600
commit f6e9c30818
2 changed files with 19 additions and 5 deletions

View File

@ -162,13 +162,17 @@ TEST(lammps_external, array)
for (int i = 0; i < nlocal; ++i) for (int i = 0; i < nlocal; ++i)
force[i][0] = force[i][1] = force[i][2] = 0.0; force[i][0] = force[i][1] = force[i][2] = 0.0;
lammps_fix_external_set_energy_global(handle, "ext", 0.5); lammps_fix_external_set_energy_global(handle, "ext", 0.5);
double v[6] = {0.5, 0.5, 0.5, 0.0, 0.0, 0.0};
lammps_fix_external_set_virial_global(handle, "ext", v);
lammps_command(handle, "run 5 post no"); lammps_command(handle, "run 5 post no");
double temp = lammps_get_thermo(handle, "temp"); double temp = lammps_get_thermo(handle, "temp");
double pe = lammps_get_thermo(handle, "pe"); double pe = lammps_get_thermo(handle, "pe");
double press = lammps_get_thermo(handle, "press");
output = ::testing::internal::GetCapturedStdout(); output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
EXPECT_DOUBLE_EQ(temp, 4.0 / 525.0); EXPECT_DOUBLE_EQ(temp, 4.0 / 525.0);
EXPECT_DOUBLE_EQ(pe, 1.0 / 16.0); EXPECT_DOUBLE_EQ(pe, 1.0 / 16.0);
EXPECT_DOUBLE_EQ(press, 0.069166666666666668);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
nlocal = lammps_extract_setting(handle, "nlocal"); nlocal = lammps_extract_setting(handle, "nlocal");
@ -176,13 +180,18 @@ TEST(lammps_external, array)
for (int i = 0; i < nlocal; ++i) for (int i = 0; i < nlocal; ++i)
force[i][0] = force[i][1] = force[i][2] = 6.0; force[i][0] = force[i][1] = force[i][2] = 6.0;
lammps_fix_external_set_energy_global(handle, "ext", 1.0); lammps_fix_external_set_energy_global(handle, "ext", 1.0);
v[0] = v[1] = v[2] = 1.0;
v[3] = v[4] = v[5] = 0.0;
lammps_fix_external_set_virial_global(handle, "ext", v);
lammps_command(handle, "run 5 post no"); lammps_command(handle, "run 5 post no");
temp = lammps_get_thermo(handle, "temp"); temp = lammps_get_thermo(handle, "temp");
pe = lammps_get_thermo(handle, "pe"); pe = lammps_get_thermo(handle, "pe");
press = lammps_get_thermo(handle, "press");
output = ::testing::internal::GetCapturedStdout(); output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
EXPECT_DOUBLE_EQ(temp, 1.0 / 30.0); EXPECT_DOUBLE_EQ(temp, 1.0 / 30.0);
EXPECT_DOUBLE_EQ(pe, 1.0 / 8.0); EXPECT_DOUBLE_EQ(pe, 1.0 / 8.0);
EXPECT_DOUBLE_EQ(press, 0.15416666666666667);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lammps_close(handle); lammps_close(handle);

View File

@ -75,7 +75,8 @@ class PythonExternal(unittest.TestCase):
velocity all set 0.1 0.0 -0.1 velocity all set 0.1 0.0 -0.1
fix 1 all nve fix 1 all nve
fix ext all external pf/array 1 fix ext all external pf/array 1
thermo_style custom step temp pe ke fix_modify ext energy yes virial yes
thermo_style custom step temp pe ke press
thermo 5 thermo 5
""" """
lmp.commands_string(basic_system) lmp.commands_string(basic_system)
@ -86,10 +87,12 @@ class PythonExternal(unittest.TestCase):
force[i][1] = 0.0 force[i][1] = 0.0
force[i][2] = 0.0 force[i][2] = 0.0
lmp.fix_external_set_energy_global("ext", 0.5) lmp.fix_external_set_energy_global("ext", 0.5)
lmp.fix_external_set_virial_global("ext",[0.5, 0.5, 0.5, 0.0, 0.0, 0.0])
lmp.command("run 5 post no") lmp.command("run 5 post no")
self.assertAlmostEqual(lmp.get_thermo("temp"),4.0/525.0,14) self.assertAlmostEqual(lmp.get_thermo("temp"),4.0/525.0,14)
self.assertAlmostEqual(lmp.get_thermo("pe"),1.0/16.0,14) self.assertAlmostEqual(lmp.get_thermo("pe"),1.0/16.0,14)
self.assertAlmostEqual(lmp.get_thermo("press"),0.06916666666666667,14)
force = lmp.fix_external_get_force("ext"); force = lmp.fix_external_get_force("ext");
nlocal = lmp.extract_setting("nlocal"); nlocal = lmp.extract_setting("nlocal");
@ -98,9 +101,11 @@ class PythonExternal(unittest.TestCase):
force[i][1] = 6.0 force[i][1] = 6.0
force[i][2] = 6.0 force[i][2] = 6.0
lmp.fix_external_set_energy_global("ext", 1.0) lmp.fix_external_set_energy_global("ext", 1.0)
lmp.fix_external_set_virial_global("ext",[1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
lmp.command("run 5 post no") lmp.command("run 5 post no")
self.assertAlmostEqual(lmp.get_thermo("temp"),1.0/30.0,14) self.assertAlmostEqual(lmp.get_thermo("temp"),1.0/30.0,14)
self.assertAlmostEqual(lmp.get_thermo("pe"),1.0/8.0,14) self.assertAlmostEqual(lmp.get_thermo("pe"),1.0/8.0,14)
self.assertAlmostEqual(lmp.get_thermo("press"),0.15416666666666667,14)
############################## ##############################
if __name__ == "__main__": if __name__ == "__main__":