示例#1
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
示例#2
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
示例#3
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()
示例#4
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)
示例#5
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)
示例#6
0
    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]
示例#7
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)
示例#8
0
    def test_script(self):
        for A in self.valid_args:
            exchange = oc.Exchange(A)

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

            lines = script.split("\n")
            assert len(lines) == 6
            assert lines[0] == "# UniformExchange"
            assert lines[1] == "Specify Oxs_UniformExchange {"
            assert lines[2] == "  A {}".format(A)
            assert lines[3] == "}"
示例#9
0
文件: bar.py 项目: gamdow/oommfc
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
示例#10
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)
示例#11
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)
示例#12
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)
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)
示例#14
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)
示例#15
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)