コード例 #1
0
    def test_mdlc(self):
        s = self.system
        rho = 0.3

        # This is only for box size calculation. The actual particle number is
        # lower, because particles are removed from the mdlc gap region
        n_particle = 100

        particle_radius = 0.5
        box_l = np.cbrt(4 * n_particle * np.pi / (3 * rho)) * particle_radius
        s.box_l = 3 * [box_l]
        ref_E_path = abspath("data/mdlc_reference_data_energy.dat")
        ref_E = float(np.genfromtxt(ref_E_path)) * DIPOLAR_PREFACTOR
        gap_size = 2.0

        # Particles
        data = np.genfromtxt(
            abspath("data/mdlc_reference_data_forces_torques.dat"))
        s.part.add(pos=data[:, 1:4], dip=data[:, 4:7])
        s.part[:].rotation = (1, 1, 1)

        p3m = magnetostatics.DipolarP3M(prefactor=DIPOLAR_PREFACTOR,
                                        mesh=32,
                                        accuracy=1E-4)
        dlc = magnetostatic_extensions.DLC(maxPWerror=1E-5, gap_size=gap_size)
        s.actors.add(p3m)
        s.actors.add(dlc)
        s.integrator.run(0)
        err_f = self.vector_error(s.part[:].f,
                                  data[:, 7:10] * DIPOLAR_PREFACTOR)
        err_t = self.vector_error(s.part[:].torque_lab,
                                  data[:, 10:13] * DIPOLAR_PREFACTOR)
        err_e = s.analysis.energy()["dipolar"] - ref_E

        tol_f = 2E-3
        tol_t = 2E-3
        tol_e = 1E-3

        self.assertLessEqual(abs(err_e), tol_e, "Energy difference too large")
        self.assertLessEqual(abs(err_t), tol_t, "Torque difference too large")
        self.assertLessEqual(abs(err_f), tol_f, "Force difference too large")

        # Check if error is thrown when particles enter the MDLC gap
        # positive direction
        s.part[0].pos = [
            s.box_l[0] / 2, s.box_l[1] / 2, s.box_l[2] - gap_size / 2
        ]
        with self.assertRaises(Exception):
            self.system.analysis.energy()
        with self.assertRaises(Exception):
            self.integrator.run(2)
        # negative direction
        s.part[0].pos = [s.box_l[0] / 2, s.box_l[1] / 2, -gap_size / 2]
        with self.assertRaises(Exception):
            self.system.analysis.energy()
        with self.assertRaises(Exception):
            self.integrator.run(2)
コード例 #2
0
    def test_mdlc(self):
        s = self.s
        s.part.clear()
        rho = 0.3

        # This is only for box size calculation. The actual particle numbwe is
        # lower, because particles are removed from the mdlc gap region
        n_particle = 100

        particle_radius = 0.5
        box_l = pow(((4 * n_particle * 3.141592654) /
                     (3 * rho)), 1.0 / 3.0) * particle_radius
        s.box_l = box_l, box_l, box_l
        f = open(abspath("data/mdlc_reference_data_energy.dat"))
        ref_E = float(f.readline())
        f.close()

        # Particles
        data = np.genfromtxt(
            abspath("data/mdlc_reference_data_forces_torques.dat"))
        for p in data[:, :]:
            s.part.add(id=int(p[0]), pos=p[1:4], dip=p[4:7])
        s.part[:].rotation = (1, 1, 1)

        p3m = magnetostatics.DipolarP3M(prefactor=1, mesh=32, accuracy=1E-4)
        dlc = magnetostatic_extensions.DLC(maxPWerror=1E-5, gap_size=2.)
        s.actors.add(p3m)
        s.actors.add(dlc)
        s.thermostat.turn_off()
        s.integrator.run(0)
        err_f = np.sum(np.sqrt(np.sum(
            (s.part[:].f - data[:, 7:10])**2, 1)), 0) / np.sqrt(data.shape[0])
        err_t = np.sum(
            np.sqrt(np.sum((s.part[:].torque_lab - data[:, 10:13])**2, 1)),
            0) / np.sqrt(data.shape[0])
        err_e = s.analysis.energy()["dipolar"] - ref_E
        print("Energy difference", err_e)
        print("Force difference", err_f)
        print("Torque difference", err_t)

        tol_f = 2E-3
        tol_t = 2E-3
        tol_e = 1E-3

        self.assertLessEqual(abs(err_e), tol_e, "Energy difference too large")
        self.assertLessEqual(abs(err_t), tol_t, "Torque difference too large")
        self.assertLessEqual(abs(err_f), tol_f, "Force difference too large")

        s.part.clear()
        del s.actors[0]
        del s.actors[0]
