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 __init__(self, A=20e-12, Ms=0.648, B=0.1, L=400e-9, thickness=100e-9, init_state_radius=80e-9, cell=(4e-9, 4e-9, 4e-9)): self.A = A self.Ms = Ms / mu0 self.Ku = A / 2.3e-16 self.B = B self.L = L self.thickness = thickness print('Exch length lex = ', 1e9 * np.sqrt(2 * self.A / (mu0 * self.Ms**2)), 'nm') self.mesh = oc.Mesh(p1=(-self.L / 2, -self.L / 2, -self.thickness / 2), p2=(self.L / 2, self.L / 2, self.thickness / 2), cell=cell) self.system = oc.System(name='oommf_typeII_bubble') # Add interactions self.system.hamiltonian = ( oc.Exchange(A=self.A) + oc.UniaxialAnisotropy(K1=self.Ku, u=(0, 0, 1)) + oc.Demag() + oc.Zeeman((0, 0, self.B / mu0))) self.system.m = df.Field( self.mesh, value=lambda r: init_type2bubble_bls_II(r, init_state_radius), norm=self.Ms) # self.system.m = df.Field(self.mesh, value=(0, 0.1, 0.99), # norm=self.Ms) self.md = oc.MinDriver() # Get system cordinates self.coordinates = np.array(list(self.system.m.mesh.coordinates)) # Turn coordinates into a (N, 3) array and save in corresponding # variables scaled in nm self.x, self.y, self.z = (self.coordinates[:, 0] * 1e9, self.coordinates[:, 1] * 1e9, self.coordinates[:, 2] * 1e9) # Array with uniue z coordinates self.xs = np.unique(self.x) self.ys = np.unique(self.y) self.zs = np.unique(self.z) self.z_layers = {} for i, z in enumerate(self.zs): self.z_layers[i] = '{:.2f} nm'.format(z) # Compute the initial magnetisation profile self.compute_magnetisation()
def setup(self): self.name = "derive_tests" if os.path.exists(self.name): shutil.rmtree(self.name) self.system = oc.System(name=self.name) self.system.hamiltonian += oc.Exchange(A=1e-12) self.system.hamiltonian += oc.Demag() self.system.hamiltonian += oc.Zeeman(H=(8e6, 0, 0)) self.system.hamiltonian += oc.UniaxialAnisotropy(K1=1e4, u=(0, 0, 1)) mesh = oc.Mesh(p1=(0, 0, 0), p2=(4e-9, 4e-9, 2e-9), cell=(1e-9, 1e-9, 1e-9)) self.system.m = df.Field(mesh, value=(0, 0, 1), norm=8e6)
def setup(self): A = 1e-12 self.exchange = oc.Exchange(A) H = (0, 0, 1.2e6) self.zeeman = oc.Zeeman(H) K = 1e4 u = (0, 1, 0) self.uniaxialanisotropy = oc.UniaxialAnisotropy(K, u) self.demag = oc.Demag() self.terms = [self.exchange, self.zeeman, self.uniaxialanisotropy, self.demag]
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_skyrmion(): name = "skyrmion" # Remove any previous simulation directories. if os.path.exists(name): shutil.rmtree(name) mesh = oc.Mesh(p1=(-50e-9, -50e-9, 0), p2=(50e-9, 50e-9, 10e-9), cell=(5e-9, 5e-9, 5e-9)) system = oc.System(name="skyrmion") system.hamiltonian = oc.Exchange(A=1.6e-11) + \ oc.DMI(D=4e-3, kind="interfacial") + \ oc.UniaxialAnisotropy(K1=0.51e6, K2=0.1, u=(0, 0, 1)) + \ oc.Demag() + \ oc.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 = oc.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_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 test_script(self): for H in self.valid_args: zeeman = oc.Zeeman(H=H) script = zeeman._script assert script.count("\n") == 10 assert script[0] == "#" assert script[-1] == "\n" lines = script.split("\n") assert len(lines) == 11 assert lines[0] == "# FixedZeeman" assert lines[1] == "Specify Oxs_FixedZeeman {" assert lines[2] == " field {" assert lines[3] == " Oxs_UniformVectorField {" assert lines[4] == " vector {{{} {} {}}}".format(*H) assert lines[5] == " }" assert lines[6] == " }" assert lines[7] == " multiplier 1" assert lines[8] == "}"
def test_script(self): for H in self.valid_args: name = 'zeeman_test' zeeman = oc.Zeeman(H, name=name) script = zeeman.script() assert script.count("\n") == 10 assert script[0] == "#" assert script[-1] == "\n" lines = script.split("\n") assert len(lines) == 11 assert lines[0] == "# FixedZeeman" assert lines[1] == "Specify Oxs_FixedZeeman:{} {{".format(name) assert lines[2] == " field {" assert lines[3] == " Oxs_UniformVectorField {" assert lines[4] == " vector {{{} {} {}}}".format( H[0], H[1], H[2]) assert lines[5] == " }" assert lines[6] == " }" assert lines[7] == " multiplier 1" assert lines[8] == "}"
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
name = "test_sample" # Remove any previous simulation directories. 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)
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)