def test_demag_two_spin_xx(): mesh = CuboidMesh(nx=2, ny=1, nz=1) sim = Sim(mesh) demag = Demag() sim.add(demag) sim.set_m((1, 0, 0)) field = demag.compute_field() print(field) assert (field[0] == 2e-7) assert (field[3] == 2e-7)
def test_demag_two_spin_xx(): mesh = CuboidMesh(nx=2, ny=1, nz=1) sim = Sim(mesh) demag = Demag() sim.add(demag) sim.set_m((1, 0, 0)) field = demag.compute_field() print field assert(field[0] == 2e-7) assert(field[3] == 2e-7)
def test_demag_fft_exact_oommf(): mesh = CuboidMesh(nx=5, ny=3, nz=2, unit_length=1e-9) sim = Sim(mesh) demag = Demag() sim.add(demag) def init_m(pos): x = pos[0] if x <= 2: return (1, 0, 0) elif x >= 4: return (0, 0, 1) else: return (0, 1, 0) sim.set_m(init_m) fft = demag.compute_field() exact = demag.compute_exact() np.testing.assert_allclose(fft, exact, rtol=1e-10)
def test_demag_fft_exact(): mesh = CuboidMesh(nx=5, ny=3, nz=4) sim = Sim(mesh) demag = Demag() sim.add(demag) def init_m(pos): x = pos[0] if x <= 2: return (1, 0, 0) elif x >= 4: return (0, 0, 1) else: return (0, 1, 0) sim.set_m(init_m) fft = demag.compute_field() exact = demag.compute_exact() # print fft,exact print np.max(np.abs(fft - exact)) assert np.max(np.abs(fft - exact)) < 5e-22
def relax_system(mesh): sim = Sim(mesh, name='relax') sim.mu_s = 1e-23 sim.driver.gamma = 1.76e11 sim.driver.alpha = 1.0 J = 1e-22 exch = UniformExchange(J) sim.add(exch) demag = Demag() sim.add(demag) sim.set_m(init_m) ts = np.linspace(0, 5e-10, 101) for t in ts: sim.driver.run_until(t) sim.save_vtk() np.save('m0.npy', sim.spin)
def test_cuboid_demags_2D(): """ Comparison of the FFT approach for hexagonal meshes, named DemagHexagonal, where it is used a system with the double number of nodes along the x direction (i.e. a mesh with twice the number of nodes of the original mesh), against the full calculation of the Demag field """ # Number of atoms N = 15 a = 0.4 mesh = CuboidMesh(a, a, a, N, N, 1, unit_length=1e-9) mu_s = 2 * const.mu_B # Centre xc = (mesh.Lx * 0.5) yc = (mesh.Ly * 0.5) sim = Sim(mesh) sim.mu_s = mu_s sim.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc))) # Brute force demag calculation sim.add(DemagFull()) sim.get_interaction('DemagFull').compute_field() # print sim.get_interaction('DemagFull').field DemagFull_energy = sim.compute_energy() / const.meV # Demag using the FFT approach sim2 = Sim(mesh) sim2.mu_s = mu_s sim2.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc))) sim2.add(Demag()) sim2.get_interaction('Demag').compute_field() sim2.compute_energy() demag_fft_energy = sim2.compute_energy() / const.meV # We compare both energies scaled in meV assert (DemagFull_energy - demag_fft_energy) < 1e-10
def test_cuboid_demags_1Dchain(): """ Test a brute force calculation of the demagnetising field, called DemagFull, based on the sum of the dipolar contributions of the whole system for every lattice site, against the default FFT approach for the demag field. We compute the energies scaled in meV. This test is performed in a cuboid mesh to assure that the DemagFull library is calculating the same than the default demag function """ N = 12 a = 0.4 mesh = CuboidMesh(a, a, a, N, 1, 1, unit_length=1e-9) mu_s = 2 * const.mu_B sim = Sim(mesh) sim.mu_s = mu_s sim.set_m(lambda pos: m_init_dw(pos, N, a)) # Brute force demag calculation sim.add(DemagFull()) sim.get_interaction('DemagFull').compute_field() # print sim.get_interaction('DemagFull').field DemagFull_energy = sim.compute_energy() / const.meV # Demag using the FFT approach sim2 = Sim(mesh) sim2.mu_s = mu_s sim2.set_m(lambda pos: m_init_dw(pos, N, a)) sim2.add(Demag()) sim2.get_interaction('Demag').compute_field() sim2.compute_energy() demag_fft_energy = sim2.compute_energy() / const.meV # We compare both energies scaled in meV assert (DemagFull_energy - demag_fft_energy) < 1e-10
# self.fmm.compute_field(self.theta, self.field) # self.field *= 1e-7 # return self.field mesh = fidimag.common.CuboidMesh(nx=Nx, ny=Ny, nz=Nz, dx=1, dy=1, dz=1, unit_length=1e-9) N = mesh.n print("Nparticles = {}".format(N)) demagfmm = DemagFMM(order, ncrit, theta=theta) demagfft = Demag() demagfull = DemagFull() sim = fidimag.atomistic.Sim(mesh) sim.set_m((0, 0, 1), normalise=True) print(f"Bohr Magnetom = {fidimag.common.constant.mu_B}") sim.set_mu_s(fidimag.common.constant.mu_B) sim.add(demagfft) sim.add(demagfmm) sim.add(demagfull) start = time.time() demagfft.compute_field() end = time.time() t = end - start