Beispiel #1
0
def test_exch_1d():
    """
    Test the x component of the exchange field
    in a 1D mesh, with the spin ordering:

    0 1 2 3 4 5

    """
    mesh = CuboidMesh(nx=5, ny=1, nz=1)
    sim = Sim(mesh)
    exch = Exchange(1.0)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    assert field[0] == 1
    assert field[1 * 3] == 2
    assert field[2 * 3] == 4
    assert field[3 * 3] == 6
    assert field[4 * 3] == 3

    assert np.max(field[2::3]) == 0
    assert np.max(field[1::3]) == 0
Beispiel #2
0
def relax_system(mesh):

    # Only relaxation
    sim = Sim(mesh, name='relax')

    # Simulation parameters
    sim.driver.set_tols(rtol=1e-8, atol=1e-10)
    sim.alpha = 0.5
    sim.driver.gamma = 2.211e5 / mu0
    sim.mu_s = 1e-27 / mu0
    sim.driver.do_precession = False

    # The initial state passed as a function
    sim.set_m(init_m)
    # sim.set_m(np.load('m0.npy'))

    # Energies
    exch = UniformExchange(J=2e-20)
    sim.add(exch)

    anis = Anisotropy(0.01 * 2e-20, axis=(0, 0, 1))
    sim.add(anis)

    # dmi = DMI(D=8e-4)
    # sim.add(dmi)

    # Start relaxation and save the state in m0.npy
    sim.relax(dt=1e-14,
              stopping_dmdt=1e4,
              max_steps=5000,
              save_m_steps=None,
              save_vtk_steps=None)

    np.save('m0.npy', sim.spin)
Beispiel #3
0
def test_dynamic():

    mesh = CuboidMesh(nx=1, ny=1, nz=1)

    sim = Sim(mesh, name='dyn_spin', driver='llg_stt_cpp')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m((0.8, 0, -1))

    Kx = Anisotropy(Ku=-0.05, axis=(0, 0, 1), name='Kz')
    sim.add(Kx)

    sim.p = (0, 0, 1)

    sim.a_J = 0.0052
    sim.alpha = 0.1

    ts = np.linspace(0, 1200, 401)
    for t in ts:
        sim.driver.run_until(t)

    mz = sim.spin[2]
    alpha, K, u = 0.1, 0.05, 0.0052
    print(mz, u / (2 * alpha * K))

    #########################################################
    # The system used in this test can be solved analytically, which gives that mz = u/(2*alpha*K),
    # where K represents the easy-plane anisotropy.
    ###
    assert abs(mz - u / (2 * alpha * K)) / mz < 5e-4
