def run_finmag(demagsolver):
    """Run the finmag simulation and store data in (demagsolvertype)averages.txt."""

    sim = Sim(mesh, Ms, unit_length=unit_length)
    sim.alpha = 0.5
    sim.set_m((1, 0, 1))

    exchange = Exchange(13.0e-12)
    sim.add(exchange)
    demag = Demag(solver=demagsolver)
    sim.add(demag)

    fh = open(os.path.join(MODULE_DIR, demagsolver + "averages.txt"), "w")
    fe = open(os.path.join(MODULE_DIR, demagsolver + "energies.txt"), "w")

    # Progressbar
    bar = pb.ProgressBar(maxval=60, \
                    widgets=[pb.ETA(), pb.Bar('=', '[', ']'), ' ', pb.Percentage()])

    logger.info("Time integration")
    times = np.linspace(0, 3.0e-10, 61)
    #times = np.linspace(0, 3.0e-10, 100000)
    for counter, t in enumerate(times):
        bar.update(counter)

        # Integrate
        sim.run_until(t)
        print counter
        print("press return to continue")
        _ = raw_input()

        # Save averages to file
        mx, my, mz = sim.m_average
        fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n")

        # Energies
        E_e = exchange.compute_energy()
        E_d = demag.compute_energy()
        fe.write(str(E_e) + " " + str(E_d) + "\n")

        # Energy densities
        if counter == 10:
            exch_energy = exchange.energy_density_function()
            demag_energy = demag.demag.energy_density_function()
            finmag_exch, finmag_demag = [], []
            R = range(100)
            for i in R:
                finmag_exch.append(exch_energy([15, 15, i]))
                finmag_demag.append(demag_energy([15, 15, i]))
            # Store data
            np.save(
                os.path.join(MODULE_DIR,
                             "finmag%s_exch_density.npy" % demagsolver),
                np.array(finmag_exch))
            np.save(
                os.path.join(MODULE_DIR,
                             "finmag%s_demag_density.npy" % demagsolver),
                np.array(finmag_demag))
    fh.close()
    fe.close()
Exemple #2
0
def test_zhangli():

    #mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(100, 1, 1), 50, 1, 1)
    mesh = df.IntervalMesh(50, 0, 100)

    sim = Sim(mesh, Ms=8.6e5, unit_length=1e-9, kernel='llg_stt')
    sim.set_m(init_m)

    sim.add(UniaxialAnisotropy(K1=520e3, axis=[1, 0, 0]))
    sim.add(Exchange(A=13e-12))
    sim.alpha = 0.01

    sim.llg.set_parameters(J_profile=init_J, speedup=50)

    p0 = sim.m_average

    sim.run_until(5e-12)
    p1 = sim.m_average
    print sim.integrator.stats()
    print p0, p1
    sim.run_until(1e-11)
    p1 = sim.m_average
    print sim.integrator.stats()
    print p0, p1

    assert p1[0] < p0[0]
    assert abs(p0[0]) < 1e-15
    assert abs(p1[0]) > 1e-3
Exemple #3
0
def run_simulation():
    L = 3e-8
    W = 1e-8
    H = 1e-8
    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(L, W, H), 10, 4, 4)

    Ms = 0.86e6  # A/m
    A = 1.3e-11  # J/m

    sim = Sim(mesh, Ms)
    sim.set_m(("2*x[0]/L - 1", "2*x[1]/W - 1", "1"), L=3e-8, H=1e-8, W=1e-8)
    sim.alpha = 0.1
    sim.add(Zeeman((Ms / 2, 0, 0)))
    sim.add(Exchange(A))

    t = 0
    dt = 1e-11
    tmax = 1e-9  # s

    fh = open(os.path.join(MODULE_DIR, "averages.txt"), "w")
    while t <= tmax:
        mx, my, mz = sim.m_average
        fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n")
        t += dt
        sim.run_until(t)
    fh.close()
