def test_script(self): system = oc.System(name="test_system") system.mesh = oc.Mesh((0, 0, 0), (5, 5, 5), (1, 1, 1)) system.hamiltonian += oc.Exchange(1e-12) system.hamiltonian += oc.Demag() system.hamiltonian += oc.UniaxialAnisotropy(1e3, (0, 1, 0)) system.hamiltonian += oc.Zeeman((0, 1e6, 0)) system.dynamics += oc.Precession(2.211e5) system.dynamics += oc.Damping(0.1) system.m = lambda pos: (0, 1, 0) script = system.script() assert script[0] == "#" assert script[-1] == "\n" assert script.count("#") == 6 assert script.count("Specify") == 6 assert "Exchange" in script assert "Demag" in script assert "Zeeman" in script assert "UniaxialAnisotropy" in script assert "BoxAtlas" in script assert "RectangularMesh" in script
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_script_missing_terms(self): # Missing Gilbert damping alpha self.system.dynamics = oc.Precession(gamma=2.2) td = oc.TimeDriver() script = td.script(self.system, t=1e-9, n=20) assert "alpha 0" in script assert "gamma_G 2.2" in script # Missing gamma self.system.dynamics = oc.Damping(alpha=5) td = oc.TimeDriver() script = td.script(self.system, t=1e-9, n=20) assert "alpha 5" in script assert "gamma_G 221100" in script
def test_stdprob5(): name = "stdprob5" # Remove any previous simulation directories. if os.path.exists(name): shutil.rmtree(name) # Geometry lx = 100e-9 # x dimension of the sample(m) ly = 100e-9 # y dimension of the sample (m) lz = 10e-9 # sample thickness (m) # Material (permalloy) parameters Ms = 8e5 # saturation magnetisation (A/m) A = 1.3e-11 # exchange energy constant (J/m) # Dynamics (LLG + STT equation) parameters gamma = 2.211e5 # gyromagnetic ratio (m/As) alpha = 0.1 # Gilbert damping ux = -72.35 # velocity in x direction beta = 0.05 # non-adiabatic STT parameter system = oc.System(name=name) mesh = oc.Mesh(p1=(0, 0, 0), p2=(100e-9, 100e-9, 10e-9), cell=(5e-9, 5e-9, 5e-9)) system.mesh = mesh system.hamiltonian = oc.Exchange(A) + oc.Demag() def m_vortex(pos): x, y, z = pos[0] / 1e-9 - 50, pos[1] / 1e-9 - 50, pos[2] / 1e-9 return (-y, x, 10) system.m = df.Field(mesh, value=m_vortex, normalisedto=Ms) md = oc.MinDriver() md.drive(system) system.dynamics += oc.Precession(gamma) + oc.Damping(alpha) + \ oc.STT(u=(ux, 0, 0), beta=beta) td = oc.TimeDriver() td.drive(system, t=8e-9, n=100) mx = system.dt["mx"].as_matrix() assert -0.03 < mx.max() < 0 assert -0.35 < mx.min() < -0.30 shutil.rmtree(name)
def macrospin(): """Return a sytsem that represents a macrospin. """ p1 = (0, 0, 0) p2 = (5e-9, 5e-9, 5e-9) cell = (5e-9, 5e-9, 5e-9) mesh = oc.Mesh(p1=p1, p2=p2, cell=cell) system = oc.System(name="example-macrospin") system.hamiltonian = oc.Zeeman(H=(0, 0, 5e6)) system.m = df.Field(mesh, value=(0, 0, 1), norm=8e6) system.dynamics = oc.Precession(gamma=oc.gamma) + oc.Damping(alpha=0.05) return system
def bar(): system = oc.System(name="example-bar") shape = (100e-9, 30e-9, 30e-9) d = 10e-9 mesh = oc.Mesh(p1=(0, 0, 0), p2=shape, cell=(d, d, d)) # Permalloy A = 1e-12 H = (0, 0, 0) # no Zeeman field, but provide interaction as convenience system.hamiltonian = oc.Exchange(A=A) + oc.Demag() + oc.Zeeman(H=H) alpha = 0.2 system.dynamics = oc.Precession(gamma=oc.gamma0) + oc.Damping(alpha=alpha) Ms = 8e6 # A/m system.m = df.Field(mesh, value=(1, 0, 1), norm=Ms) return system
def test_stdprobfmr(): name = "stdprobfmr" # Remove any previous simulation directories. if os.path.exists(name): shutil.rmtree(name) lx = ly = 120e-9 # x and y dimensions of the sample(m) lz = 10e-9 # sample thickness (m) dx = dy = dz = 10e-9 # discretisation in x, y, and z directions (m) Ms = 8e5 # saturation magnetisation (A/m) A = 1.3e-11 # exchange energy constant (J/m) H = 8e4 * np.array([0.81345856316858023, 0.58162287266553481, 0.0]) alpha = 0.008 # Gilbert damping gamma = 2.211e5 mesh = oc.Mesh(p1=(0, 0, 0), p2=(lx, ly, lz), cell=(dx, dy, dz)) system = oc.System(name="stdprobfmr") system.hamiltonian = oc.Exchange(A) + oc.Demag() + oc.Zeeman(H) system.dynamics = oc.Precession(gamma) + oc.Damping(alpha) system.m = df.Field(mesh, value=(0, 0, 1), norm=Ms) md = oc.MinDriver() md.drive(system) H = 8e4 * np.array([0.81923192051904048, 0.57346234436332832, 0.0]) system.hamiltonian.zeeman.H = H T = 20e-9 n = 4000 td = oc.TimeDriver() td.drive(system, t=T, n=n) t = system.dt['t'].as_matrix() my = system.dt['mx'].as_matrix() psd = np.log10(np.abs(scipy.fftpack.fft(my))**2) f_axis = scipy.fftpack.fftfreq(4000, d=20e-9/4000) shutil.rmtree(name)
def macrospin(): """Return a sytsem that represents a macrospin.""" # define macro spin (i.e. one discretisation cell) p1 = (0, 0, 0) # all lengths in metre p2 = (5e-9, 5e-9, 5e-9) cell = (5e-9, 5e-9, 5e-9) mesh = oc.Mesh(p1=p1, p2=p2, cell=cell) initial_m = (1, 0, 0) # vector in x direction Ms = 8e6 # magnetisation saturation (A/m) m = df.Field(mesh, value=initial_m, norm=Ms) zeeman = oc.Zeeman(H=(0, 0, 5e6)) # external magnetic field (A/m) gamma = 2.211e5 # gyrotropic ratio alpha = 0.05 # Gilbert damping runid = "example-macrospin" system = oc.System(name=runid) system.hamiltonian = zeeman system.m = m system.dynamics = oc.Precession(gamma) + oc.Damping(alpha) return system
if os.path.exists(name): shutil.rmtree(name) L = 30e-9 # (m) cellsize = (10e-9, 15e-9, 5e-9) # (m) mesh = oc.Mesh((0, 0, 0), (L, L, L), cellsize) system = oc.System(name=name) A = 1.3e-11 # (J/m) H = (1e6, 0.0, 2e5) system.hamiltonian = oc.Exchange(A=A) + oc.Zeeman(H=H) gamma = 2.211e5 # (m/As) alpha = 0.02 system.dynamics = oc.Precession(gamma) + oc.Damping(alpha) Ms = 8e5 # (A/m) system.m = df.Field(mesh, value=(0.0, 0.25, 0.1), norm=Ms) td = oc.TimeDriver() td.drive(system, t=25e-12, n=25) # updates system.m in-place td.drive(system, t=15e-12, n=15) td.drive(system, t=5e-12, n=10) md = oc.MinDriver() md.drive(system) system.hamiltonian.zeeman.H = (0.0, 0.0, 1.0e6) td.drive(system, t=5e-12, n=5) md.drive(system)
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 = oc.Mesh((0, 0, 0), (L, d, th), cellsize) system = oc.System(name=name) A = 1.3e-11 # (J/m) system.hamiltonian = oc.Exchange(A) + oc.Demag() gamma = 2.211e5 # (m/As) alpha = 0.02 system.dynamics = oc.Precession(gamma) + oc.Damping(alpha) Ms = 8e5 # (A/m) system.m = df.Field(mesh, value=(1, 0.25, 0.1), norm=Ms) md = oc.MinDriver() md.drive(system) # updates system.m in-place dirname = os.path.join(name, "") miffilename = os.path.join(name, "{}.mif".format(name)) assert os.path.exists(dirname) assert os.path.isfile(miffilename) omf_files = list(glob.iglob("{}/*.omf".format(name))) odt_files = list(glob.iglob("{}/*.odt".format(name))) assert len(omf_files) == 2 omffilename = os.path.join(name, "m0.omf") assert omffilename in omf_files assert len(odt_files) == 1 shutil.rmtree(name) H = (-24.6e-3/oc.mu0, 4.3e-3/oc.mu0, 0) system.hamiltonian += oc.Zeeman(H) td = oc.TimeDriver() td.drive(system, t=1e-9, n=200) dirname = os.path.join(name, "") miffilename = os.path.join(name, "{}.mif".format(name)) assert os.path.exists(dirname) assert os.path.isfile(miffilename) omf_files = list(glob.iglob("{}/*.omf".format(name))) odt_files = list(glob.iglob("{}/*.odt".format(name))) assert len(omf_files) == 201 omffilename = os.path.join(name, "m0.omf") assert omffilename in omf_files assert len(odt_files) == 1 myplot = system.dt.plot("t", "my") figfilename = os.path.join(name, "stdprob4-t-my.pdf") myplot.figure.savefig(figfilename) assert os.path.isfile(figfilename) t = system.dt["t"].as_matrix() my = system.dt["my"].as_matrix() 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)
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_script(self): for gamma in self.valid_args: precession = oc.Precession(gamma) with pytest.raises(NotImplementedError): precession._script()