Beispiel #4
0
def dynamic(mesh):

    sim = Sim(mesh, name='dyn', driver='slonczewski')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load('m0.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    Kx = Anisotropy(Ku=0.005, axis=(1, 0, 0), name='Kx')
    sim.add(Kx)

    sim.p = (0,0,1)

    sim.u0 = 0.03
    sim.alpha = 0.1

    ts = np.linspace(0, 1e3, 101)
    for t in ts:
        sim.run_until(t)
        sim.save_vtk()
        print t
Beispiel #5
0
def test_exch_3d():
    """
    Test the exchange field of the spins in this 3D mesh:

    bottom layer:
    8  9  10  11
    4  5  6   7       x 2
    0  1  2   3

    The assertions are the mx component
    of the: 0, 1, 2, .. 7 spins

    Remember the new new ordering: fx1, fy1, fz1, fx2, ...

    """
    mesh = CuboidMesh(nx=4, ny=3, nz=2)
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()
    # print field
    assert field[0] == 1
    assert field[3] == 0 + 1 + 2 + 1
    assert field[6] == 1 + 2 + 3 + 2
    assert field[9] == 2 + 3 + 3

    assert field[4 * 3] == 1
    assert field[5 * 3] == 5
    assert field[6 * 3] == 10
    assert field[7 * 3] == 11
Beispiel #6
0
def dynamic(mesh):

    sim = Sim(mesh, name='dyn', driver='slonczewski')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load('m0.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    Kx = Anisotropy(Ku=0.005, axis=(1, 0, 0), name='Kx')
    sim.add(Kx)

    sim.p = (0, 0, 1)

    sim.u0 = 0.03
    sim.driver.alpha = 0.1

    ts = np.linspace(0, 1e3, 101)
    for t in ts:
        sim.run_until(t)
        sim.save_vtk()
        print t
def relax_system(mesh):

    # Only relaxation
    sim = Sim(mesh, name='relax')

    # Simulation parameters
    sim.driver.set_tols(rtol=1e-8, atol=1e-10)
    sim.alpha = 0.5
    sim.driver.gamma = 2.211e5 / mu0
    sim.mu_s = 1e-27 / mu0
    sim.driver.do_precession = False

    # The initial state passed as a function
    sim.set_m(init_m)
    # sim.set_m(np.load('m0.npy'))

    # Energies
    exch = UniformExchange(J=2e-20)
    sim.add(exch)

    anis = Anisotropy(0.01*2e-20, axis=(0, 0, 1))
    sim.add(anis)

    # dmi = DMI(D=8e-4)
    # sim.add(dmi)

    # Start relaxation and save the state in m0.npy
    sim.relax(dt=1e-14, stopping_dmdt=1e4, max_steps=5000,
              save_m_steps=None, save_vtk_steps=None)

    np.save('m0.npy', sim.spin)
def test_dynamic():

    mesh = CuboidMesh(nx=1, ny=1, nz=1)

    sim = Sim(mesh, name='dyn_spin', driver='llg_stt_cpp')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m((0.8,0,-1))

    Kx = Anisotropy(Ku=-0.05, axis=(0, 0, 1), name='Kz')
    sim.add(Kx)

    sim.p = (0,0,1)

    sim.a_J = 0.0052
    sim.alpha = 0.1

    ts = np.linspace(0, 1200, 401)
    for t in ts:
        sim.driver.run_until(t)


    mz = sim.spin[2]
    alpha, K, u = 0.1, 0.05, 0.0052
    print(mz, u/(2*alpha*K))

    #########################################################
    # The system used in this test can be solved analytically, which gives that mz = u/(2*alpha*K),
    # where K represents the easy-plane anisotropy.
    ###
    assert abs(mz - u/(2*alpha*K))/mz< 5e-4
Beispiel #9
0
def relax_system(mesh):

    sim = Sim(mesh, name='relax')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.driver.alpha = 1.0
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(init_m)
    # sim.set_m(random_m)
    # sim.set_m(np.load('m_10000.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    Kx = Anisotropy(Ku=0.005, axis=(1, 0, 0), name='Kx')
    sim.add(Kx)

    sim.relax(dt=2.0,
              stopping_dmdt=1e-6,
              max_steps=1000,
              save_m_steps=100,
              save_vtk_steps=50)

    np.save('m0.npy', sim.spin)
Beispiel #10
0
def test_full_exch_hex_3_shells_lattice_pos():
    """
    Test the x component of the exchange field when using 3 shells of
    neighbours in a 9 x 9 hexagonal lattice with square arrangement

    We set the s_x and s_y spin components as the (i, j) index of the
    lattice positions:
    """
    a = 1
    shells = 3
    mesh = HexagonalMesh(a * 0.5,
                         nx=9,
                         ny=9,
                         shells=shells,
                         alignment='square')
    sim = Sim(mesh)
    # Set the indexes (i, j) as their s_x, s_y position
    sim.set_m(lambda r: init_m(r, a), normalise=False)

    Js = np.ones(shells)
    exch = Exchange(Js)
    sim.add(exch)

    field = exch.compute_field()
    assert field[3 * 0] == (1 + 1 + 0) + (2 + 0) + (2 + 1)  # f_x 1st spin
    assert field[3 * 11] == ((3 + 1 + 2 + 1 + 1 + 2) +
                             (3 + 0 + 2 + 0 + 0 + 3) + (4 + 0 + 3 + 0 + 1 + 0))
Beispiel #11
0
def test_full_exch_hex_2_shells():
    """
    Test the x component of the exchange field when using 2 shells of
    neighbours, comparing the field manually.
    This is similar than the *test_full_exch_hex_9_shells* function but
    here we do not assume that the neighbours indexes are correct
    We set J=1 for NN and J=2 for NNN
    """
    a = 1
    shells = 2
    mesh = HexagonalMesh(a * 0.5,
                         nx=9,
                         ny=9,
                         shells=shells,
                         alignment='square')
    sim = Sim(mesh)
    sim.spin.reshape(-1, 3)[:,
                            0] = np.arange(len(sim.spin.reshape(-1, 3)[:, 0]))
    Js = np.array([1., 2.])
    exch = Exchange(Js)
    sim.add(exch)
    field = exch.compute_field()
    assert field[3 * 0] == 1. * (1 + 10 + 9) + 2. * (11 + 18)
    assert field[3 *
                 11] == (12 + 10 + 20 + 1 + 19 + 2) + 2. * (21 + 29 + 18 + 3)
Beispiel #12
0
def test_exch_2d_pbc2d():
    """
    Test the exchange field components in a 2D mesh with PBCs
    The mesh sites:

            3     4     5    -->    (0,1,0)  (1,1,0)  (2,1,0)
     y ^    0     1     2           (0,0,0)  (1,0,0)  (2,0,0)
       |
       x -->

    The expected components are in increasing order along x

    """

    mesh = CuboidMesh(nx=3, ny=2, nz=1, periodicity=(True, True, False))
    print mesh.neighbours
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    expected_x = np.array([3, 4, 5, 3, 4, 5])
    expected_y = np.array([2, 2, 2, 2, 2, 2])

    # Since the field ordering is now: fx1 fy1 fz1 fx2 ...
    # We extract the x components jumping in steps of 3
    assert np.max(abs(field[::3] - expected_x)) == 0
    # For the y component is similar, now we start at the 1th
    # entry and jump in steps of 3
    assert np.max(abs(field[1::3] - expected_y)) == 0
    # Similar fot he z component
    assert np.max(field[2::3]) == 0
Beispiel #13
0
def test_exch_1d():
    """
    Test the x component of the exchange field
    in a 1D mesh, with the spin ordering:

    0 1 2 3 4 5

    """
    mesh = CuboidMesh(nx=5, ny=1, nz=1)
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    assert field[0] == 1
    assert field[1 * 3] == 2
    assert field[2 * 3] == 4
    assert field[3 * 3] == 6
    assert field[4 * 3] == 3

    assert np.max(field[2::3]) == 0
    assert np.max(field[1::3]) == 0
def test_exch_3d():
    """
    Test the exchange field of the spins in this 3D mesh:

    bottom layer:
    8  9  10  11
    4  5  6   7       x 2
    0  1  2   3

    Assertions are according to the mx component of the spins, since J is set
    to 1


    Spin components are given according to the (i, j) index position in the
    lattice:

           i                lattice site
        [[ 0.  0.  0.]  --> 0    j=0
         [ 1.  0.  0.]  --> 1
         [ 2.  0.  0.]  --> 2
         [ 3.  0.  0.]  --> 3
         [ 0.  1.  0.]  --> 4    j=1
         [ 1.  1.  0.]
         ...

    Remember the field ordering: fx0, fy0, fz0, fx1, ...

    """
    mesh = CuboidMesh(nx=4, ny=3, nz=2)
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()
    # print field

    # Exchange from 0th spin
    assert field[0] == 1

    # Exchange from 1st spin
    #            spin: 2   0   5   13
    #              mx: 2   0   1   1
    assert field[3] == 2 + 0 + 1 + 1

    # Exchange from 2nd spin
    #            spin: 3   1   6   14
    #              mx: 3   1   2   2
    assert field[6] == 3 + 1 + 2 + 2

    # ...
    assert field[9] == 2 + 3 + 3

    assert field[4 * 3] == 1
    assert field[5 * 3] == 5
    assert field[6 * 3] == 10
    assert field[7 * 3] == 11
Beispiel #15
0
def test_sim_spins(do_plot=False):

    mesh = CuboidMesh(nx=10, ny=5, nz=1)

    sim = Sim(mesh, name='10spin')

    alpha = 0.1
    gamma = 2.21e5
    sim.alpha = alpha
    sim.gamma = gamma
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))
    print(sim.spin)

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))

    ts = np.linspace(0, 1e-9, 101)

    mx = []
    my = []
    mz = []
    real_ts = []

    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        #print sim.t, abs(sim.spin_length()[0] - 1)
        av = sim.compute_average()
        mx.append(av[0])
        my.append(av[1])
        mz.append(av[2])

        #sim.save_vtk()

    mz = np.array(mz)
    # print mz
    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    print(sim.stat())

    if do_plot:
        plot(real_ts,
             mx,
             my,
             mz,
             a_mx,
             a_my,
             a_mz,
             name='spins.pdf',
             title='integrating spins')

    print(("Max Deviation = {0}".format(np.max(np.abs(mz - a_mz)))))

    assert np.max(np.abs(mz - a_mz)) < 5e-7
