def test_hexagonal_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 = HexagonalMesh(a * 0.5, N, N, unit_length=1e-9, alignment='square') # Centre xc = (mesh.Lx * 0.5) yc = (mesh.Ly * 0.5) mu_s = 2 * const.mu_B 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() sim.get_interaction('DemagFull').field DemagFull_energy = sim.compute_energy() / const.meV # Demag using the FFT approach and a larger mesh sim2 = Sim(mesh) sim2.mu_s = mu_s sim2.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc))) sim2.add(DemagHexagonal()) sim2.get_interaction('DemagHexagonal').compute_field() sim2.compute_energy() demag_2fft_energy = sim2.compute_energy() / const.meV # We compare both energies scaled in meV assert (DemagFull_energy - demag_2fft_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
if args.B: zeeman = Zeeman((0, 0, args.B)) sim.add(zeeman, save_field=True) if args.k_u: # Uniaxial anisotropy along + z-axis sim.add(Anisotropy(args.k_u * const.meV, axis=[0, 0, 1])) if args.Demag: print('Using Demag!') sim.add(DemagHexagonal()) if args.FullDemag: print('Using Full Demag calculation!') sim.add(DemagFull()) # ------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Load magnetisation profile --------------------------------------------- # Change the skyrmion initial configuration according to the # chirality of the system (give by the DMI constant) if args.initial_state_skyrmion_down: if len(args.initial_state_skyrmion_down) > 1: pi_factor = args.initial_state_skyrmion_down[1] else: pi_factor = 1
# 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 print('fft t = {}'.format(t))