コード例 #3
0
    def test_p3m(self):
        s = self.s
        s.part.clear()
        rho = 0.09

        # This is only for box size calculation. The actual particle numbwe is
        # lower, because particles are removed from the mdlc gap region
        n_particle = 1000

        particle_radius = 1
        box_l = pow(((4 * n_particle * 3.141592654) /
                     (3 * rho)), 1.0 / 3.0) * particle_radius
        s.box_l = box_l, box_l, box_l

        # Particles
        data = np.genfromtxt(abspath("data/p3m_magnetostatics_system.data"))
        for p in data[:, :]:
            s.part.add(id=int(p[0]), pos=p[1:4], dip=p[4:7])
        s.part[:].rotation = (1, 1, 1)

        p3m = magnetostatics.DipolarP3M(prefactor=1,
                                        mesh=32,
                                        accuracy=1E-6,
                                        epsilon="metallic")
        s.actors.add(p3m)
        s.integrator.run(0)
        expected = np.genfromtxt(
            abspath("data/p3m_magnetostatics_expected.data"))[:, 1:]
        err_f = np.sum(np.sqrt(np.sum((s.part[:].f - expected[:, 0:3])**2, 1)),
                       0) / np.sqrt(data.shape[0])
        err_t = np.sum(
            np.sqrt(np.sum((s.part[:].torque_lab - expected[:, 3:6])**2, 1)),
            0) / np.sqrt(data.shape[0])
        ref_E = 5.570
        err_e = s.analysis.energy()["dipolar"] - ref_E
        print("Energy difference", err_e)
        print("Force difference", err_f)
        print("Torque difference", err_t)

        tol_f = 2E-3
        tol_t = 2E-3
        tol_e = 1E-3

        self.assertLessEqual(abs(err_e), tol_e, "Energy difference too large")
        self.assertLessEqual(abs(err_t), tol_t, "Torque difference too large")
        self.assertLessEqual(abs(err_f), tol_f, "Force difference too large")

        s.part.clear()
        del s.actors[0]
コード例 #4
0
    def test_p3m(self):
        s = self.system
        rho = 0.09

        # This is only for box size calculation. The actual particle number is
        # lower, because particles are removed from the mdlc gap region
        n_particle = 1000

        particle_radius = 1
        box_l = np.cbrt(4 * n_particle * np.pi / (3 * rho)) * particle_radius
        s.box_l = 3 * [box_l]

        # Particles
        data = np.genfromtxt(abspath("data/p3m_magnetostatics_system.data"))
        s.part.add(pos=data[:, 1:4], dip=data[:, 4:7])
        s.part[:].rotation = (1, 1, 1)

        p3m = magnetostatics.DipolarP3M(prefactor=DIPOLAR_PREFACTOR,
                                        mesh=32,
                                        accuracy=1E-6,
                                        epsilon="metallic")
        s.actors.add(p3m)
        s.integrator.run(0)
        expected = np.genfromtxt(
            abspath("data/p3m_magnetostatics_expected.data"))[:, 1:]
        err_f = self.vector_error(s.part[:].f,
                                  expected[:, 0:3] * DIPOLAR_PREFACTOR)
        err_t = self.vector_error(s.part[:].torque_lab,
                                  expected[:, 3:6] * DIPOLAR_PREFACTOR)
        ref_E = 5.570 * DIPOLAR_PREFACTOR
        err_e = s.analysis.energy()["dipolar"] - ref_E

        tol_f = 2E-3
        tol_t = 2E-3
        tol_e = 1E-3

        self.assertLessEqual(abs(err_e), tol_e, "Energy difference too large")
        self.assertLessEqual(abs(err_t), tol_t, "Torque difference too large")
        self.assertLessEqual(abs(err_f), tol_f, "Force difference too large")
コード例 #5
0
ファイル: ferrofluid.py プロジェクト: xiuru-yan/espresso
                                       gamma=0.001,
                                       max_displacement=0.01)

# warmup
while system.analysis.energy()["total"] > 0.1 * n_part:
    print("minimization: {:.1f}".format(system.analysis.energy()["total"]))
    system.integrator.run(20)
print("minimization: {:.1f}".format(system.analysis.energy()["total"]))
print()
system.integrator.set_vv()

system.thermostat.set_langevin(kT=1.0, gamma=1.0, seed=42)

system.integrator.run(min(5 * measurement_steps, 60000))

system.actors.add(magnetostatics.DipolarP3M(prefactor=1, accuracy=1E-4))
print("Tune skin: {}".format(
    system.cell_system.tune_skin(min_skin=0.2,
                                 max_skin=1,
                                 tol=0.05,
                                 int_steps=100)))

system.integrator.run(min(5 * measurement_steps, 2500))

print(system.non_bonded_inter[0, 0].lennard_jones)

if not args.visualizer:
    # print initial energies
    energies = system.analysis.energy()
    print(energies)