Exemple #4
0
def test_thin_film_demag_against_real_demag():
    sim = Sim(
        df.BoxMesh(df.Point(0, 0, 0), df.Point(500e-9, 500e-9, 1e-9), 50, 50,
                   1), Ms)
    sim.set_m((0, 0, 1))

    tfdemag = ThinFilmDemag()
    sim.add(tfdemag)
    H_tfdemag = tfdemag.compute_field().view().reshape((3, -1)).mean(1)
    demag = Demag()
    sim.add(demag)
    H_demag = demag.compute_field().view().reshape((3, -1)).mean(1)

    diff = np.abs(H_tfdemag - H_demag) / Ms
    print "Standard Demag:\n", H_demag
    print "ThinFilmDemag:\n", H_tfdemag
    print "Difference relative to Ms:\n", diff
    assert np.allclose(H_tfdemag, H_demag, atol=0.05 * Ms)  # 5% of Ms

    sim.set_m((1, 0, 0))
    H_tfdemag = tfdemag.compute_field().view().reshape((3, -1)).mean(1)
    H_demag = demag.compute_field().view().reshape((3, -1)).mean(1)

    print "Running again, changed m in the meantime."
    diff = np.abs(H_tfdemag - H_demag) / Ms
    print "Standard Demag:\n", H_demag
    print "ThinFilmDemag:\n", H_tfdemag
    print "Difference relative to Ms:\n", diff
    assert np.allclose(H_tfdemag, H_demag, atol=0.005 * Ms)  # 0.5% of Ms
Exemple #5
0
def test_current_time():
    size = 20e-9
    simplices = 4
    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(size, size, size), simplices,
                      simplices, simplices)

    Ms = 860e3
    A = 13.0e-12

    sim = Sim(mesh, Ms)
    sim.set_m((1, 0, 0))
    sim.add(Exchange(A))
    sim.add(Demag())

    t = 0.0
    t_max = 1e-10
    dt = 1e-12

    while t <= t_max:
        t += dt
        sim.run_until(t)
        # cur_t is equal to whatever time the integrator decided to probe last
        assert not sim.integrator.cur_t == 0.0
        # t is equal to our current simulation time
        assert abs(sim.t - t) < epsilon
Exemple #6
0
def example3(Ms):
    x0 = y0 = z0 = 0
    x1 = 500
    y1 = 10
    z1 = 500
    nx = 50
    ny = 1
    nz = 1
    mesh = df.Box(x0, y0, z0, x1, y1, z1, nx, ny, nz)

    sim = Sim(mesh, Ms, unit_length=1e-9)
    sim.alpha = 0.01
    sim.set_m((1, 0, 0.1))

    H_app = Zeeman((0, 0, 5e5))
    sim.add(H_app)

    exch = fe.Exchange(13.0e-12)
    sim.add(exch)

    demag = Demag(solver="FK")
    sim.add(demag)

    llg = sim.llg
    max_time = 1 * np.pi / (llg.gamma * 1e5)
    ts = np.linspace(0, max_time, num=100)

    for t in ts:
        print t
        sim.run_until(t)

        df.plot(llg._m)

    df.interactive()
Exemple #7
0
def run_sim_with_stt():
    sim = Sim(mesh, Ms=8.6e5)
    sim.set_m((1, 0.01, 0.01))
    sim.alpha = 0.014
    sim.gamma = 221017

    H_app_mT = np.array([0.2, 0.2, 10.0])
    H_app_SI = H_app_mT / (1000 * mu0)
    sim.add(Zeeman(tuple(H_app_SI)))

    sim.add(Exchange(1.3e-11))
    sim.add(UniaxialAnisotropy(1e5, (0, 0, 1)))

    I = 5e-5  # current in A
    J = I / (L * W)  # current density in A/m^2
    theta = 40.0 * pi / 180
    phi = pi / 2  # polarisation direction
    p = (sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta))
    sim.llg.use_slonczewski(J=J, P=0.4, d=5e-9, p=(0, 1, 0))

    with open(averages_with, "w") as f:
        dt = 5e-12
        t_max = 10e-9
        for t in np.arange(0, t_max, dt):
            sim.run_until(t)
            f.write("{} {} {} {}\n".format(t, *sim.m_average))
