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 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 / oc.mu0) # magnetisation saturation (A/m) A = 0.5 * oc.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 = oc.Mesh(p1=(0, 0, 0), p2=(cubesize, cubesize, cubesize), cell=(cellsize, cellsize, cellsize)) system = oc.System(name=name) system.hamiltonian = oc.Exchange(A) + oc.UniaxialAnisotropy(K, u) + \ oc.Demag() system.m = df.Field(mesh, value=m_init, norm=Ms) md = oc.MinDriver() md.drive(system) return system
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 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_script(self): for arg in self.valid_args: K = arg[0] u = arg[1] name = "anisotropy_test" anisotropy = oc.UniaxialAnisotropy(K, u, name=name) script = anisotropy.script() assert script.count("\n") == 6 assert script[0] == "#" assert script[-1] == "\n" lines = script.split("\n") assert len(lines) == 7 assert lines[0] == "# UniaxialAnisotropy" assert lines[1] == "Specify Oxs_UniaxialAnisotropy {" assert lines[2] == " K1 {}".format(K) assert lines[3] == " axis {{{} {} {}}}".format(u[0], u[1], u[2]) assert lines[4] == "}"
def test_script(self): for K1, K2, u in self.valid_args: anisotropy = oc.UniaxialAnisotropy(K1=K1, K2=K2, u=u) script = anisotropy._script assert script[0] == "#" assert script[-1] == "\n" lines = script.split("\n") assert lines[0] == "# UniaxialAnisotropy" assert lines[2] == " K1 {}".format(K1) assert lines[-4] == " axis {{{} {} {}}}".format(*u) assert lines[-3] == "}" if K2 == 0: assert script.count("\n") == 6 assert len(lines) == 7 assert lines[1] == "Specify Oxs_UniaxialAnisotropy {" else: assert script.count("\n") == 7 assert len(lines) == 8 assert lines[1] == "Specify Southampton_UniaxialAnisotropy4 {" assert lines[3] == " K2 {}".format(K2)
def test_stdprob1(): name = "stdprob1" # Geometry lx = 2e-6 # x dimension of the sample(m) ly = 1e-6 # y dimension of the sample (m) lz = 20e-9 # sample thickness (m) # Material parameters Ms = 8e5 # saturation magnetisation (A/m) A = 1.3e-11 # exchange energy constant (J/m) K = 0.5e3 # uniaxial anisotropy constant (J/m**3) u = (1, 0, 0) # uniaxial anisotropy axis # Create a mesh object. mesh = oc.Mesh(p1=(0, 0, 0), p2=(lx, ly, lz), cell=(20e-9, 20e-9, 20e-9)) system = oc.System(name=name) system.hamiltonian = oc.Exchange(A) + oc.UniaxialAnisotropy(K, u) + \ oc.Demag() system.m = df.Field(mesh, value=(-10, -1, 0), norm=Ms) Hmax = (50e-3 / oc.mu0, 0.87275325e-3 / oc.mu0, 0) Hmin = (-50e-3 / oc.mu0, -0.87275325e-3 / oc.mu0, 0) n = 10 hd = oc.HysteresisDriver() hd.drive(system, Hmax=Hmax, Hmin=Hmin, n=n) Bx = system.dt["Bx"].as_matrix() mx = system.dt["mx"].as_matrix() assert len(mx) == 21 assert len(Bx) == 21 shutil.rmtree(name)