Beispiel #16
0
def test_demag_two_spin_xx():
    mesh = CuboidMesh(nx=2, ny=1, nz=1)
    sim = Sim(mesh)
    demag = Demag()
    sim.add(demag)
    sim.set_m((1, 0, 0))
    field = demag.compute_field()
    print(field)
    assert (field[0] == 2e-7)
    assert (field[3] == 2e-7)
Beispiel #17
0
def test_exch_energy_1d():
    mesh = CuboidMesh(nx=2, ny=1, nz=1)
    sim = Sim(mesh)
    exch = UniformExchange(1.23)
    sim.add(exch)

    sim.set_m((0, 0, 1))

    energy = exch.compute_energy()
    assert energy == -1.23
Beispiel #18
0
def test_demag_two_spin_xx():
    mesh = CuboidMesh(nx=2, ny=1, nz=1)
    sim = Sim(mesh)

    demag = Demag()
    sim.add(demag)

    sim.set_m((1, 0, 0))
    field = demag.compute_field()
    print field
    assert(field[0] == 2e-7)
    assert(field[3] == 2e-7)
Beispiel #19
0
def test_full_exch_hex_9_shells_J_rings():
    """
    Test the x component of the exchange field when using 9 shells of
    neighbours in a 11 X 11 hexagonal lattice with square and diagonal
    arrangement

    We set J=1,2,3,.. for every shell and set the s_x component of the spins as
    the lattice site number:
    [0, 1, 2, 3, ... 120]

    Since we set the s_x components as the lattice position indexes, the x
    component of the field is the sum of the indexes of the neighbours
    (assuming the neighbours indexing is correct) multiplied by J[i] where i is
    the shell (1, 2, ...9), i.e. the 1st shell of ngbs is multiplied by 1,
    the 2nd shell by 2, the 3rd shell by 3, and so on
    """

    for arrang in ['square', 'diagonal']:
        a = 1
        shells = 9
        mesh = HexagonalMesh(a * 0.5,
                             nx=11,
                             ny=11,
                             shells=shells,
                             alignment=arrang)
        sim = Sim(mesh)
        # Set s_x as the lattice site number
        sim.spin.reshape(-1,
                         3)[:,
                            0] = np.arange(len(sim.spin.reshape(-1, 3)[:, 0]))

        # Exchange constants according to the shell
        Js = np.arange(1, 10)
        exch = Exchange(Js)
        sim.add(exch)

        field = exch.compute_field()

        # We only test for the 60th lattice site
        ngbs_60 = mesh.neighbours[60]
        sum_ngbs = mesh._sum_ngbs_shell

        # For every shell, find the ngb indexes in that shell and multiply the
        # sum by the corresponding J=1, 2, 3, ...
        sum_rings = 0
        for i in range(1, shells + 1):
            ngbs_range = slice(sum_ngbs[i - 1], sum_ngbs[i])
            print('J = ', Js[i - 1], '  ngbs indexes: ', ngbs_60[ngbs_range])
            sum_rings += Js[i - 1] * np.sum(ngbs_60[ngbs_range])

        assert field[3 * 60] == sum_rings
