Пример #1
0
    def test_get_mif(self):
        for p1, p2, cell in self.valid_args:
            name = "test_mesh"

            mesh = oc.Mesh(p1, p2, cell, name=name)

            script = mesh._script
            assert script.count("\n") == 14
            assert script[0] == "#"
            assert script[-1] == "\n"

            lines = script.split("\n")
            assert len(lines) == 15

            # Assert BoxAtlas script
            assert lines[0] == "# BoxAtlas"
            assert lines[1] == "Specify Oxs_BoxAtlas:atlas {"
            assert lines[2] == "  xrange {{{} {}}}".format(mesh.pmin[0],
                                                           mesh.pmax[0])
            assert lines[3] == "  yrange {{{} {}}}".format(mesh.pmin[1],
                                                           mesh.pmax[1])
            assert lines[4] == "  zrange {{{} {}}}".format(mesh.pmin[2],
                                                           mesh.pmax[2])
            assert lines[5] == "  name atlas"
            assert lines[6] == "}"

            # Empty line between BoxAtlas and RectangularMesh
            assert lines[7] == ""

            # Assert RectangularMesh script
            assert lines[8] == "# RectangularMesh"
            assert lines[9] == "Specify Oxs_RectangularMesh:{} {{".format(name)
            assert lines[10] == "  cellsize {{{} {} {}}}".format(*cell)
            assert lines[11] == "  atlas Oxs_BoxAtlas:atlas"
            assert lines[12] == "}"
Пример #2
0
    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
Пример #3
0
def test_relax_with_cubicanisotropy():
    name = "cubic_anisotropy"
    L = 100e-9
    d = 5e-9
    Ms = 8e6

    # Remove any previous simulation directories.
    if os.path.exists(name):
        shutil.rmtree(name)

    system = oc.System(name=name)
    system.hamiltonian = oc.CubicAnisotropy(K1=5e6, u1=(1, 0, 0), u2=(0, 1, 0))

    mesh = oc.Mesh(p1=(0, 0, 0), p2=(L, L, L), cell=(d, d, d))

    def m_init(pos):
        x, y, z = pos
        if x < 30e-9:
            return (0.7, 0.1, 0.3)
        elif x > 70e-9:
            return (0.1, 0.7, 0.3)
        else:
            return (0.3, 0.1, 0.7)

    system.m = df.Field(mesh, value=m_init, norm=Ms)

    md = oc.MinDriver()
    md.drive(system)

    comp_value = 0.99 * Ms
    assert system.m((10e-9, 0, 0))[0] > comp_value
    assert system.m((50e-9, 0, 0))[2] > comp_value
    assert system.m((80e-9, 0, 0))[1] > comp_value

    shutil.rmtree(name)
Пример #4
0
    def test_get_mif(self):
        for arg in self.valid_args:
            p1 = arg[0]
            p2 = arg[1]
            cell = arg[2]
            name = "test_mesh"

            mesh = oc.Mesh(p1, p2, cell, name=name)

            script = mesh.script()
            assert script.count("\n") == 13
            assert script[0] == "#"
            assert script[-1] == "\n"

            lines = script.split("\n")
            assert len(lines) == 14

            # Assert BoxAtlas script
            assert lines[0] == "# BoxAtlas"
            assert lines[1] == "Specify Oxs_BoxAtlas:atlas {"
            assert lines[2] == "  xrange {{{} {}}}".format(p1[0], p2[0])
            assert lines[3] == "  yrange {{{} {}}}".format(p1[1], p2[1])
            assert lines[4] == "  zrange {{{} {}}}".format(p1[2], p2[2])
            assert lines[5] == "}"

            # Empty line between BoxAtlas and RectangularMesh
            assert lines[6] == ""

            # Assert RectangularMesh script
            assert lines[7] == "# RectangularMesh"
            assert lines[8] == "Specify Oxs_RectangularMesh:{} {{".format(name)
            assert lines[9] == "  cellsize {{{} {} {}}}".format(
                cell[0], cell[1], cell[2])
            assert lines[10] == "  atlas Oxs_BoxAtlas:atlas"
            assert lines[11] == "}"
Пример #5
0
    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
Пример #6
0
    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()
Пример #7
0
 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)
Пример #8
0
    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)
Пример #9
0
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)
Пример #10
0
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
Пример #11
0
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
Пример #12
0
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)
Пример #13
0
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)
Пример #14
0
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)
Пример #15
0
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
Пример #16
0
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)
Пример #17
0
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)
Пример #18
0
import os
import shutil
import oommfc as oc
import discretisedfield as df

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)
Пример #19
0
l_ex = np.sqrt(2 * A / (4 * np.pi * 1e-7 * Ms**2))  # Exchange Length

# Geometry parameters
d = 0.1 * l_ex
L = 5.0 * d
t = 0.1 * d
h = d / 20

assert h < (l_ex / 3.0)
print(f"Exchange Length = {l_ex}")
print(f"d / l_ex = {d/l_ex}")
print(f"H = {H}")

H_field = H * np.array([1, 1, 1]) / np.sqrt(
    3)  # external magnetic field in the x-direction (A/m)
gamma = 2.211e5  # gamma parameter (m/As)
alpha = 1.0  # Gilbert damping

mesh = mc.Mesh(p1=(0, 0, 0), p2=(L, d, t), cell=(h, h, h))
system = mc.System(name='stdprob2')
system.hamiltonian = mc.Exchange(A=A) + mc.Demag() + mc.Zeeman(H=H_field)
system.dynamics = mc.Precession(gamma=gamma) + mc.Damping(alpha=alpha)
system.m = df.Field(mesh, value=(0, 0, 1), norm=Ms)

md = mc.MinDriver()
md.drive(system, overwrite=True)

mx, my, mz = system.m.average

system.m.plot_plane("z")