コード例 #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]