def test_resize_works(self): # Given pa = self.pa h = DeviceHelper(pa) # When pa.set_device_helper(h) pa.extend(2) pa.align_particles() h.resize(4) # Then self.assertTrue(np.allclose(pa.x[:2], h.x[:2].get())) self.assertTrue(np.allclose(pa.m[:2], h.m[:2].get())) self.assertTrue(np.allclose(pa.rho[:2], h.rho[:2].get())) self.assertTrue(np.allclose(pa.tag[:2], h.tag[:2].get())) # When pa.remove_particles([2, 3]) pa.align_particles() old_x = h.x.data h.resize(2) # Then self.assertEqual(old_x, h.x.data) self.assertTrue(np.allclose(pa.x, h.x.get())) self.assertTrue(np.allclose(pa.y, h.y.get())) self.assertTrue(np.allclose(pa.m, h.m.get())) self.assertTrue(np.allclose(pa.rho, h.rho.get())) self.assertTrue(np.allclose(pa.tag, h.tag.get()))
def test_remove_tagged_particles(self): # Given pa = self.pa h = DeviceHelper(pa) # When pa.set_device_helper(h) h.resize(5) h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype)) h.tag.set(np.array([0, 0, 1, 0, 1], h.tag.dtype)) h.remove_tagged_particles(1) # Then assert np.all(np.sort(h.x.get()) == np.array([2., 3., 5.]))
def test_align_particles(self): # Given pa = self.pa h = DeviceHelper(pa) # When pa.set_device_helper(h) h.resize(5) h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype)) h.tag.set(np.array([0, 0, 1, 0, 1], h.tag.dtype)) h.align_particles() # Then x = h.x.get() assert np.all(np.sort(x[:-2]) == np.array([2., 3., 5.]))
def test_align(self): # Given pa = self.pa h = DeviceHelper(pa) # When pa.set_device_helper(h) h.resize(5) h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype)) indices = cl.array.arange(get_queue(), 4, -1, -1, dtype=np.int32) h.align(indices) # Then assert np.all(h.x.get() == np.array([6., 5., 4., 3., 2.]))
def test_get_number_of_particles(self): # Given pa = self.pa h = DeviceHelper(pa) # When pa.set_device_helper(h) h.resize(5) h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype)) h.tag.set(np.array([0, 0, 1, 0, 1], h.tag.dtype)) h.align_particles() # Then assert h.get_number_of_particles() == 5 assert h.get_number_of_particles(real=True) == 3
def test_remove_particles(self): # Given pa = self.pa h = DeviceHelper(pa) # When pa.set_device_helper(h) h.resize(5) h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype)) indices = np.array([1, 2], dtype=np.uint32) indices = cl.array.to_device(get_queue(), indices) h.remove_particles(indices) # Then assert np.all(np.sort(h.x.get()) == np.array([2., 5., 6.]))