Beispiel #20
0
def test_sim_single_spin_sllg(do_plot=False):

    mesh = CuboidMesh(nx=1, ny=1, nz=1)

    sim = Sim(mesh, name='spin', driver='sllg')

    alpha = 0.1
    gamma = 2.21e5

    sim.set_options(dt=5e-15, gamma=gamma)

    sim.alpha = alpha
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))

    ts = np.linspace(0, 1e-10, 101)

    mx = []
    my = []
    mz = []
    real_ts = []
    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        print(sim.t, abs(sim.spin_length()[0] - 1))
        mx.append(sim.spin[0])
        my.append(sim.spin[1])
        mz.append(sim.spin[2])

    mz = np.array(mz)

    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    if do_plot:
        plot(real_ts,
             mx,
             my,
             mz,
             a_mx,
             a_my,
             a_mz,
             name='spin_sllg.pdf',
             title='integrating a spin')

    print(("Max Deviation = {0}".format(np.max(np.abs(mz - a_mz)))))

    assert np.max(np.abs(mz - a_mz)) < 1e-8
Beispiel #21
0
def excite_system(mesh, Hy=0):

    sim = Sim(mesh, name="dyn")

    sim.set_options(rtol=1e-10, atol=1e-12)
    sim.alpha = 0.04
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load("m0.npy"))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.18
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, Hy, 2e-2], name="H")
    sim.add(zeeman)

    hx = TimeZeeman([0, 0, 1e-5], sinc_fun, name="h")
    sim.add(hx, save_field=True)

    dt = 5
    steps = 2001
    for i in range(steps):

        sim.run_until(i * dt)
Beispiel #22
0
def excite_system(mesh, Hy=0):

    sim = Sim(mesh, name='dyn')

    sim.driver.set_tols(rtol=1e-10, atol=1e-12)
    sim.driver.alpha = 0.04
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load('m0.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.18
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, Hy, 2e-2], name='H')
    sim.add(zeeman)

    hx = TimeZeeman([0, 0, 1e-5], sinc_fun, name='h')
    sim.add(hx, save_field=True)

    dt = 5
    steps = 2001
    for i in range(steps):
        sim.run_until(i * dt)
        sim.save_m()
        print("step {}/{}".format(i, steps))
Beispiel #23
0
def test_sim_pin():
    mesh = CuboidMesh(nx=3, ny=2, nz=1)
    sim = Sim(mesh)
    sim.set_m((0, 0.8, 0.6))
    sim.alpha = 0.1
    sim.gamma = 1.0
    sim.pins = pin_fun

    anis = Anisotropy(Ku=1.0, axis=[0, 0, 1], name='Dx')
    sim.add(anis)

    sim.run_until(1.0)
    assert sim.spin[0] == 0
    assert sim.spin[2] != 0
def excite_system(mesh):

    sim = Sim(mesh, name='dyn')

    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.driver.alpha = 0.04
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load('m0.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.09
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, 0, 3.75e-3], name='H')
    sim.add(zeeman)

    w0 = 0.02

    def time_fun(t):
        return np.exp(-w0 * t)

    hx = TimeZeeman([0, 0, 1e-5], sinc_fun, name='h')
    sim.add(hx, save_field=True)

    ts = np.linspace(0, 20000, 5001)
    for t in ts:
        sim.run_until(t)
        print 'sim t=%g' % t
Beispiel #25
0
def test_sim_pin():
    mesh = CuboidMesh(nx=3, ny=2, nz=1)
    sim = Sim(mesh)
    sim.set_m((0, 0.8, 0.6))
    sim.alpha = 0.1
    sim.gamma = 1.0
    sim.pins = pin_fun

    anis = Anisotropy(Ku=1.0, axis=[0, 0, 1], name='Dx')
    sim.add(anis)

    sim.run_until(1.0)
    assert sim.spin[0] == 0
    assert sim.spin[2] != 0
Beispiel #26
0
def excite_system(mesh):

    sim = Sim(mesh, name='dyn')

    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.alpha = 0.04
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load('m0.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.09
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, 0, 3.75e-3], name='H')
    sim.add(zeeman)

    w0 = 0.02

    def time_fun(t):
        return np.exp(-w0 * t)

    hx = TimeZeeman([0, 0, 1e-5], sinc_fun, name='h')
    sim.add(hx, save_field=True)

    ts = np.linspace(0, 20000, 5001)
    for t in ts:
        sim.run_until(t)
        print 'sim t=%g' % t
Beispiel #27
0
def test_sim_spins(do_plot=False):

    mesh = CuboidMesh(nx=10, ny=5, nz=1)

    sim = Sim(mesh, name='10spin')

    alpha = 0.1
    gamma = 2.21e5
    sim.alpha = alpha
    sim.gamma = gamma
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))
    print(sim.spin)

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))

    ts = np.linspace(0, 1e-9, 101)

    mx = []
    my = []
    mz = []
    real_ts = []

    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        #print sim.t, abs(sim.spin_length()[0] - 1)
        av = sim.compute_average()
        mx.append(av[0])
        my.append(av[1])
        mz.append(av[2])

        #sim.save_vtk()

    mz = np.array(mz)
    # print mz
    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    print(sim.stat())

    if do_plot:
        plot(real_ts, mx, my, mz, a_mx, a_my, a_mz, name='spins.pdf', title='integrating spins')

    print(("Max Deviation = {0}".format(
        np.max(np.abs(mz - a_mz)))))

    assert np.max(np.abs(mz - a_mz)) < 5e-7
