예제 #1
0
 def run_with_p3m(self, p3m, **npt_kwargs):
     system = self.system
     np.random.seed(42)
     # set up particles
     system.box_l = [6] * 3
     system.part.add(pos=np.random.uniform(0, system.box_l[0], (11, 3)))
     if espressomd.has_features("P3M"):
         system.part[:].q = np.sign(np.arange(-5, 6))
     if espressomd.has_features("DP3M"):
         system.part[:].dip = tests_common.random_dipoles(11)
     system.non_bonded_inter[0,
                             0].lennard_jones.set_params(epsilon=1,
                                                         sigma=1,
                                                         cutoff=2**(1 / 6),
                                                         shift=0.25)
     system.integrator.set_steepest_descent(f_max=10,
                                            gamma=0.1,
                                            max_displacement=0.01)
     system.integrator.run(100)
     system.integrator.set_vv()
     # combine NpT with a P3M algorithm
     system.actors.add(p3m)
     system.integrator.run(20)
     system.integrator.set_isotropic_npt(ext_pressure=0.001,
                                         piston=0.001,
                                         **npt_kwargs)
     system.thermostat.set_npt(kT=1.0, gamma0=2, gammav=0.04, seed=42)
     system.integrator.run(20)
예제 #2
0
파일: p3m_fft.py 프로젝트: jngrad/espresso
 def add_magnetic_particles(self):
     np.random.seed(seed=42)
     num_part = 200
     positions = np.random.random((num_part, 3))
     dipoles = tests_common.random_dipoles(num_part)
     self.system.part.add(pos=positions * self.system.box_l,
                          dip=dipoles, rotation=num_part * [(1, 1, 1)])
     self.minimize()
예제 #3
0
    def gen_reference_data(self,
                           filepath_energy=OPEN_BOUNDARIES_REF_ENERGY,
                           filepath_arrays=OPEN_BOUNDARIES_REF_ARRAYS):
        system = self.system
        np.random.seed(42)

        # add particles
        N = 20
        dipole_modulus = 1.3
        part_pos = np.random.random((N, 3)) * system.box_l
        part_dip = dipole_modulus * tests_common.random_dipoles(N)
        self.particles = system.part.add(pos=part_pos,
                                         dip=part_dip,
                                         rotation=N * [(1, 1, 1)])

        # minimize system
        system.non_bonded_inter[0, 0].lennard_jones.set_params(epsilon=10.0,
                                                               sigma=1,
                                                               cutoff=2**(1.0 /
                                                                          6.0),
                                                               shift="auto")
        system.integrator.set_steepest_descent(f_max=1,
                                               gamma=0.001,
                                               max_displacement=0.01)
        system.integrator.run(100)
        system.non_bonded_inter[0, 0].lennard_jones.set_params(epsilon=0.0,
                                                               sigma=0,
                                                               cutoff=0,
                                                               shift=0)
        system.integrator.set_vv()
        assert system.analysis.energy()["total"] == 0

        # compute forces and energies for dawaanr
        ref_e, ref_f, ref_t = self.dds_data()
        np.save(filepath_energy, np.array([ref_e]), allow_pickle=False)
        np.save(filepath_arrays,
                np.hstack((self.particles.pos_folded, self.particles.dip,
                           ref_f, ref_t)),
                allow_pickle=False)
예제 #4
0
    def test(self):
        pf_bh_gpu = 2.34
        pf_dds_gpu = 3.524
        ratio_dawaanr_bh_gpu = pf_dds_gpu / pf_bh_gpu
        l = 15
        self.system.box_l = [l, l, l]
        self.system.periodicity = [0, 0, 0]
        self.system.time_step = 1E-4
        self.system.cell_system.skin = 0.1

        part_dip = np.zeros((3))

        for n in [128, 541]:
            dipole_modulus = 1.3
            part_pos = np.random.random((n, 3)) * l
            part_dip = dipole_modulus * tests_common.random_dipoles(n)
            self.system.part.add(pos=part_pos, dip=part_dip,
                                 v=n * [(0, 0, 0)], omega_body=n * [(0, 0, 0)])

            self.system.non_bonded_inter[0, 0].lennard_jones.set_params(
                epsilon=10.0, sigma=0.5, cutoff=0.55, shift="auto")
            self.system.thermostat.set_langevin(kT=0.0, gamma=10.0, seed=42)
            g = espressomd.galilei.GalileiTransform()
            g.kill_particle_motion(rotation=True)
            self.system.integrator.set_vv()

            self.system.non_bonded_inter[0, 0].lennard_jones.set_params(
                epsilon=0.0, sigma=0.0, cutoff=-1, shift=0.0)

            self.system.cell_system.skin = 0.0
            self.system.time_step = 0.01
            self.system.thermostat.turn_off()

            # gamma should be zero in order to avoid the noise term in force
            # and torque
            self.system.thermostat.set_langevin(kT=1.297, gamma=0.0)

            dds_gpu = espressomd.magnetostatics.DipolarDirectSumGpu(
                prefactor=pf_dds_gpu)
            self.system.actors.add(dds_gpu)
            self.system.integrator.run(steps=0, recalc_forces=True)

            dawaanr_f = np.copy(self.system.part[:].f)
            dawaanr_t = np.copy(self.system.part[:].torque_lab)
            dawaanr_e = self.system.analysis.energy()["total"]

            del dds_gpu
            self.system.actors.clear()

            self.system.integrator.run(steps=0, recalc_forces=True)
            bh_gpu = espressomd.magnetostatics.DipolarBarnesHutGpu(
                prefactor=pf_bh_gpu, epssq=200.0, itolsq=8.0)
            self.system.actors.add(bh_gpu)
            self.system.integrator.run(steps=0, recalc_forces=True)

            bhgpu_f = np.copy(self.system.part[:].f)
            bhgpu_t = np.copy(self.system.part[:].torque_lab)
            bhgpu_e = self.system.analysis.energy()["total"]

            # compare
            for i in range(n):
                self.assertTrue(
                    self.vectorsTheSame(
                        np.array(dawaanr_t[i]),
                        ratio_dawaanr_bh_gpu * np.array(bhgpu_t[i])),
                    msg='Torques on particle do not match. i={0} dawaanr_t={1} '
                        'ratio_dawaanr_bh_gpu*bhgpu_t={2}'.format(
                        i, np.array(dawaanr_t[i]),
                        ratio_dawaanr_bh_gpu * np.array(bhgpu_t[i])))
                self.assertTrue(
                    self.vectorsTheSame(
                        np.array(dawaanr_f[i]),
                        ratio_dawaanr_bh_gpu * np.array(bhgpu_f[i])),
                    msg='Forces on particle do not match: i={0} dawaanr_f={1} '
                        'ratio_dawaanr_bh_gpu*bhgpu_f={2}'.format(
                        i, np.array(dawaanr_f[i]),
                        ratio_dawaanr_bh_gpu * np.array(bhgpu_f[i])))
            self.assertLessEqual(
                abs(dawaanr_e - bhgpu_e * ratio_dawaanr_bh_gpu),
                abs(1E-3 * dawaanr_e),
                msg='Energies for dawaanr {0} and bh_gpu {1} do not match.'
                    .format(dawaanr_e, ratio_dawaanr_bh_gpu * bhgpu_e))

            self.system.integrator.run(steps=0, recalc_forces=True)

            del bh_gpu
            self.system.actors.clear()
            self.system.part.clear()
