Esempio n. 1
0
    def test_electric_plane_wave(self):
        E0 = np.array([1., -2., 3.])
        k = np.array([-.1, .2, 0.3])
        omega = 5.
        phi = 1.4

        electric_wave = constraints.ElectricPlaneWave(
            E0=E0, k=k, omega=omega, phi=phi)
        np.testing.assert_almost_equal(E0, electric_wave.E0)
        np.testing.assert_almost_equal(k, electric_wave.k)
        np.testing.assert_almost_equal(omega, electric_wave.omega)
        np.testing.assert_almost_equal(phi, electric_wave.phi)

        self.system.constraints.add(electric_wave)

        p = self.system.part.add(pos=[0.4, 0.1, 0.11], q=-14.)
        self.system.time = 1042.

        self.system.integrator.run(0)

        np.testing.assert_almost_equal(np.copy(p.f),
                                       p.q * E0 * np.sin(np.dot(k, p.pos_folded) - omega * self.system.time + phi))

        self.system.integrator.run(10)

        np.testing.assert_almost_equal(np.copy(p.f),
                                       p.q * E0 * np.sin(np.dot(k, p.pos_folded) - omega * self.system.time + phi))
Esempio n. 2
0
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,
                           grid_spacing=np.ones(3),
                           default_scale=1.4))
if espressomd.has_features("ELECTROSTATICS"):
    system.constraints.add(
        constraints.ElectricPlaneWave(E0=[1., -2., 3.],
                                      k=[-.1, .2, .3],
                                      omega=5.,
                                      phi=1.4))

if 'LB.OFF' in modes:
    # set thermostat
    if 'THERM.LANGEVIN' in modes:
        system.thermostat.set_langevin(kT=1.0, gamma=2.0, seed=42)
    elif 'THERM.BD' in modes:
        system.thermostat.set_brownian(kT=1.0, gamma=2.0, seed=42)
    elif 'THERM.NPT' in modes and has_features('NPT'):
        system.thermostat.set_npt(kT=1.0, gamma0=2.0, gammav=0.1, seed=42)
    elif 'THERM.DPD' in modes and has_features('DPD'):
        system.thermostat.set_dpd(kT=1.0, seed=42)
    elif 'THERM.SDM' in modes and (has_features('STOKESIAN_DYNAMICS')
                                   or has_features('STOKESIAN_DYNAMICS_GPU')):
        system.periodicity = [0, 0, 0]