Beispiel #28
0
def test_exch_1d_pbc():
    mesh = CuboidMesh(nx=5, ny=1, nz=1, periodicity=(True, False, False))
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()
    assert field[0] == 1 + 4
    assert field[3] == 2
    assert field[6] == 4
    assert field[9] == 6
    assert field[12] == 3 + 0
    assert np.max(field[2::3]) == 0
    assert np.max(field[1::3]) == 0
Beispiel #29
0
def disable_test_sim_single_spin_llg_stt(do_plot=False):
    ni = Nickel()
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    mesh.set_material(ni)

    ni.alpha = 0.1
    sim = Sim(mesh, driver='llg_stt')
    sim.set_m((1, 0, 0))

    H0 = 1
    sim.add(Zeeman((0, 0, H0)))

    dt = 1e-12
    ts = np.linspace(0, 200 * dt, 101)

    precession = ni.gamma / (1 + ni.alpha**2)

    mz_ref = []
    mxyz = []
    real_ts = []

    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        print(sim.t, abs(sim.spin_length()[0] - 1), sim.spin)
        mz_ref.append(np.tanh(precession * ni.alpha * H0 * sim.t))
        mxyz.append(np.copy(sim.spin))

    mxyz = np.array(mxyz)

    if do_plot:
        ts_ns = np.array(real_ts) * 1e9

        plt.plot(ts_ns, mxyz[:, 0], ".-", label="mx")
        plt.plot(ts_ns, mxyz[:, 1], ".-", label="my")
        plt.plot(ts_ns, mxyz[:, 2], ".-", label="mz")
        plt.plot(ts_ns, mz_ref, "-", label="analytical")
        plt.xlabel("time (ns)")
        plt.ylabel("mz")
        plt.title("integrating a macrospin")
        plt.legend()
        plt.savefig("test_llg_stt.png")

        print(("Deviation = {0}".format(np.max(np.abs(mxyz[:, 2] - mz_ref)))))

    assert np.max(np.abs(mxyz[:, 2] - mz_ref)) < 1e-9
def relax_system(rtol=1e-10, atol=1e-12):
    """numerical solution"""
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    sim = Sim(mesh, name='relax')
    sim.driver.set_tols(rtol=rtol, atol=atol)
    sim.driver.alpha = 0.5
    sim.driver.gamma = 2.21e5
    sim.mu_s = 1.0

    sim.set_m((1.0, 0, 0))

    sim.add(Zeeman((0, 0, 1e5)))

    ts = np.linspace(0, 1e-9, 1001)

    for t in ts:
        sim.driver.run_until(t)
Beispiel #31
0
def test_hexagonal_demags_2D():
    """
    Comparison of the FFT approach for hexagonal meshes, named
    DemagHexagonal, where it is used a system with the double number
    of nodes along the x direction (i.e. a mesh with twice the number
    of nodes of the original mesh), against the full calculation
    of the Demag field
    """
    # Number of atoms
    N = 15
    a = 0.4
    mesh = HexagonalMesh(a * 0.5, N, N,
                         unit_length=1e-9,
                         alignment='square')

    # Centre
    xc = (mesh.Lx * 0.5)
    yc = (mesh.Ly * 0.5)

    mu_s = 2 * const.mu_B

    sim = Sim(mesh)
    sim.mu_s = mu_s

    sim.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))
    # Brute force demag calculation
    sim.add(DemagFull())

    sim.get_interaction('DemagFull').compute_field()
    sim.get_interaction('DemagFull').field
    DemagFull_energy = sim.compute_energy() / const.meV

    # Demag using the FFT approach and a larger mesh
    sim2 = Sim(mesh)
    sim2.mu_s = mu_s

    sim2.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))

    sim2.add(DemagHexagonal())
    sim2.get_interaction('DemagHexagonal').compute_field()
    sim2.compute_energy()

    demag_2fft_energy = sim2.compute_energy() / const.meV

    # We compare both energies scaled in meV
    assert (DemagFull_energy - demag_2fft_energy) < 1e-10
def test_hexagonal_demags_2D():
    """
    Comparison of the FFT approach for hexagonal meshes, named
    DemagHexagonal, where it is used a system with the double number
    of nodes along the x direction (i.e. a mesh with twice the number
    of nodes of the original mesh), against the full calculation
    of the Demag field
    """
    # Number of atoms
    N = 15
    a = 0.4
    mesh = HexagonalMesh(a * 0.5, N, N,
                         unit_length=1e-9,
                         alignment='square')

    # Centre
    xc = (mesh.Lx * 0.5)
    yc = (mesh.Ly * 0.5)

    mu_s = 2 * const.mu_B

    sim = Sim(mesh)
    sim.mu_s = mu_s

    sim.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))
    # Brute force demag calculation
    sim.add(DemagFull())

    sim.get_interaction('demag_full').compute_field()
    sim.get_interaction('demag_full').field
    demag_full_energy = sim.compute_energy() / const.meV

    # Demag using the FFT approach and a larger mesh
    sim2 = Sim(mesh)
    sim2.mu_s = mu_s

    sim2.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))

    sim2.add(DemagHexagonal())
    sim2.get_interaction('demag_hex').compute_field()
    sim2.compute_energy()

    demag_2fft_energy = sim2.compute_energy() / const.meV

    # We compare both energies scaled in meV
    assert (demag_full_energy - demag_2fft_energy) < 1e-10
