def test_step(self): mpcd.integrator(dt=0.1) bulk = mpcd.stream.bulk(period=1) # run 1 step and check updated velocity k0 = 2. * np.pi / 10. f = mpcd.force.sine(F=2., k=k0) bulk.set_force(f) hoomd.run(1) snap = self.s.take_snapshot() if hoomd.context.current.device.comm.rank == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], (1.1, -1.2, 0.2)) np.testing.assert_array_almost_equal( snap.particles.velocity[0], (1. + 0.5 * 0.1 * 2. * np.sin(k0 * 0.2), -2.0, 2.)) # remove force and stream freely bulk.remove_force() hoomd.run(1) snap = self.s.take_snapshot() if hoomd.context.current.device.comm.rank == 0: np.testing.assert_array_almost_equal( snap.particles.velocity[0], (1. + 0.5 * 0.1 * 2. * np.sin(k0 * 0.2), -2.0, 2.))
def setUp(self): # establish the simulation context hoomd.context.initialize() # set the decomposition in z for mpi builds if hoomd.comm.get_num_ranks() > 1: hoomd.comm.decomposition(nz=2) # default testing configuration hoomd.init.read_snapshot( hoomd.data.make_snapshot(N=0, box=hoomd.data.boxdim(L=10.))) # initialize the system from the starting snapshot snap = mpcd.data.make_snapshot(N=8) snap.particles.position[:] = [[-3.05, -4, -4.11], [3.05, 4, 4.11], [-3.05, -2, 4.11], [3.05, 2, -4.11], [0, 0, 3.95], [0, 0, -3.95], [3.03, 0, -3.98], [3.02, 0, -3.97]] snap.particles.velocity[:] = [[1., -1., 1.], [-1., 1., -1.], [1., 0., -1.], [-1., 0., 1.], [0., 0., 1.], [0., 0., -1.], [-1., 0., -1.], [-1., 0., -1.]] self.s = mpcd.init.read_snapshot(snap) mpcd.integrator(dt=0.1)
def test_step(self): mpcd.integrator(dt=0.1) mpcd.stream.bulk(period=1) # take one step hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], [1.1, 4.95, 3.1]) np.testing.assert_array_almost_equal(snap.particles.position[1], [-3.1, -4.85, -1.1]) # take another step, wrapping the first particle through the boundary hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], [1.2, -4.95, 3.2]) np.testing.assert_array_almost_equal(snap.particles.position[1], [-3.2, -4.95, -1.2]) # take another step, wrapping the second particle through the boundary hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], [1.3, -4.85, 3.3]) np.testing.assert_array_almost_equal(snap.particles.position[1], [-3.3, 4.95, -1.3])
def test_step(self): mpcd.integrator(dt=0.1) bulk = mpcd.stream.bulk(period=1) # run 1 step and check updated velocity for all particles getting a force # velocities are reset at the end of the step f = mpcd.force.block(F=2.0) bulk.set_force(f) hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.velocity, ((0.2,0,0),(-0.2,0,0),(0.2,0,0))) snap.particles.velocity[:] = 0. self.s.restore_snapshot(snap) # run another step, but now the particle at the origin is outside the blocks # velocities are reset at the end of the step f = mpcd.force.block(F=2.0, H=2.1, w=0.2) bulk.set_force(f) hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.velocity, ((0.2,0,0),(-0.2,0,0),(0,0,0))) snap.particles.velocity[:] = 0. self.s.restore_snapshot(snap) # remove force and stream freely bulk.remove_force() hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.velocity, ((0,0,0),(0,0,0),(0,0,0)))
def test_period(self): snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: snap.particles.position[0] = [1.3,-4.85,3.3] snap.particles.position[1] = [-3.3,4.95,-1.3] self.s.restore_snapshot(snap) mpcd.integrator(dt=0.05) bulk = mpcd.stream.bulk(period=4) # first step should go hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], [1.5,-4.65,3.5]) np.testing.assert_array_almost_equal(snap.particles.position[1], [-3.5,4.75,-1.5]) # running again should not move the particles since we haven't hit next period hoomd.run(3) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], [1.5,-4.65,3.5]) np.testing.assert_array_almost_equal(snap.particles.position[1], [-3.5,4.75,-1.5]) # but one more step should move them again hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], [1.7,-4.45,3.7]) np.testing.assert_array_almost_equal(snap.particles.position[1], [-3.7,4.55,-1.7]) # trying to change the period on the wrong step should throw an error with self.assertRaises(RuntimeError): bulk.set_period(period=2) # running up to the next period should be allowed hoomd.run(3) bulk.set_period(period=2) # running once should now move half as far hoomd.run(1) snap = self.s.take_snapshot() if hoomd.comm.get_rank() == 0: np.testing.assert_array_almost_equal(snap.particles.position[0], [1.8,-4.35,3.8]) np.testing.assert_array_almost_equal(snap.particles.position[1], [-3.8,4.45,-1.8]) # changing in between runs should fail with self.assertRaises(RuntimeError): bulk.set_period(1) hoomd.run(1) # cannot set period to a not equal multiple with self.assertRaises(RuntimeError): bulk.set_period(9) # but this should work since the timestep is 10 bulk.set_period(5)
def setUp(self): # establish the simulation context hoomd.context.initialize() # default testing configuration hoomd.init.read_snapshot(hoomd.data.make_snapshot(N=1, box=hoomd.data.boxdim(L=20.))) # initialize the system from the starting snapshot mpcd.init.read_snapshot(mpcd.data.make_snapshot(N=1)) # create an integrator mpcd.integrator(dt=0.02)
def test_enable(self): mpcd.integrator(dt=0.1) bulk = mpcd.stream.bulk(period=1) self.assertTrue(bulk.enabled) self.assertEqual(hoomd.context.current.mpcd._stream, bulk) # ensure this is disabled bulk.disable() self.assertEqual(bulk.enabled, False) self.assertEqual(hoomd.context.current.mpcd._stream, None) bulk.enable() self.assertTrue(bulk.enabled) self.assertEqual(hoomd.context.current.mpcd._stream, bulk)
def test_bad_period(self): ig = mpcd.integrator(dt=0.001) bulk = mpcd.stream.bulk(period=5) # period cannot be less than integrator's period srd = mpcd.collide.srd(seed=42, period=1, angle=130.) with self.assertRaises(ValueError): ig.update_methods() srd.disable() # being equal is OK srd = mpcd.collide.srd(seed=42, period=5, angle=130.) ig.update_methods() srd.disable() # period being greater but not a multiple is also an error srd = mpcd.collide.srd(seed=42, period=7, angle=130.) with self.assertRaises(ValueError): ig.update_methods() srd.disable() # being greater and a multiple is OK srd = mpcd.collide.srd(seed=42, period=10, angle=130.) ig.update_methods() # using set_period interface should also cause a problem now though bulk.set_period(7) with self.assertRaises(ValueError): ig.update_methods()
def test_update_methods(self): ig = mpcd.integrator(dt=0.001) ig.update_methods() # add an nve integrator md.integrate.nve(group=hoomd.group.all()) ig.update_methods()
def setUp(self): # establish the simulation context hoomd.context.initialize() # set the decomposition in z for mpi builds if hoomd.context.current.device.comm.num_ranks > 1: hoomd.comm.decomposition(nz=2) # default testing configuration hoomd.init.read_snapshot( hoomd.data.make_snapshot(N=0, box=hoomd.data.boxdim(L=10.))) # initialize the system from the starting snapshot snap = mpcd.data.make_snapshot(N=2) snap.particles.position[:] = [[4.95, -4.95, 3.85], [0., 0., -3.8]] snap.particles.velocity[:] = [[1., -1., 1.], [-1., -1., -1.]] self.s = mpcd.init.read_snapshot(snap) mpcd.integrator(dt=0.1)
def setUp(self): hoomd.context.initialize() # box size L and solvent density 5 L = 20 self.density = 5. # solute initially on simple cubic lattice self.solute = hoomd.init.create_lattice(hoomd.lattice.sc(a=1.0), L) snap = self.solute.take_snapshot(all=True) if hoomd.comm.get_rank() == 0: snap.particles.mass[:] = self.density self.solute.restore_snapshot(snap) # srd self.solvent = mpcd.init.make_random(N=int(self.density*L**3), kT=1.0, seed=42) mpcd.integrator(dt=0.1) self.srd = mpcd.collide.srd(seed=791, period=1, angle=130., kT=1.0) mpcd.stream.bulk(period=1) md.integrate.nve(hoomd.group.all())
def test_step(self): mpcd.integrator(dt=0.1) bulk = mpcd.stream.bulk(period=1) # run 1 step and check updated velocity f = mpcd.force.constant((1.,0.,-1.)) bulk.set_force(f) hoomd.run(1) snap = self.s.take_snapshot() if hoomd.context.current.device.comm.rank == 0: np.testing.assert_array_almost_equal(snap.particles.velocity[0], (1.1, -2.0, 2.9)) np.testing.assert_array_almost_equal(snap.particles.position[0], (0.105, -1.2, 1.295)) # remove force and stream freely bulk.remove_force() hoomd.run(1) snap = self.s.take_snapshot() if hoomd.context.current.device.comm.rank == 0: np.testing.assert_array_almost_equal(snap.particles.velocity[0], (1.1, -2.0, 2.9)) np.testing.assert_array_almost_equal(snap.particles.position[0], (0.215, -1.4, 1.585))
def test_set_params(self): ig = mpcd.integrator(dt=0.001) self.assertAlmostEqual(ig.dt, 0.001) self.assertEqual(ig.aniso, None) # test changing dt ig.set_params(dt=0.005) self.assertAlmostEqual(ig.dt, 0.005) self.assertEqual(ig.aniso, None) # test changing aniso to False ig.set_params(aniso=False) self.assertAlmostEqual(ig.dt, 0.005) self.assertEqual(ig.aniso, False) # test chaning aniso to True ig.set_params(aniso=True) self.assertAlmostEqual(ig.dt, 0.005) self.assertEqual(ig.aniso, True)
def test_not_init(self): hoomd.context.initialize() # calling before initialization must fail with self.assertRaises(RuntimeError): mpcd.integrator(dt=0.001) # calling after HOOMD initialization but not MPCD initialization must also fail hoomd.init.read_snapshot(hoomd.data.make_snapshot(N=1, box=hoomd.data.boxdim(L=20.))) with self.assertRaises(RuntimeError): mpcd.integrator(dt=0.001) # now it must succeed mpcd.init.read_snapshot(mpcd.data.make_snapshot(N=1)) mpcd.integrator(dt=0.001)
def test_not_init(self): hoomd.context.initialize() # calling before initialization must fail with self.assertRaises(RuntimeError): mpcd.integrator(dt=0.001) # calling after HOOMD initialization but not MPCD initialization must also fail hoomd.init.read_snapshot( hoomd.data.make_snapshot(N=1, box=hoomd.data.boxdim(L=20.))) with self.assertRaises(RuntimeError): mpcd.integrator(dt=0.001) # now it must succeed mpcd.init.read_snapshot(mpcd.data.make_snapshot(N=1)) mpcd.integrator(dt=0.001)
def test_create(self): ig = mpcd.integrator(dt=0.001) self.assertEqual(hoomd.context.current.integrator, ig) mpcd.integrator(dt=0.001) mpcd.integrator(dt=0.005, aniso=True)
def test_run(self): mpcd.integrator(dt=0.001) hoomd.run(1)