add unit tests for c-library interface and plain python module
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#define STRINGIFY(val) XSTR(val)
|
||||
#define XSTR(val) #val
|
||||
|
||||
using ::LAMMPS_NS::bigint;
|
||||
using ::LAMMPS_NS::tagint;
|
||||
using ::LAMMPS_NS::platform::path_join;
|
||||
using ::testing::HasSubstr;
|
||||
@ -93,6 +94,9 @@ TEST_F(LibraryProperties, natoms)
|
||||
|
||||
TEST_F(LibraryProperties, thermo)
|
||||
{
|
||||
bigint bval = *(bigint *)lammps_last_thermo(lmp, "step", 0);
|
||||
EXPECT_EQ(bval, -1);
|
||||
|
||||
if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP();
|
||||
std::string input = path_join(INPUT_DIR, "in.fourmol");
|
||||
::testing::internal::CaptureStdout();
|
||||
@ -105,6 +109,59 @@ TEST_F(LibraryProperties, thermo)
|
||||
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3375.0);
|
||||
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695);
|
||||
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0);
|
||||
|
||||
bval = *(bigint *)lammps_last_thermo(lmp, "step", 0);
|
||||
EXPECT_EQ(bval, 2);
|
||||
int ival = *(int *)lammps_last_thermo(lmp, "num", 0);
|
||||
EXPECT_EQ(ival, 6);
|
||||
|
||||
const char *key = (const char *)lammps_last_thermo(lmp, "keyword", 0);
|
||||
EXPECT_THAT(key, StrEq("Step"));
|
||||
ival = *(int *)lammps_last_thermo(lmp, "type", 0);
|
||||
#if defined(LAMMPS_SMALLSMALL)
|
||||
EXPECT_EQ(ival, LAMMPS_INT);
|
||||
ival = *(int *)lammps_last_thermo(lmp, "data", 0);
|
||||
EXPECT_EQ(ival, 2);
|
||||
#else
|
||||
EXPECT_EQ(ival, LAMMPS_INT64);
|
||||
bval = *(bigint *)lammps_last_thermo(lmp, "data", 0);
|
||||
EXPECT_EQ(bval, 2);
|
||||
#endif
|
||||
|
||||
key = (const char *)lammps_last_thermo(lmp, "keyword", 1);
|
||||
EXPECT_THAT(key, StrEq("Temp"));
|
||||
ival = *(int *)lammps_last_thermo(lmp, "type", 1);
|
||||
EXPECT_EQ(ival, LAMMPS_DOUBLE);
|
||||
double dval = *(double *)lammps_last_thermo(lmp, "data", 1);
|
||||
EXPECT_DOUBLE_EQ(dval, 28.042780385852982);
|
||||
|
||||
key = (const char *)lammps_last_thermo(lmp, "keyword", 2);
|
||||
EXPECT_THAT(key, StrEq("E_pair"));
|
||||
ival = *(int *)lammps_last_thermo(lmp, "type", 2);
|
||||
EXPECT_EQ(ival, LAMMPS_DOUBLE);
|
||||
dval = *(double *)lammps_last_thermo(lmp, "data", 2);
|
||||
EXPECT_DOUBLE_EQ(dval, 0.0);
|
||||
|
||||
key = (const char *)lammps_last_thermo(lmp, "keyword", 3);
|
||||
EXPECT_THAT(key, StrEq("E_mol"));
|
||||
ival = *(int *)lammps_last_thermo(lmp, "type", 3);
|
||||
EXPECT_EQ(ival, LAMMPS_DOUBLE);
|
||||
dval = *(double *)lammps_last_thermo(lmp, "data", 3);
|
||||
EXPECT_DOUBLE_EQ(dval, 0.0);
|
||||
|
||||
key = (const char *)lammps_last_thermo(lmp, "keyword", 4);
|
||||
EXPECT_THAT(key, StrEq("TotEng"));
|
||||
ival = *(int *)lammps_last_thermo(lmp, "type", 4);
|
||||
EXPECT_EQ(ival, LAMMPS_DOUBLE);
|
||||
dval = *(double *)lammps_last_thermo(lmp, "data", 4);
|
||||
EXPECT_DOUBLE_EQ(dval, 2.3405256449146163);
|
||||
|
||||
key = (const char *)lammps_last_thermo(lmp, "keyword", 5);
|
||||
EXPECT_THAT(key, StrEq("Press"));
|
||||
ival = *(int *)lammps_last_thermo(lmp, "type", 5);
|
||||
EXPECT_EQ(ival, LAMMPS_DOUBLE);
|
||||
dval = *(double *)lammps_last_thermo(lmp, "data", 5);
|
||||
EXPECT_DOUBLE_EQ(dval, 31.700964689115658);
|
||||
};
|
||||
|
||||
TEST_F(LibraryProperties, box)
|
||||
@ -326,7 +383,7 @@ TEST_F(LibraryProperties, global)
|
||||
EXPECT_EQ(lammps_extract_global_datatype(lmp, "special_lj"), LAMMPS_DOUBLE);
|
||||
EXPECT_EQ(lammps_extract_global_datatype(lmp, "special_coul"), LAMMPS_DOUBLE);
|
||||
double *special_lj = (double *)lammps_extract_global(lmp, "special_lj");
|
||||
double *special_coul= (double *)lammps_extract_global(lmp, "special_coul");
|
||||
double *special_coul = (double *)lammps_extract_global(lmp, "special_coul");
|
||||
EXPECT_DOUBLE_EQ(special_lj[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(special_lj[1], 0.0);
|
||||
EXPECT_DOUBLE_EQ(special_lj[2], 0.5);
|
||||
|
||||
@ -533,6 +533,33 @@ create_atoms 1 single &
|
||||
result = self.lmp.get_thermo(key)
|
||||
self.assertEqual(value, result, key)
|
||||
|
||||
|
||||
def test_last_thermo(self):
|
||||
self.lmp.command("units lj")
|
||||
self.lmp.command("atom_style atomic")
|
||||
self.lmp.command("atom_modify map array")
|
||||
self.lmp.command("boundary f f f")
|
||||
self.lmp.command("region box block 0 2 0 2 0 2")
|
||||
self.lmp.command("create_box 1 box")
|
||||
self.lmp.command("mass * 1")
|
||||
|
||||
x = [
|
||||
0.5, 0.5, 0.5,
|
||||
1.5, 1.5, 1.5
|
||||
]
|
||||
types = [1, 1]
|
||||
self.lmp.create_atoms(2, id=None, type=types, x=x)
|
||||
|
||||
self.assertEqual(self.lmp.last_thermo(), None)
|
||||
self.lmp.command("run 2 post no")
|
||||
ref = { "Step" : 2,
|
||||
"Temp" : 0.0,
|
||||
"E_pair" : 0.0,
|
||||
"E_mol" : 0.0,
|
||||
"TotEng" : 0.0,
|
||||
"Press" : 0.0}
|
||||
self.assertDictEqual(self.lmp.last_thermo(), ref)
|
||||
|
||||
def test_extract_global(self):
|
||||
self.lmp.command("region box block -1 1 -2 2 -3 3")
|
||||
self.lmp.command("create_box 1 box")
|
||||
|
||||
Reference in New Issue
Block a user