Beispiel #33
0
def test_exch_2d():
    mesh = CuboidMesh(nx=5, ny=2, nz=1)
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    assert np.max(field[2::3]) == 0

    assert field[0] == 1
    assert field[3] == 2 + 1
    assert field[6] == 1 + 2 + 3
    assert field[9] == 2 + 3 + 4
    assert field[12] == 3 + 4
Beispiel #34
0
def relax_system(rtol=1e-10, atol=1e-12):
    """numerical solution"""
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    sim = Sim(mesh, name='relax')
    sim.driver.set_tols(rtol=rtol, atol=atol)
    sim.driver.alpha = 0.5
    sim.driver.gamma = 2.21e5
    sim.mu_s = 1.0

    sim.set_m((1.0, 0, 0))

    sim.add(Zeeman((0, 0, 1e5)))

    ts = np.linspace(0, 1e-9, 1001)

    for t in ts:
        sim.driver.run_until(t)
Beispiel #35
0
def disable_test_sim_single_spin_llg_stt(do_plot=False):
    ni = Nickel()
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    mesh.set_material(ni)

    ni.alpha = 0.1
    sim = Sim(mesh, driver='llg_stt')
    sim.set_m((1, 0, 0))

    H0 = 1
    sim.add(Zeeman((0, 0, H0)))

    dt = 1e-12
    ts = np.linspace(0, 200 * dt, 101)

    precession = ni.gamma / (1 + ni.alpha**2)

    mz_ref = []
    mxyz = []
    real_ts = []

    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        print(sim.t, abs(sim.spin_length()[0] - 1), sim.spin)
        mz_ref.append(np.tanh(precession * ni.alpha * H0 * sim.t))
        mxyz.append(np.copy(sim.spin))

    mxyz = np.array(mxyz)

    if do_plot:
        ts_ns = np.array(real_ts) * 1e9

        plt.plot(ts_ns, mxyz[:, 0], ".-", label="mx")
        plt.plot(ts_ns, mxyz[:, 1], ".-", label="my")
        plt.plot(ts_ns, mxyz[:, 2], ".-", label="mz")
        plt.plot(ts_ns, mz_ref, "-", label="analytical")
        plt.xlabel("time (ns)")
        plt.ylabel("mz")
        plt.title("integrating a macrospin")
        plt.legend()
        plt.savefig("test_llg_stt.png")

        print(("Deviation = {0}".format(np.max(np.abs(mxyz[:, 2] - mz_ref)))))

    assert np.max(np.abs(mxyz[:, 2] - mz_ref)) < 1e-9
Beispiel #36
0
def relax_system(mesh):

    sim = Sim(mesh, name='relax')
    sim.mu_s = 1e-23
    sim.driver.gamma = 1.76e11
    sim.driver.alpha = 1.0
    J = 1e-22
    exch = UniformExchange(J)
    sim.add(exch)
    demag = Demag()
    sim.add(demag)
    sim.set_m(init_m)

    ts = np.linspace(0, 5e-10, 101)
    for t in ts:
        sim.driver.run_until(t)
        sim.save_vtk()
    np.save('m0.npy', sim.spin)
Beispiel #37
0
def test_dmi_1d():

    mesh = CuboidMesh(nx=2, ny=1, nz=1)

    sim = Sim(mesh)
    sim.set_m((1, 0, 0))

    dmi = DMI(D=1)
    sim.add(dmi)

    field = dmi.compute_field()

    expected = np.array([0, 0, 0, 0, 0, 0])

    assert (field == expected).all()

    energy = dmi.compute_energy()
    assert energy == 0
Beispiel #38
0
def test_sim_single_spin_sllg(do_plot=False):

    mesh = CuboidMesh(nx=1, ny=1, nz=1)

    sim = Sim(mesh, name='spin', driver='sllg')

    alpha = 0.1
    gamma = 2.21e5

    sim.set_options(dt=5e-15, gamma=gamma)

    sim.alpha = alpha
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))

    ts = np.linspace(0, 1e-10, 101)

    mx = []
    my = []
    mz = []
    real_ts = []
    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        print(sim.t, abs(sim.spin_length()[0] - 1))
        mx.append(sim.spin[0])
        my.append(sim.spin[1])
        mz.append(sim.spin[2])

    mz = np.array(mz)

    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    if do_plot:
        plot(real_ts, mx, my, mz, a_mx, a_my, a_mz, name='spin_sllg.pdf', title='integrating a spin')

    print(("Max Deviation = {0}".format(
        np.max(np.abs(mz - a_mz)))))

    assert np.max(np.abs(mz - a_mz)) < 1e-8
Beispiel #39
0
def test_sim_single_spin_vode(do_plot=False):

    mesh = CuboidMesh(nx=1, ny=1, nz=1)

    sim = Sim(mesh, name='spin')

    alpha = 0.1
    gamma = 2.21e5
    sim.alpha = alpha
    sim.gamma = gamma
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))

    ts = np.linspace(0, 1e-9, 101)

    mx = []
    my = []
    mz = []
    real_ts = []
    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        #print sim.t, abs(sim.spin_length()[0] - 1)
        mx.append(sim.spin[0])
        my.append(sim.spin[1])
        mz.append(sim.spin[2])

    mz = np.array(mz)
    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    print sim.stat()

    if do_plot:
        plot(real_ts, mx, my, mz, a_mx, a_my, a_mz)

    print("Max Deviation = {0}".format(
        np.max(np.abs(mz - a_mz))))

    assert np.max(np.abs(mz - a_mz)) < 5e-7