Exemple #8
0
def run_simulation():
    L = W = 12.5e-9
    H = 2.5e-9
    sim = Sim(mesh, Ms=8.6e5, unit_length=1e-9)
    sim.set_m((1, 0.01, 0.01))
    sim.alpha = 0.014
    sim.gamma = 221017

    H_app_mT = np.array([0.0, 0.0, 10.0])
    H_app_SI = H_app_mT / (1000 * mu0)
    sim.add(Zeeman(tuple(H_app_SI)))

    sim.add(Exchange(1.3e-11))

    I = 5e-5  # current in A
    J = I / (L * W)  # current density in A/m^2
    theta = 40.0 * pi / 180
    phi = pi / 2  # polarisation direction
    p = (sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta))
    sim.llg.use_slonczewski(J=J, P=0.4, d=H, p=p)

    with open(averages_file, "w") as f:
        dt = 10e-12
        t_max = 10e-9
        for t in np.arange(0, t_max, dt):
            sim.run_until(t)
            f.write("{} {} {} {}\n".format(t, *sim.m_average))
Exemple #9
0
def setup_module(module=None):
    # define the mesh
    x_max = 20e-9  # m
    simplexes = 10
    mesh = IntervalMesh(simplexes, 0, x_max)

    def m_gen(coords):
        x = coords[0]
        mx = min(1.0, 2.0 * x / x_max - 1.0)
        my = np.sqrt(1.0 - mx**2)
        mz = 0.0
        return np.array([mx, my, mz])

    Ms = 0.86e6
    A = 1.3e-11

    global sim
    sim = Sim(mesh, Ms)
    sim.alpha = 0.2
    sim.set_m(m_gen)
    sim.pins = [0, 10]
    exchange = Exchange(A)
    sim.add(exchange)

    # Save H_exc and m at t0 for comparison with nmag
    global H_exc_t0, m_t0
    H_exc_t0 = exchange.compute_field()
    m_t0 = sim.m

    t = 0
    t1 = 5e-10
    dt = 1e-11
    # s

    av_f = open(os.path.join(MODULE_DIR, "averages.txt"), "w")
    tn_f = open(os.path.join(MODULE_DIR, "third_node.txt"), "w")

    global averages
    averages = []
    global third_node
    third_node = []

    while t <= t1:
        mx, my, mz = sim.m_average
        averages.append([t, mx, my, mz])
        av_f.write(
            str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n")

        mx, my, mz = h.components(sim.m)
        m2x, m2y, m2z = mx[2], my[2], mz[2]
        third_node.append([t, m2x, m2y, m2z])
        tn_f.write(
            str(t) + " " + str(m2x) + " " + str(m2y) + " " + str(m2z) + "\n")

        t += dt
        sim.run_until(t)

    av_f.close()
    tn_f.close()
Exemple #10
0
def create_simulation(mesh):

    sim = Sim(mesh, Ms=8.6e5, unit_length=1e-9)

    sim.set_m((1, 0, 0))
    sim.add(UniaxialAnisotropy(-1e5, (0, 0, 1), name='Kp'))
    sim.add(UniaxialAnisotropy(1e4, (1, 0, 0), name='Kx'))

    return sim
Exemple #11
0
def create_initial_state():
    print "Creating initial relaxed state."
    sim = Sim(mesh, Ms=Ms, unit_length=1e-9)
    sim.set_m(m_gen)
    sim.alpha = 0.5
    sim.add(Exchange(1.3e-11))
    sim.add(Demag())
    sim.relax()
    np.savetxt(initial_m_file, sim.m)
Exemple #12
0
def angles_after_a_nanosecond(initial_M, pins=[]):
    sim = Sim(mesh, Ms)
    sim.set_m(initial_M, L=length)
    sim.add(Exchange(A))
    sim.pins = pins
    sim.run_until(1e-9)

    m = vectors(sim.m)
    angles = np.array([angle(m[i], m[i + 1]) for i in xrange(len(m) - 1)])
    return angles
Exemple #13
0
def create_sim(mesh):

    Ms = 3.84e5  # A/m
    A = 8.78e-12  # J/m
    D = 1.58e-3  # J/m**2

    sim = Sim(mesh, Ms, unit_length=1e-9)
    sim.set_m((0, 0, 1))
    sim.set_tol(reltol=1e-10, abstol=1e-10)

    sim.add(Exchange(A))
    sim.add(DMI(D))

    return sim
Exemple #14
0
def test_uniform_external_field():
    TOLERANCE = 3.5e-10

    mesh = df.UnitCubeMesh(2, 2, 2)
    sim = Sim(mesh, Ms)
    sim.set_m((1, 0, 0))
    sim.add(Zeeman((0, Ms, 0)))
    sim.alpha = 1.0
    sim.run_until(1e-9)

    m = sim.m.reshape((3, -1)).mean(-1)
    expected_m = np.array([0, 1, 0])
    diff = np.abs(m - expected_m)
    assert np.max(diff) < TOLERANCE
Exemple #15
0
def run_simulation():
    print "Running simulation of STT dynamics."
    sim = Sim(mesh, Ms=Ms, unit_length=1e-9)
    sim.set_m(np.loadtxt(initial_m_file))
    sim.alpha = 0.01
    sim.add(Exchange(1.3e-11))
    sim.add(Demag())
    sim.llg.use_slonczewski(J=0.1e12, P=0.4, d=10e-9, p=(0, 1, 0))
    with open(averages_file, "w") as f:
        dt = 5e-12
        t_max = 10e-9
        for t in np.arange(0, t_max, dt):
            sim.run_until(t)
            f.write("{} {} {} {}\n".format(t, *sim.m_average))
Exemple #16
0
def compare_with_demag_from_initial_m(H_gen, m_init, atol=0, rtol=0):
    sim = Sim(df.UnitCubeMesh(2, 2, 2), Ms, unit_length=1e-9)
    sim.set_m(m_init)

    demag = ThinFilmDemag()
    sim.add(demag)
    H_computed = demag.compute_field()
    H_expected = H_gen(sim.m)

    diff = np.abs(H_computed - H_expected)
    print "Expected, with shape {}:\n".format(H_expected.shape), H_expected
    print "Got, with shape {}:\n".format(H_computed.shape), H_computed
    print "Difference:\n", diff
    assert np.allclose(H_computed, H_expected, atol=atol, rtol=rtol)
Exemple #17
0
def relax_system(mesh):
    sim = Sim(mesh, Ms=8.0e5, unit_length=1e-9)
    sim.gamma = 2.211e5

    sim.alpha = 1

    sim.add(Exchange(A=13e-12))
    sim.add(Demag())

    sim.set_m(init_m)

    sim.relax(stopping_dmdt=0.01)
    np.save('m0.npy', sim.m)
    df.plot(sim._m)
Exemple #18
0
def setup_module(module=None):
    x_max = 100e-9  # m
    simplexes = 50
    mesh = dolfin.IntervalMesh(simplexes, 0, x_max)

    def m_gen(coords):
        x = coords[0]
        mx = min(1.0, x / x_max)
        mz = 0.1
        my = np.sqrt(1.0 - (0.99 * mx**2 + mz**2))
        return np.array([mx, my, mz])

    K1 = 520e3  # J/m^3
    Ms = 0.86e6

    sim = Sim(mesh, Ms)
    sim.alpha = 0.2
    sim.set_m(m_gen)
    anis = UniaxialAnisotropy(K1, (0, 0, 1))
    sim.add(anis)

    # Save H_anis and m at t0 for comparison with nmag
    global H_anis_t0, m_t0
    H_anis_t0 = anis.compute_field()
    m_t0 = sim.m

    av_f = open(os.path.join(MODULE_DIR, "averages.txt"), "w")
    tn_f = open(os.path.join(MODULE_DIR, "third_node.txt"), "w")

    t = 0
    t_max = 3e-10
    dt = 5e-12
    # s
    while t <= t_max:
        mx, my, mz = sim.m_average
        averages.append([t, mx, my, mz])
        av_f.write(
            str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n")

        mx, my, mz = h.components(sim.m)
        m2x, m2y, m2z = mx[2], my[2], mz[2]
        third_node.append([t, m2x, m2y, m2z])
        tn_f.write(
            str(t) + " " + str(m2x) + " " + str(m2y) + " " + str(m2z) + "\n")

        t += dt
        sim.run_until(t)

    av_f.close()
    tn_f.close()
Exemple #19
0
def create_simulation():

    from finmag.util.meshes import ellipsoid
    #mesh = df.IntervalMesh(10,0,30)
    #mesh = df.RectangleMesh(0,0,10,2,5,1)
    mesh = ellipsoid(30, 10, 10, maxh=3.0)

    sim = Sim(mesh, Ms=8.6e5, unit_length=1e-9)

    sim.set_m((1, 1, 1))
    sim.add(Exchange(1.3e-11))
    sim.add(UniaxialAnisotropy(-1e5, (0, 0, 1), name='Kp'))
    sim.add(UniaxialAnisotropy(1e4, (1, 0, 0), name='Kx'))

    return sim
def run_finmag():
    """Run the finmag simulation and store data in averages.txt."""

    sim = Sim(mesh, Ms, unit_length=unit_length)
    sim.alpha = 0.5
    sim.set_m((1, 0, 1))

    exchange = Exchange(13.0e-12)
    sim.add(exchange)
    demag = Demag(solver="FK")
    sim.add(demag)

    fh = open(os.path.join(MODULE_DIR, "averages.txt"), "w")
    fe = open(os.path.join(MODULE_DIR, "energies.txt"), "w")

    logger.info("Time integration")
    times = np.linspace(0, 3.0e-10, 61)
    for counter, t in enumerate(times):

        # Integrate
        sim.run_until(t)

        # Save averages to file
        mx, my, mz = sim.m_average
        fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n")

        # Energies
        E_e = exchange.compute_energy()
        E_d = demag.compute_energy()
        fe.write(str(E_e) + " " + str(E_d) + "\n")

        # Energy densities
        if counter == 10:
            exch_energy = exchange.energy_density_function()
            demag_energy = demag.energy_density_function()
            finmag_exch, finmag_demag = [], []
            R = range(100)
            for i in R:
                finmag_exch.append(exch_energy([15, 15, i]))
                finmag_demag.append(demag_energy([15, 15, i]))
            # Store data
            np.save(os.path.join(MODULE_DIR, "finmag_exch_density.npy"),
                    np.array(finmag_exch))
            np.save(os.path.join(MODULE_DIR, "finmag_demag_density.npy"),
                    np.array(finmag_demag))

    fh.close()
    fe.close()
Exemple #21
0
def test_negative_uniform_external_field():
    TOLERANCE = 1e-10

    mesh = df.UnitCubeMesh(2, 2, 2)
    sim = Sim(mesh, Ms)
    sim.set_m((1, 0.1, 0))  # slightly misaligned
    sim.add(Zeeman((-1.0 * Ms, 0, 0)))
    sim.alpha = 1.0
    sim.run_until(1e-9)

    m = sim.m.reshape((3, -1)).mean(-1)
    print "Average magnetisation ({:.2g}, {:.2g}, {:.2g}).".format(*m)
    expected_m = np.array([-1, 0, 0])
    diff = np.abs(m - expected_m)
    TOLERANCE = 1e-5
    assert np.max(diff) < TOLERANCE
Exemple #22
0
def with_current(mesh):
    sim = Sim(mesh, Ms=8.0e5, unit_length=1e-9, name='stt')
    sim.gamma = 2.211e5

    sim.alpha = 0.1
    sim.set_m(np.load('m0.npy'))

    sim.add(Exchange(A=13e-12))
    sim.add(Demag())

    sim.set_zhangli(init_J, 1.0, 0.05)

    sim.schedule('save_ndt', every=5e-11)
    #sim.schedule('save_vtk', every=5e-11)
    sim.schedule(spin_length, every=5e-11)

    sim.run_until(8e-9)
    df.plot(sim._m)
Exemple #23
0
def t_test_sim_ode_parallel(do_plot=False):
    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(2, 2, 2), 1, 1, 1)
    sim = Sim(mesh, 8.6e5, unit_length=1e-9, pbc='2d', parallel=True)
    sim.alpha = alpha
    sim.set_m((1, 0, 0))

    sim.set_tol(1e-10, 1e-14)

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))
    # sim.add(Exchange(1.3e-11))

    dt = 1e-12
    ts = np.linspace(0, 500 * dt, 100)

    precession_coeff = sim.gamma / (1 + alpha**2)
    mz_ref = np.tanh(precession_coeff * alpha * H0 * ts)

    mzs = []
    length_error = []
    for t in ts:
        sim.run_until(t)
        mm = sim.m.copy()

        # mm.shape=(3,-1)
        # mx,my,mz = mm[:,0] # same as m_average for this macrospin problem
        mzs.append(mm[-1])
        #length = np.sqrt(mx**2+my**2+mz**2)
        # length_error.append(abs(length-1.0))

    if do_plot:
        ts_ns = ts * 1e9
        plt.plot(ts_ns, mzs, "b.", label="computed")
        plt.plot(ts_ns, mz_ref, "r-", label="analytical")
        plt.xlabel("time (ns)")
        plt.ylabel("mz")
        plt.title("integrating a macrospin")
        plt.legend()
        plt.savefig(os.path.join(MODULE_DIR, "test_sim_ode.png"))

    print("Deviation = {}, total value={}".format(np.max(np.abs(mzs - mz_ref)),
                                                  mz_ref))

    assert np.max(np.abs(mzs - mz_ref)) < 1e-9