예제 #5
0
    def test(self):
        pf_dds_gpu = 2.34
        pf_dawaanr = 3.524
        ratio_dawaanr_dds_gpu = pf_dawaanr / pf_dds_gpu
        self.es.box_l = 3 * [15]
        self.es.periodicity = [0, 0, 0]
        self.es.time_step = 1E-4
        self.es.cell_system.skin = 0.1

        for n in [128, 541]:
            dipole_modulus = 1.3
            part_dip = dipole_modulus * tests_common.random_dipoles(n)
            part_pos = np.random.random((n, 3)) * self.es.box_l[0]
            self.es.part.add(pos=part_pos, dip=part_dip)

            self.es.non_bonded_inter[0, 0].lennard_jones.set_params(
                epsilon=10.0, sigma=0.5, cutoff=0.55, shift="auto")

            self.es.thermostat.turn_off()
            self.es.integrator.set_steepest_descent(
                f_max=0.0, gamma=0.1, max_displacement=0.1)
            self.es.integrator.run(500)
            g = espressomd.galilei.GalileiTransform()
            g.kill_particle_motion(rotation=True)
            self.es.integrator.set_vv()

            self.es.non_bonded_inter[0, 0].lennard_jones.set_params(
                epsilon=0.0, sigma=0.0, cutoff=0.0, shift=0.0)

            self.es.cell_system.skin = 0.0
            self.es.time_step = 0.01
            self.es.thermostat.turn_off()
            # gamma should be zero in order to avoid the noise term in force
            # and torque
            self.es.thermostat.set_langevin(kT=1.297, gamma=0.0, seed=42)

            dds_cpu = espressomd.magnetostatics.DipolarDirectSumCpu(
                prefactor=pf_dawaanr)
            self.es.actors.add(dds_cpu)
            self.es.integrator.run(steps=0, recalc_forces=True)

            dawaanr_f = np.copy(self.es.part[:].f)
            dawaanr_t = np.copy(self.es.part[:].torque_lab)
            dawaanr_e = self.es.analysis.energy()["total"]

            del dds_cpu
            for i in range(len(self.es.actors.active_actors)):
                self.es.actors.remove(self.es.actors.active_actors[i])

            self.es.integrator.run(steps=0, recalc_forces=True)
            dds_gpu = espressomd.magnetostatics.DipolarDirectSumGpu(
                prefactor=pf_dds_gpu)
            self.es.actors.add(dds_gpu)
            self.es.integrator.run(steps=0, recalc_forces=True)

            ddsgpu_f = np.copy(self.es.part[:].f)
            ddsgpu_t = np.copy(self.es.part[:].torque_lab)
            ddsgpu_e = self.es.analysis.energy()["total"]

            # compare
            for i in range(n):
                np.testing.assert_allclose(
                    np.array(dawaanr_t[i]),
                    ratio_dawaanr_dds_gpu * np.array(ddsgpu_t[i]),
                    err_msg='Torques on particle do not match for particle {}'
                    .format(i), atol=3e-3)
                np.testing.assert_allclose(
                    np.array(dawaanr_f[i]),
                    ratio_dawaanr_dds_gpu * np.array(ddsgpu_f[i]),
                    err_msg='Forces on particle do not match for particle i={}'
                    .format(i), atol=3e-3)
            self.assertAlmostEqual(
                dawaanr_e,
                ddsgpu_e * ratio_dawaanr_dds_gpu,
                places=2,
                msg='Energies for dawaanr {0} and dds_gpu {1} do not match.'
                .format(dawaanr_e, ratio_dawaanr_dds_gpu * ddsgpu_e))

            self.es.integrator.run(steps=0, recalc_forces=True)

            del dds_gpu
            self.es.actors.clear()
            self.es.part.clear()