Beispiel #40
0
def test_sim_single_spin_vode(do_plot=False):

    mesh = CuboidMesh(nx=1, ny=1, nz=1)

    sim = Sim(mesh, name='spin')

    alpha = 0.1
    gamma = 2.21e5
    sim.driver.alpha = alpha
    sim.driver.gamma = gamma
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))

    ts = np.linspace(0, 1e-9, 101)

    mx = []
    my = []
    mz = []
    real_ts = []
    for t in ts:
        sim.driver.run_until(t)
        real_ts.append(sim.driver.t)
        #print sim.driver.t, abs(sim.spin_length()[0] - 1)
        mx.append(sim.spin[0])
        my.append(sim.spin[1])
        mz.append(sim.spin[2])

    mz = np.array(mz)
    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    print(sim.driver.stat())

    if do_plot:
        plot(real_ts, mx, my, mz, a_mx, a_my, a_mz)

    print(("Max Deviation = {0}".format(
        np.max(np.abs(mz - a_mz)))))

    assert np.max(np.abs(mz - a_mz)) < 5e-7
Beispiel #41
0
def test_dmi_1d_field():

    mesh = CuboidMesh(nx=2, ny=1, nz=1)

    sim = Sim(mesh)
    sim.set_m(init_m)

    dmi = DMI(D=1.23)
    sim.add(dmi)

    field = dmi.compute_field()

    expected = np.array([0, -1, 0, 0, 0, -1]) * 1.23

    assert np.allclose(field, expected)

    energy = dmi.compute_energy()

    assert energy == 1.23
Beispiel #42
0
def test_demag_fft_exact_oommf():
    mesh = CuboidMesh(nx=5, ny=3, nz=2, unit_length=1e-9)
    sim = Sim(mesh)
    demag = Demag()
    sim.add(demag)

    def init_m(pos):
        x = pos[0]
        if x <= 2:
            return (1, 0, 0)
        elif x >= 4:
            return (0, 0, 1)
        else:
            return (0, 1, 0)

    sim.set_m(init_m)
    fft = demag.compute_field()
    exact = demag.compute_exact()
    np.testing.assert_allclose(fft, exact, rtol=1e-10)
Beispiel #43
0
def test_full_exch_hex_9_shells():
    """
    Test the x component of the exchange field when using 9 shells of
    neighbours in a 9 X 9 hexagonal lattice with square and diagonal
    arrangement

    We set J=1 for every shell and set the s_x component of the spins as the
    lattice site number:
    [0, 1, 2, 3, ... 80]

    Since we set the s_x components as the lattice position indexes, the x
    component of the field is just the sum of the indexes of the neighbours
    (assuming the neighbours indexing is correct) because we set the exchange
    constants as 1
    """

    for arrang in ['square', 'diagonal']:
        a = 1
        shells = 9
        mesh = HexagonalMesh(a * 0.5,
                             nx=9,
                             ny=9,
                             shells=shells,
                             alignment=arrang)
        sim = Sim(mesh)
        # Set s_x as the lattice site number
        sim.spin.reshape(-1,
                         3)[:,
                            0] = np.arange(len(sim.spin.reshape(-1, 3)[:, 0]))

        Js = np.ones(shells)
        exch = Exchange(Js)
        sim.add(exch)

        field = exch.compute_field()

        # Test the x component for every lattice site, summing the neighbours
        # index and removing the -1 elements (their contribution is zero)
        for i in range(sim.mesh.n):
            assert field[3 * i] == np.sum(
                remove_negatives(sim.mesh.neighbours[i]))
Beispiel #44
0
def test_exch_1d_spatial():
    """
    Test the x component of the exchange field
    in a 1D mesh, with the spin ordering:

    0 1 2 3 4 5

    """
    mesh = CuboidMesh(nx=12, ny=1, nz=1)
    sim = Sim(mesh)
    exch = Exchange(spatial_J)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    assert exch._J[3, 3] == -1.0
    assert exch._J[5, 1] == 0.3
    assert exch._J[6, 0] == 0.3
    assert exch._J[8, 5] == 1.0
Beispiel #45
0
def test_exch_1d_spatial():
    """
    Test the x component of the exchange field
    in a 1D mesh, with the spin ordering:

    0 1 2 3 4 5

    """
    mesh = CuboidMesh(nx=12, ny=1, nz=1)
    sim = Sim(mesh)
    exch = Exchange(spatial_J)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    assert exch._J[3,3] == -1.0
    assert exch._J[5,1] == 0.3
    assert exch._J[6,0] == 0.3
    assert exch._J[8,5] == 1.0
Beispiel #46
0
def relax_system_stage1():

    mesh = CuboidMesh(nx=140 , ny=140, nz=1)

    sim = Sim(mesh, name='relax', driver='llg')
    #sim.set_options(dt=1e-14, gamma=const.gamma, k_B=const.k_B)
    sim.alpha = 0.5
    sim.do_precession = False
    sim.gamma = const.gamma
    sim.mu_s = spatial_mu

    sim.set_m(init_m)

    J = 50 * const.k_B
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.27 * J
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman(spatial_H)
    sim.add(zeeman)

    sim.relax(dt=1e-14, stopping_dmdt=1e10, max_steps=1000,
              save_m_steps=100, save_vtk_steps=10)

    np.save('skx.npy', sim.spin)
    plot_m(mesh, 'skx.npy', comp='z')
