Ejemplo 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
Ejemplo n.º 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 / mc.mu0)  # magnetisation saturation (A/m)
        A = 0.5 * mc.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 = mc.Mesh(p1=(0, 0, 0),
                       p2=(cubesize, cubesize, cubesize),
                       cell=(cellsize, cellsize, cellsize))

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

        system = mc.System(name=name)
        system.hamiltonian = mc.Exchange(A) + mc.UniaxialAnisotropy(K, u) + \
            mc.Demag()
        system.m = df.Field(mesh, value=m_init, norm=Ms)

        md = mc.RelaxDriver()
        md.drive(system)

        if os.path.exists(name):
            shutil.rmtree(name)

        return system
Ejemplo n.º 3
0
    def test_script(self):
        for K1, K2, u in self.valid_args:
            anisotropy = mc.UniaxialAnisotropy(K1=K1, K2=K2, u=u)
            script = anisotropy._script

            assert script[0:2] == "//"
            assert script[-1] == "\n"
            lines = script.split("\n")
            assert lines[0] == "// UniaxialAnisotropy"
            assert lines[1] == "Ku1={}".format(K1)
            assert lines[2] == "Ku2={}".format(K2)
            assert lines[3] == "anisu=vector({},{},{})".format(*u)

            assert script.count("\n") == 5
            assert len(lines) == 6
Ejemplo n.º 4
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)
Ejemplo n.º 5
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