From ef3b01f3402cb92ec20902c7c469fdbde2e8b2e9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 18:14:08 -0400 Subject: [PATCH] add neighbor list access tests. now we can always test for a full list. --- unittest/python/python-commands.py | 69 ++++++++++++++++++++++++++++++ unittest/python/python-numpy.py | 68 +++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index cd77fa21a1..13be27f067 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -209,6 +209,75 @@ create_atoms 1 single & self.assertEqual(idx,i) self.assertEqual(num,nlocal-1) + def testNeighborListZeroHalf(self): + self.lmp.commands_string(""" + boundary f f f + units real + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 + pair_coeff 1 1 + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, num, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(num,nlocal-1-i) + + # look up neighbor list by atom index + num, neighs = nlist.find(2) + self.assertEqual(num,4) + self.assertIsNotNone(neighs,None) + # this one will fail + num, neighs = nlist.find(10) + self.assertEqual(num,-1) + self.assertIsNone(neighs,None) + + def testNeighborListZeroFull(self): + self.lmp.commands_string(""" + boundary f f f + units metal + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 full + pair_coeff * * + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, num, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(num,nlocal-1) + @unittest.skipIf(not has_manybody,"Hybrid neighbor list test for manybody potential") def testNeighborListHybrid(self): self.lmp.commands_string(""" diff --git a/unittest/python/python-numpy.py b/unittest/python/python-numpy.py index 7cbae8e48d..3306aba1cd 100644 --- a/unittest/python/python-numpy.py +++ b/unittest/python/python-numpy.py @@ -412,6 +412,74 @@ class PythonNumpy(unittest.TestCase): idx, neighs = nlist.get(i) self.assertEqual(neighs.size,nlocal-1-i) + def testNeighborListZeroHalf(self): + self.lmp.commands_string(""" + boundary f f f + units real + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 + pair_coeff 1 1 + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.numpy.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(neighs.size,nlocal-1-i) + + # look up neighbor list by atom index + neighs = nlist.find(2) + self.assertEqual(neighs.size,4) + self.assertIsNotNone(neighs,None) + # this one will fail + neighs = nlist.find(10) + self.assertIsNone(neighs,None) + + def testNeighborListZeroFull(self): + self.lmp.commands_string(""" + boundary f f f + units metal + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 full + pair_coeff * * + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.numpy.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(neighs.size,nlocal-1) + def testNeighborListCompute(self): self.lmp.commands_string(""" boundary f f f