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
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)) print('{}\n\n'.format(demagfft.field)) start = time.time() demagfmm.fmm.numcells() print(f"N * bohr = {fidimag.common.constant.mu_B * N}") demagfmm.compute_field() err = (demagfft.field - demagfmm.field) / demagfft.field errx = (err[0::3] * err[0::3])**0.5 erry = (err[1::3] * err[1::3])**0.5