Exemple #24
0
def test_non_uniform_external_field():
    TOLERANCE = 1e-9
    length = 10e-9
    vertices = 5
    mesh = df.IntervalMesh(vertices, 0, length)
    sim = Sim(mesh, Ms)
    sim.set_m((1, 0, 0))
    # applied field
    # (0, -H, 0) for 0 <= x <= a
    # (0, +H, 0) for a <  x <= length
    H_expr = df.Expression(("0", "H*(x[0]-a)/fabs(x[0]-a)", "0"), a=length / 2, H=Ms / 2, degree=1)
    sim.add(Zeeman(H_expr))
    sim.alpha = 1.0
    sim.run_until(1e-9)

    m = sim.m.reshape((3, -1)).mean(-1)
    expected_m = np.array([0, 0, 0])
    diff = np.abs(m - expected_m)
    assert np.max(diff) < TOLERANCE
Exemple #25
0
def run_sim_without_stt():
    sim = Sim(mesh, Ms=8.6e5)
    sim.set_m((1, 0.01, 0.01))
    sim.alpha = 0.014
    sim.gamma = 221017

    H_app_mT = np.array([0.2, 0.2, 10.0])
    H_app_SI = H_app_mT / (1000 * mu0)
    sim.add(Zeeman(tuple(H_app_SI)))

    sim.add(Exchange(1.3e-11))
    sim.add(UniaxialAnisotropy(1e5, (0, 0, 1)))

    with open(averages_without, "w") as f:
        dt = 5e-12
        t_max = 10e-9
        for t in np.arange(0, t_max, dt):
            sim.run_until(t)
            f.write("{} {} {} {}\n".format(t, *sim.m_average))
