def test_script(self): system = mc.System(name="test_system") system.hamiltonian += mc.Exchange(1e-12) system.hamiltonian += mc.Demag() system.hamiltonian += mc.UniaxialAnisotropy(1e3, (0, 1, 0)) system.hamiltonian += mc.Zeeman((0, 1e6, 0)) system.dynamics += mc.Precession(2.211e5) system.dynamics += mc.Damping(0.1) mesh = mc.Mesh((0, 0, 0), (5, 5, 5), (1, 1, 1)) system.m = df.Field(mesh, dim=3, value=(0, 1, 0), norm=1) script = system._script assert script[-1] == "\n" assert "mu0mm" in script assert "SetGridSize(5, 5, 5)" in script assert "SetCellSize(1, 1, 1)" in script assert "Aex=1e-12" in script assert "enabledemag=true" in script assert "B_ext=vector(0*mu0mm,1000000.0*mu0mm,0*mu0mm)" in script assert "Ku1=1000.0" in script assert "Ku2=0" in script assert "anisu=vector(0,1,0)" in script return None
def test_script_no_pbc(self): for p1, p2, cell in self.valid_args: name = "test_mesh" mesh = oc.Mesh(p1, p2, cell, name=name) script = mesh._script assert len(re.findall("SetGridSize" + coord_regex, script)) == 1 assert len(re.findall("SetCellSize" + coord_regex, script)) == 1
def minimise_system_energy(L, m_init): N = 16 # discretisation in one dimension cubesize = 100e-9 # cube edge length (m) cellsize = cubesize / N # discretisation in all three dimensions. lex = cubesize / L # exchange length. Km = 1e6 # magnetostatic energy density (J/m**3) Ms = np.sqrt(2 * Km / mc.mu0) # magnetisation saturation (A/m) A = 0.5 * mc.mu0 * Ms**2 * lex**2 # exchange energy constant K = 0.1 * Km # Uniaxial anisotropy constant u = (0, 0, 1) # Uniaxial anisotropy easy-axis p1 = (0, 0, 0) # Minimum sample coordinate. p2 = (cubesize, cubesize, cubesize) # Maximum sample coordinate. cell = (cellsize, cellsize, cellsize) # Discretisation. mesh = mc.Mesh(p1=(0, 0, 0), p2=(cubesize, cubesize, cubesize), cell=(cellsize, cellsize, cellsize)) # Remove any previous simulation directories. if os.path.exists(name): shutil.rmtree(name) system = mc.System(name=name) system.hamiltonian = mc.Exchange(A) + mc.UniaxialAnisotropy(K, u) + \ mc.Demag() system.m = df.Field(mesh, value=m_init, norm=Ms) md = mc.RelaxDriver() md.drive(system) if os.path.exists(name): shutil.rmtree(name) return system
def setup(self): self.system = oc.System(name='tds') mesh = oc.Mesh((0, 0, 0), (100e-9, 100e-9, 10e-9), (10e-9, 10e-9, 10e-9)) self.system.hamiltonian += oc.Exchange(1.5e-11) self.system.hamiltonian += oc.Demag() self.system.dynamics += oc.Precession(2.211e5) self.system.dynamics += oc.Damping(0.02) self.system.m = df.Field(mesh, value=(0, 1, 0), norm=8e5)
def test_skyrmion(): name = "skyrmion" # Remove any previous simulation directories. if os.path.exists(name): shutil.rmtree(name) mesh = mc.Mesh(p1=(-50e-9, -50e-9, 0), p2=(50e-9, 50e-9, 10e-9), cell=(5e-9, 5e-9, 5e-9)) system = mc.System(name="skyrmion") system.hamiltonian = mc.Exchange(A=1.6e-11) + \ mc.DMI(D=4e-3, crystalclass="cnv") + \ mc.UniaxialAnisotropy(K1=0.51e6, K2=0.1, u=(0, 0, 1)) + \ mc.Demag() + \ mc.Zeeman(H=(0, 0, 2e5)) Ms = 1.1e6 def Ms_fun(pos): x, y, z = pos if (x**2 + y**2)**0.5 < 50e-9: return Ms else: return 0 def m_init(pos): x, y, z = pos if (x**2 + y**2)**0.5 < 10e-9: return (0, 0.1, -1) else: return (0, 0.1, 1) system.m = df.Field(mesh, value=m_init, norm=Ms_fun) md = mc.MinDriver() md.drive(system) # Check the magnetisation at the sample centre. assert system.m((0, 0, 0))[2] / Ms < -0.97 # Check the magnetisation at the sample edge. assert system.m((50e-9, 0, 0))[2] / Ms > 0 shutil.rmtree(name)
def test_total_energy(self): system = mc.System(name="test_system") system.hamiltonian += mc.Exchange(1e-12) system.hamiltonian += mc.UniaxialAnisotropy(1e3, (0, 1, 0)) system.hamiltonian += mc.Zeeman((0, 1e6, 0)) system.dynamics += mc.Precession(2.211e5) system.dynamics += mc.Damping(0.1) mesh = mc.Mesh((0, 0, 0), (5, 5, 5), (1, 1, 1)) system.m = df.Field(mesh, dim=3, value=(0, 1, 0), norm=1) with pytest.raises(AttributeError): system.total_energy() return None
#import oommfc as mc import mumaxc as mc import discretisedfield as df L = 10e-9 d = 1e-9 Ms = 8e6 # saturation magnetisation (A/m) A = 1e-12 # exchange energy constant (J/m) H = (5e6, 0, 0) # external magnetic field in the x-direction (A/m) gamma = 2.211e5 # gamma parameter (m/As) alpha = 0.2 # Gilbert damping mesh = mc.Mesh(p1=(0, 0, 0), p2=(L, L, L), cell=(d, d, d)) system = mc.System(name='example2') system.hamiltonian = mc.Exchange(A=A) + mc.Demag() + mc.Zeeman(H=H) system.dynamics = mc.Precession(gamma=gamma) + mc.Damping(alpha=alpha) system.m = df.Field(mesh, value=(0, 0, 1), norm=Ms) td = mc.TimeDriver() td.drive(system, t=1e-9, n=10, overwrite=True) mx, my, mz = system.m.average assert mx > my assert mx > mz print(system.m.average)
def test_stdprob4(): name = "stdprob4" # Remove any previous simulation directories. if os.path.exists(name): shutil.rmtree(name) L, d, th = 500e-9, 125e-9, 3e-9 # (m) cellsize = (5e-9, 5e-9, 3e-9) # (m) mesh = mc.Mesh((0, 0, 0), (L, d, th), cellsize) system = mc.System(name=name) A = 1.3e-11 # (J/m) system.hamiltonian = mc.Exchange(A) + mc.Demag() gamma = 2.211e5 # (m/As) alpha = 0.02 system.dynamics = mc.Precession(gamma) + mc.Damping(alpha) Ms = 8e5 # (A/m) system.m = df.Field(mesh, value=(1, 0.25, 0.1), norm=Ms) md = mc.MinDriver() md.drive(system) # updates system.m in-place dirname = os.path.join(name, "drive-{}".format(system.drive_number - 1)) mx3filename = os.path.join(dirname, "{}.mx3".format(name)) assert os.path.exists(dirname) assert os.path.isfile(mx3filename) omf_files = list(glob.iglob("{}/**/*.o*f".format(dirname), recursive=True)) txt_files = list(glob.iglob("{}/**/*.txt".format(dirname), recursive=True)) assert len(omf_files) == 3 omffilename = os.path.join(dirname, "m0.omf") assert omffilename in omf_files assert len(txt_files) == 2 shutil.rmtree(name) H = (-24.6e-3 / mc.mu0, 4.3e-3 / mc.mu0, 0) system.hamiltonian += mc.Zeeman(H) td = mc.TimeDriver() td.drive(system, t=1e-9, n=200) dirname = os.path.join(name, "drive-{}".format(system.drive_number - 1)) mx3filename = os.path.join(dirname, "{}.mx3".format(name)) assert os.path.exists(dirname) assert os.path.isfile(mx3filename) omf_files = list(glob.iglob("{}/**/*.o*f".format(dirname), recursive=True)) txt_files = list(glob.iglob("{}/**/*.txt".format(dirname), recursive=True)) assert len(omf_files) == 202 omffilename = os.path.join(dirname, "m0.omf") assert omffilename in omf_files assert len(txt_files) == 2 t = system.dt["t"].values my = system.dt["my"].values assert abs(min(t) - 5e-12) < 1e-20 assert abs(max(t) - 1e-9) < 1e-20 # Eye-norm test. assert 0.7 < max(my) < 0.8 assert -0.5 < min(my) < -0.4 shutil.rmtree(name)