def excite_system(mesh):

    sim = Sim(mesh, name='dyn', driver='sllg')
    sim.set_options(dt=1e-14, gamma=const.gamma, k_B=const.k_B)
    sim.driver.alpha = 0.1
    sim.mu_s = const.mu_s_1
    sim.T = temperature_gradient

    sim.set_m(np.load("m0.npy"))

    J = 50.0 * const.k_B
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.5 * J
    dmi = DMI(D)
    sim.add(dmi)

    Hz = 0.2 * J / const.mu_s_1
    zeeman = Zeeman([0, 0, Hz])
    sim.add(zeeman)

    dt = 2e-14 * 50  # 1e-12
    ts = np.linspace(0, 1000 * dt, 501)
    for t in ts:
        sim.run_until(t)
        sim.save_vtk()
        sim.save_m()
        print 'sim t=%g' % t
def relax_system(mesh):

    sim = Sim(mesh, name='relax')
    sim.set_default_options(gamma=const.gamma)
    sim.driver.alpha = 0.5
    sim.mu_s = const.mu_s_1

    sim.set_m(init_m)

    J = 50.0 * const.k_B
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.5 * J
    dmi = DMI(D)
    sim.add(dmi)

    Hz = 0.2 * J / const.mu_s_1
    zeeman = Zeeman([0, 0, Hz])
    sim.add(zeeman)

    ONE_DEGREE_PER_NS = 17453292.52

    sim.relax(dt=1e-13, stopping_dmdt=0.01 * ONE_DEGREE_PER_NS,
              max_steps=1000, save_m_steps=100, save_vtk_steps=50)

    np.save('m0.npy', sim.spin)
def relax_system(mesh, Dx=0.005, Dp=0.01):

    mat = UnitMaterial()

    sim = Sim(mesh, name='test_energy')
    print('Created sim')
    sim.driver.set_tols(rtol=1e-10, atol=1e-12)

    sim.alpha = mat.alpha
    sim.driver.gamma = mat.gamma
    sim.pins = pin_fun

    exch = UniformExchange(mat.J)
    sim.add(exch)
    print('Added UniformExchange')

    anis = Anisotropy(Dx, axis=[1, 0, 0], name='Dx')
    sim.add(anis)
    print('Added Anisotropy')

    anis2 = Anisotropy([0, 0, -Dp], name='Dp')
    sim.add(anis2)
    print('Added Anisotropy 2')

    sim.set_m((1, 1, 1))

    T = 100
    ts = np.linspace(0, T, 201)
    for t in ts:
        # sim.save_vtk()
        sim.driver.run_until(t)
        print(('Running -', t))

    # sim.save_vtk()
    np.save('m0.npy', sim.spin)
Beispiel #50
0
def relax_system_stage2():

    mesh = CuboidMesh(nx=140 , ny=140, nz=1)

    sim = Sim(mesh, name='dyn', driver='llg')
    sim.alpha = 0.1
    sim.do_precession = True
    sim.gamma = const.gamma
    sim.mu_s = spatial_mu

    sim.set_m(np.load('skx.npy'))

    J = 50 * const.k_B
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.27 * J
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman(spatial_H)
    sim.add(zeeman)

    ts = np.linspace(0, 2e-9, 201)
    for t in ts:
        sim.run_until(t)
        sim.save_vtk()
        sim.save_m()
        print(t)
Beispiel #51
0
def test_skx_num():

    mesh = CuboidMesh(nx=120, ny=120, nz=1, periodicity=(True, True, False))

    sim = Sim(mesh, name='skx_num')
    sim.set_tols(rtol=1e-6, atol=1e-6)
    sim.alpha = 1.0
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(init_m)

    sim.do_procession = False

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.09
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, 0, 5e-3])
    sim.add(zeeman)

    sim.relax(dt=2.0, stopping_dmdt=1e-2, max_steps=1000,
              save_m_steps=None, save_vtk_steps=None)

    skn = sim.skyrmion_number()
    print 'skx_number', skn
    assert skn > -1 and skn < -0.99
Beispiel #52
0
def relax_system(mesh):

    sim=Sim(mesh,name='relax')
    sim.set_options(rtol=1e-12,atol=1e-14)
    sim.do_precession = False
    sim.alpha = 0.5
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(init_m)

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.18
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0,0e-3,2e-2],name='H')
    sim.add(zeeman)

    sim.relax(dt=2.0, stopping_dmdt=1e-8, max_steps=10000, save_m_steps=None, save_vtk_steps=100)

    np.save('m0.npy',sim.spin)
Beispiel #53
0
def relax_system(mesh):

    sim = Sim(mesh, name='relax')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.alpha = 1.0
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(init_m)
    # sim.set_m(random_m)
    # sim.set_m(np.load('m_10000.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.09
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, 0, 3.75e-3])
    sim.add(zeeman)

    sim.relax(dt=2.0, stopping_dmdt=1e-6, max_steps=1000,
              save_m_steps=100, save_vtk_steps=50)

    np.save('m0.npy', sim.spin)