Exemple #26
0
def run_simulation():
    L = W = 12.5e-9
    H = 5e-9
    sim = Sim(mesh, Ms=8.6e5, unit_length=1e-9)
    sim.set_m((1, 0.01, 0.01))
    sim.alpha = 0.014
    sim.gamma = 221017

    H_app_mT = np.array([0.0, 0.0, 10.0])
    H_app_SI = H_app_mT / (1000 * mu0)
    sim.add(Zeeman(tuple(H_app_SI)))

    sim.add(Exchange(1.3e-11))

    with open(averages_file, "w") as f:
        dt = 10e-12
        t_max = 10e-9
        for t in np.arange(0, t_max, dt):
            sim.run_until(t)
            f.write("{} {} {} {}\n".format(t, *sim.m_average))
Exemple #27
0
def test_exchange_field_should_change_when_M_changes():
    sim = Sim(mesh, Ms)
    sim.set_m(df.Expression(('(2*x[0]-L)/L',
         'sqrt(1 - ((2*x[0]-L)/L)*((2*x[0]-L)/L))',
         '0'), L=length, degree=1))

    exchange = Exchange(A)
    sim.add(exchange)

    # save the beginning value of M and the exchange field for comparison
    # purposes
    old_m = sim.m
    old_H_ex = exchange.compute_field()

    sim.run_until(1e-11)

    # Capture the current value of the exchange field and m.
    m = sim.m
    H_ex = exchange.compute_field()

    # We assert that the magnetisation has indeed changed since the beginning.
    assert not np.array_equal(old_m, m)
    assert not np.array_equal(old_H_ex, H_ex), "H_ex hasn't changed."
