Ejemplo n.º 1
0
def test_sim_single_spin(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)
    # print mz
    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    print(sim.stat())

    if do_plot:
        ts_ns = np.array(real_ts) * 1e9
        plt.plot(ts_ns, mx, ".", label="mx", color='DarkGreen')
        plt.plot(ts_ns, my, ".", label="my", color='darkslateblue')
        plt.plot(ts_ns, mz, ".", label="mz", color='m')
        plt.plot(ts_ns, a_mx, "--", label="analytical", color='b')
        plt.plot(ts_ns, a_my, "--",  color='b')
        plt.plot(ts_ns, a_mz, "--",  color='b')
        plt.xlabel("time (ns)")
        plt.ylabel("m")
        plt.title("integrating a macrospin")
        plt.legend()
        plt.savefig("single_spin.pdf")

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

    assert np.max(np.abs(mz - a_mz)) < 5e-7
Ejemplo n.º 2
0
def test_sim_single_spin(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)
    # print mz
    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    print sim.stat()

    if do_plot:
        ts_ns = np.array(real_ts) * 1e9
        plt.plot(ts_ns, mx, ".", label="mx", color='DarkGreen')
        plt.plot(ts_ns, my, ".", label="my", color='darkslateblue')
        plt.plot(ts_ns, mz, ".", label="mz", color='m')
        plt.plot(ts_ns, a_mx, "--", label="analytical", color='b')
        plt.plot(ts_ns, a_my, "--",  color='b')
        plt.plot(ts_ns, a_mz, "--",  color='b')
        plt.xlabel("time (ns)")
        plt.ylabel("m")
        plt.title("integrating a macrospin")
        plt.legend()
        plt.savefig("single_spin.pdf")

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

    assert np.max(np.abs(mz - a_mz)) < 5e-7
Ejemplo n.º 3
0
def excite_system(mesh):

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

    sim.driver.set_tols(rtol=1e-10, atol=1e-14)
    sim.driver.alpha = 0.01
    sim.driver.gamma = 2.211e5
    sim.Ms = spatial_Ms

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

    A = 1.3e-11
    exch = UniformExchange(A=A)
    sim.add(exch)

    demag = Demag(pbc_2d=True)
    sim.add(demag)

    mT = 795.7747154594767
    sigma = 0.08e-9

    def gaussian_fun(t):

        return np.exp(-0.5 * (t / sigma)**2)

    zeeman = TimeZeeman((80 * mT, 0, 0), time_fun=gaussian_fun, name='hx')
    #zeeman = Zeeman((100*mT,0,0), name='hx')
    sim.add(zeeman, save_field=True)

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

    for t in ts:
        print('time', t)
        print('length:', sim.spin_length()[0:200])
        sim.run_until(t)
        sim.save_vtk()