def test_gravity(self): g_const = [1, 2, 3] gravity = constraints.Gravity(g=g_const) self.assertSequenceEqual(gravity.g, g_const) self.system.constraints.add(gravity) if espressomd.has_features("MASS"): p = self.system.part.add(pos=[0, 0, 0], mass=3.1) else: p = self.system.part.add(pos=[0, 0, 0]) self.system.integrator.run(0) np.testing.assert_almost_equal(g_const, np.copy(p.f) / p.mass) self.assertAlmostEqual(self.system.analysis.energy()['total'], 0.)
def test_gravity(self): g_const = np.array([1, 2, 3]) gravity = constraints.Gravity(g=g_const) np.testing.assert_almost_equal(g_const, np.copy(gravity.g)) self.system.constraints.add(gravity) if espressomd.has_features("MASS"): p = self.system.part.add(pos=[0, 0, 0], mass=3.1) else: p = self.system.part.add(pos=[0, 0, 0]) self.system.integrator.run(0) np.testing.assert_almost_equal(g_const, np.copy(p.f) / p.mass) self.assertAlmostEqual(self.system.analysis.energy()['total'], 0.) # Virtual sites don't feel gravity if espressomd.has_features("VIRTUAL_SITES"): self.system.part[0].virtual = True self.system.integrator.run(0) np.testing.assert_allclose(np.copy(self.system.part[0].f), 0)
acc_time_series.update() acc_correlator.update() system.part[0].pos = [1.0, 2.0, 3.0] acc_mean_variance.update() acc_time_series.update() acc_correlator.update() system.auto_update_accumulators.add(acc_mean_variance) system.auto_update_accumulators.add(acc_time_series) system.auto_update_accumulators.add(acc_correlator) # constraints system.constraints.add(shape=Sphere(center=system.box_l / 2, radius=0.1), particle_type=17) system.constraints.add(shape=Wall(normal=[1. / np.sqrt(3)] * 3, dist=0.5)) system.constraints.add(constraints.Gravity(g=[1., 2., 3.])) system.constraints.add(constraints.HomogeneousMagneticField(H=[1., 2., 3.])) system.constraints.add( constraints.HomogeneousFlowField(u=[1., 2., 3.], gamma=2.3)) pot_field_data = constraints.ElectricPotential.field_from_fn( system.box_l, np.ones(3), lambda x: np.linalg.norm(10 * np.ones(3) - x)) checkpoint.register("pot_field_data") system.constraints.add( constraints.PotentialField(field=pot_field_data, grid_spacing=np.ones(3), default_scale=1.6)) vec_field_data = constraints.ForceField.field_from_fn( system.box_l, np.ones(3), lambda x: 10 * np.ones(3) - x) checkpoint.register("vec_field_data") system.constraints.add( constraints.ForceField(field=vec_field_data,