Exemple #28
0
def run_simulation():
    L = W = 12.5e-9
    H = 5e-9
    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(L, W, H), 5, 5, 2)
    sim = Sim(mesh, Ms=860e3, name="finmag_validation")
    sim.set_m((1, 0.01, 0.01))
    sim.alpha = 0.014
    sim.gamma = 221017

    H_app_mT = np.array([0.2, 0.2, 10.0])
    H_app_SI = H_app_mT / (1000 * mu0)
    sim.add(Zeeman(tuple(H_app_SI)))
    sim.add(Exchange(1.3e-11))
    sim.add(UniaxialAnisotropy(-1e5, (0, 0, 1)))

    I = 5e-5  # current in A
    J = I / (L * W)  # current density in A/m^2
    theta = 40.0 * pi / 180  # polarisation direction
    phi = pi / 2
    p = (sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta))
    sim.set_stt(current_density=J, polarisation=0.4, thickness=H, direction=p)

    sim.schedule("save_averages", every=5e-12)
    sim.run_until(10e-9)
Exemple #29
0
def run_finmag():

    sim = Sim(mesh, Ms, unit_length=unit_length)
    sim.alpha = 0.5
    sim.set_m(init_m)

    exchange = Exchange(13.0e-12)
    sim.add(exchange)

    dmi = DMI(4e-3)
    sim.add(dmi)

    dmi_direct = DMI(4e-3, method='direct', name='dmi_direct')
    sim.add(dmi_direct)

    df.plot(sim.m_field.f, title='m')

    fun = df.interpolate(HelperExpression(), sim.S3)
    df.plot(fun, title='exact')

    df.plot(Field(sim.S3, dmi.compute_field()).f, title='dmi_petsc')
    df.plot(Field(sim.S3, dmi_direct.compute_field()).f,
            title='dmi_direct',
            interactive=True)
                        maxh=2,
                        save_result=True,
                        filename='nanocylinder',
                        directory='mesh',
                    )

# Simulation and energies -----------------------------------------------------

# Bulk
A = 8.78e-12
D = 1.58e-3
Ms = 3.84e5
B = 0.4
initial_sk_diam = 20

sim = Sim(mesh, Ms=Ms, unit_length=1e-9, name="FeGe_cylinder")


# A linear model for the skyrmion profile
def m_init(pos):
    x, y = pos[0], pos[1]
    if (x**2 + y**2)**0.5 < initial_sk_diam:
        r = (x**2 + y**2)**0.5
        phi = np.arctan2(y, x) + 0.5 * np.pi
        k = np.pi / initial_sk_diam
        return (np.sin(k * r) * np.cos(phi), np.sin(k * r) * np.sin(phi),
                -np.cos(k * r))
    else:
        return (0, 0, 1)