fix several issues when using extract_global() from python exposed by tests
This commit is contained in:
committed by
Richard Berger
parent
b8f02d759a
commit
a193d9d429
@ -777,10 +777,11 @@ class lammps(object):
|
||||
target_type = float
|
||||
elif dtype == LAMMPS_STRING:
|
||||
self.lib.lammps_extract_global.restype = c_char_p
|
||||
target_type = lambda x: str(x, 'ascii')
|
||||
|
||||
ptr = self.lib.lammps_extract_global(self.lmp, name)
|
||||
if ptr:
|
||||
if dtype == LAMMPS_STRING:
|
||||
return ptr.decode('utf-8')
|
||||
if veclen > 1:
|
||||
result = []
|
||||
for i in range(0,veclen):
|
||||
|
||||
@ -1387,8 +1387,13 @@ void *lammps_extract_global(void *handle, const char *name)
|
||||
if (strcmp(name,"boxhi") == 0) return (void *) lmp->domain->boxhi;
|
||||
if (strcmp(name,"sublo") == 0) return (void *) lmp->domain->sublo;
|
||||
if (strcmp(name,"subhi") == 0) return (void *) lmp->domain->subhi;
|
||||
if (strcmp(name,"sublo_lambda") == 0) return (void *) lmp->domain->sublo_lamda;
|
||||
if (strcmp(name,"subhi_lambda") == 0) return (void *) lmp->domain->subhi_lamda;
|
||||
// these are only valid for a triclinic cell
|
||||
if (lmp->domain->triclinic) {
|
||||
if (strcmp(name,"sublo_lambda") == 0)
|
||||
return (void *) lmp->domain->sublo_lamda;
|
||||
if (strcmp(name,"subhi_lambda") == 0)
|
||||
return (void *) lmp->domain->subhi_lamda;
|
||||
}
|
||||
if (strcmp(name,"boxxlo") == 0) return (void *) &lmp->domain->boxlo[0];
|
||||
if (strcmp(name,"boxxhi") == 0) return (void *) &lmp->domain->boxhi[0];
|
||||
if (strcmp(name,"boxylo") == 0) return (void *) &lmp->domain->boxlo[1];
|
||||
|
||||
@ -259,9 +259,13 @@ create_atoms 1 single &
|
||||
result = self.lmp.get_thermo(key)
|
||||
self.assertEqual(value, result, key)
|
||||
|
||||
def test_extract_global_double(self):
|
||||
def test_extract_global(self):
|
||||
self.lmp.command("region box block -1 1 -2 2 -3 3")
|
||||
self.lmp.command("create_box 1 box")
|
||||
self.assertEqual(self.lmp.extract_global("units"), "lj")
|
||||
self.assertEqual(self.lmp.extract_global("ntimestep"), 0)
|
||||
self.assertEqual(self.lmp.extract_global("dt"), 0.005)
|
||||
|
||||
self.assertEqual(self.lmp.extract_global("boxxlo"), -1.0)
|
||||
self.assertEqual(self.lmp.extract_global("boxxhi"), 1.0)
|
||||
self.assertEqual(self.lmp.extract_global("boxylo"), -2.0)
|
||||
@ -273,7 +277,9 @@ create_atoms 1 single &
|
||||
self.assertEqual(self.lmp.extract_global("sublo"), [-1.0, -2.0, -3.0])
|
||||
self.assertEqual(self.lmp.extract_global("subhi"), [1.0, 2.0, 3.0])
|
||||
self.assertEqual(self.lmp.extract_global("periodicity"), [1,1,1])
|
||||
# only valid for triclinic box
|
||||
self.assertEqual(self.lmp.extract_global("triclinic"), 0)
|
||||
self.assertEqual(self.lmp.extract_global("sublo_lambda"), None)
|
||||
self.assertEqual(self.lmp.extract_global("subhi_lambda"), None)
|
||||
self.assertEqual(self.lmp.extract_global("respa_levels"), None)
|
||||
self.assertEqual(self.lmp.extract_global("respa_dt"), None)
|
||||
|
||||
@ -284,7 +290,10 @@ create_atoms 1 single &
|
||||
self.assertEqual(self.lmp.extract_global("ntimestep"), 1)
|
||||
self.assertEqual(self.lmp.extract_global("respa_levels"), 3)
|
||||
self.assertEqual(self.lmp.extract_global("respa_dt"), [0.0005, 0.0025, 0.005])
|
||||
|
||||
# checks only for triclinic boxes
|
||||
self.lmp.command("change_box all triclinic")
|
||||
self.assertEqual(self.lmp.extract_global("triclinic"), 1)
|
||||
self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0])
|
||||
self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user