Exemplo n.º 1
0
    def test_script(self):
        system = mc.System(name="test_system")

        system.hamiltonian += mc.Exchange(1e-12)
        system.hamiltonian += mc.Demag()
        system.hamiltonian += mc.UniaxialAnisotropy(1e3, (0, 1, 0))
        system.hamiltonian += mc.Zeeman((0, 1e6, 0))

        system.dynamics += mc.Precession(2.211e5)
        system.dynamics += mc.Damping(0.1)

        mesh = mc.Mesh((0, 0, 0), (5, 5, 5), (1, 1, 1))

        system.m = df.Field(mesh, dim=3, value=(0, 1, 0), norm=1)

        script = system._script

        assert script[-1] == "\n"
        assert "mu0mm" in script
        assert "SetGridSize(5, 5, 5)" in script
        assert "SetCellSize(1, 1, 1)" in script
        assert "Aex=1e-12" in script
        assert "enabledemag=true" in script
        assert "B_ext=vector(0*mu0mm,1000000.0*mu0mm,0*mu0mm)" in script
        assert "Ku1=1000.0" in script
        assert "Ku2=0" in script
        assert "anisu=vector(0,1,0)" in script

        return None
Exemplo n.º 2
0
    def test_script(self):
        for H in self.valid_args:
            zeeman = mc.Zeeman(H=H)

            script = zeeman._script
            assert script.count("\n") == 3
            assert script[0:2] == "//"
            assert script[-1] == "\n"

            lines = script.split("\n")
            assert len(lines) == 4
            assert lines[0] == "// Zeeman"
            assert lines[
                1] == "B_ext=vector({}*mu0mm,{}*mu0mm,{}*mu0mm)".format(*H)
Exemplo n.º 3
0
def test_skyrmion():
    name = "skyrmion"

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

    mesh = mc.Mesh(p1=(-50e-9, -50e-9, 0),
                   p2=(50e-9, 50e-9, 10e-9),
                   cell=(5e-9, 5e-9, 5e-9))

    system = mc.System(name="skyrmion")
    system.hamiltonian = mc.Exchange(A=1.6e-11) + \
        mc.DMI(D=4e-3, crystalclass="cnv") + \
        mc.UniaxialAnisotropy(K1=0.51e6, K2=0.1, u=(0, 0, 1)) + \
        mc.Demag() + \
        mc.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 = mc.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)
Exemplo n.º 4
0
    def test_total_energy(self):
        system = mc.System(name="test_system")

        system.hamiltonian += mc.Exchange(1e-12)
        system.hamiltonian += mc.UniaxialAnisotropy(1e3, (0, 1, 0))
        system.hamiltonian += mc.Zeeman((0, 1e6, 0))

        system.dynamics += mc.Precession(2.211e5)
        system.dynamics += mc.Damping(0.1)

        mesh = mc.Mesh((0, 0, 0), (5, 5, 5), (1, 1, 1))

        system.m = df.Field(mesh, dim=3, value=(0, 1, 0), norm=1)

        with pytest.raises(AttributeError):
            system.total_energy()

        return None
Exemplo n.º 5
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)
Exemplo n.º 6
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 = mc.Mesh((0, 0, 0), (L, d, th), cellsize)

    system = mc.System(name=name)

    A = 1.3e-11  # (J/m)
    system.hamiltonian = mc.Exchange(A) + mc.Demag()

    gamma = 2.211e5  # (m/As)
    alpha = 0.02
    system.dynamics = mc.Precession(gamma) + mc.Damping(alpha)

    Ms = 8e5  # (A/m)
    system.m = df.Field(mesh, value=(1, 0.25, 0.1), norm=Ms)

    md = mc.MinDriver()
    md.drive(system)  # updates system.m in-place

    dirname = os.path.join(name, "drive-{}".format(system.drive_number - 1))
    mx3filename = os.path.join(dirname, "{}.mx3".format(name))
    assert os.path.exists(dirname)
    assert os.path.isfile(mx3filename)

    omf_files = list(glob.iglob("{}/**/*.o*f".format(dirname), recursive=True))
    txt_files = list(glob.iglob("{}/**/*.txt".format(dirname), recursive=True))

    assert len(omf_files) == 3
    omffilename = os.path.join(dirname, "m0.omf")
    assert omffilename in omf_files

    assert len(txt_files) == 2
    shutil.rmtree(name)

    H = (-24.6e-3 / mc.mu0, 4.3e-3 / mc.mu0, 0)
    system.hamiltonian += mc.Zeeman(H)

    td = mc.TimeDriver()
    td.drive(system, t=1e-9, n=200)

    dirname = os.path.join(name, "drive-{}".format(system.drive_number - 1))
    mx3filename = os.path.join(dirname, "{}.mx3".format(name))
    assert os.path.exists(dirname)
    assert os.path.isfile(mx3filename)

    omf_files = list(glob.iglob("{}/**/*.o*f".format(dirname), recursive=True))
    txt_files = list(glob.iglob("{}/**/*.txt".format(dirname), recursive=True))

    assert len(omf_files) == 202
    omffilename = os.path.join(dirname, "m0.omf")
    assert omffilename in omf_files

    assert len(txt_files) == 2

    t = system.dt["t"].values
    my = system.dt["my"].values

    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)