def test_zeeman_energy(): mu0 = 4 * np.pi * 1e-7 # A system of 8 cells ( not using nm units) mesh = CuboidMesh(dx=2, dy=2, dz=2, nx=2, ny=2, nz=2 ) sim = Sim(mesh) Ms = 1e5 sim.set_Ms(Ms) sim.set_m((0, 0, 1)) H = 0.1 / mu0 zeeman = Zeeman((0, 0, H)) sim.add(zeeman) field = zeeman.compute_field() zf = sim.get_interaction('Zeeman') # -> -> # Expected energy: Int ( -mu0 M * H ) dV # Since we have 8 cells with the same M, we just sum their contrib exp_energy = 8 * (-mu0 * H * Ms * mesh.dx * mesh.dy * mesh.dz) assert np.abs(zf.compute_energy() - exp_energy) < 1e-10
def test_add_remove_interaction_simple(): mesh = CuboidMesh(nx=10, ny=10, nz=10, unit_length=1e-9) name = 'test_add_remove_intn_simple' sim = Sim(mesh, name=name) sim.set_m(lambda pos: (0, 0, 1)) sim.set_Ms(5.8e5) exch = UniformExchange(A=1e-11, name='Exchange') zee = Zeeman((0, 0, 0.05 / constant.mu_0), name='Zeeman') sim.add(exch) sim.add(zee) sim.driver.run_until(1e-9) sim.remove('Zeeman') sim.driver.run_until(2e-9) f = open(name + '.txt') lines = f.read().split('\n') headers = lines[0].split() first_data = lines[2].split() last_data = lines[2].split() # Find the position in the data table position = headers.index('E_Zeeman') assert np.abs(float(last_data[position])) < 1e-15
dy=dy, dz=dz, x0=-Lx / 2, y0=-Ly / 2, z0=-Lz / 2, unit_length=1e-9) sim = Sim(mesh) Ms = 1.1e6 A = 2e-12 D = 3.9e-3 Ku = 2.5e6 Bz = 1. sim.set_Ms(Ms) sim.add(fidimag.micro.UniformExchange(A)) sim.add(fidimag.micro.UniaxialAnisotropy(Ku, axis=(0, 0, 1))) sim.add(fidimag.micro.Zeeman((0, 0, Bz / C.mu_0))) # sim.add(fidimag.micro.DMI(D, dmi_type='interfacial')) # For a C_n material, there is a kind of instability when one of the DM # constants is larger than approx 0.7 times the other DM constant sim.add(fidimag.micro.DMI([D, 0.6 * D], dmi_type='C_n')) sim.set_m(init_m) sim.driver.do_precession = False sim.driver.alpha = 0.9