示例#1
0
文件: main.py 项目: fangohr/fidimag
def apply_field1(mesh):

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

    sim.set_tols(rtol=1e-10, atol=1e-10)
    sim.alpha = 0.02
    sim.gamma = 2.211e5
    sim.Ms = 8.0e5

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

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

    demag = Demag()
    sim.add(demag)

    mT = 0.001 / mu0
    print("Applied field = {}".format(mT))

    zeeman = Zeeman([-24.6 * mT, 4.3 * mT, 0], name='H')
    sim.add(zeeman, save_field=True)

    ts = np.linspace(0, 1e-9, 201)
    for t in ts:
        sim.run_until(t)
        print('sim t=%g' % t)
示例#2
0
def apply_field1(mesh):

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

    sim.driver.set_tols(rtol=1e-10, atol=1e-10)
    sim.driver.alpha = 0.02
    sim.driver.gamma = 2.211e5
    sim.Ms = 8.0e5

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

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

    demag = Demag()
    sim.add(demag)

    mT = 0.001 / mu0
    print("Applied field = {}".format(mT))

    zeeman = Zeeman([-24.6 * mT, 4.3 * mT, 0], name='H')
    sim.add(zeeman, save_field=True)

    ts = np.linspace(0, 1e-9, 201)
    for t in ts:
        sim.run_until(t)
        print('sim t=%g' % t)
示例#3
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
示例#4
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
示例#5
0
def relax_system():
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    sim = Sim(mesh, name='relax')
    sim.driver.set_tols(rtol=1e-10, atol=1e-10)
    sim.driver.alpha = 0.5

    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.run_until(t)
示例#6
0
def run(integrator, jacobian):
    name = "sim_" + integrator
    if integrator == "sundials":
        name += "_J1" if jacobian else "_J0"
    sim = Sim(mesh, name, integrator, use_jac=jacobian)
    sim.Ms = 0.86e6
    sim.driver.alpha = 0.5
    sim.set_m((1, 0, 1))
    sim.add(UniformExchange(A=13e-12))
    sim.add(Demag())

    ts = np.linspace(0, 3e-10, 61)
    for t in ts:
        sim.run_until(t)
示例#7
0
def relax_system():
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    sim = Sim(mesh, name='relax')
    sim.driver.set_tols(rtol=1e-10, atol=1e-10)
    sim.driver.alpha = 0.5

    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.run_until(t)
示例#8
0
文件: sim.py 项目: fangohr/fidimag
def run(integrator, jacobian):
    name = "sim_" + integrator
    if integrator == "sundials":
        name += "_J1" if jacobian else "_J0"
    sim = Sim(mesh, name, integrator, use_jac=jacobian)
    sim.Ms = 0.86e6
    sim.alpha = 0.5
    sim.set_m((1, 0, 1))
    sim.add(UniformExchange(A=13e-12))
    sim.add(Demag())

    ts = np.linspace(0, 3e-10, 61)
    for t in ts:
        sim.run_until(t)
示例#9
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 = UniaxialAnisotropy(Ku=1, axis=[0, 0, 1], name='Dx')
    sim.add(anis)

    sim.run_until(1.0)
    print(sim.spin)
    assert sim.spin[0] == 0
    assert sim.spin[2] != 0
示例#10
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 = UniaxialAnisotropy(Ku=1, axis=[0, 0, 1], name='Dx')
    sim.add(anis)

    sim.run_until(1.0)
    print sim.spin
    assert sim.spin[0] == 0
    assert sim.spin[2] != 0
示例#11
0
def excite_system(mesh, beta=0.0):

    # Specify the stt dynamics in the simulation
    sim = Sim(mesh, name='dyn_%g' % beta, driver='llg_stt_cpp')

    sim.driver.set_tols(rtol=1e-12, atol=1e-12)
    sim.driver.alpha = 0.1
    sim.driver.gamma = 2.211e5
    sim.Ms = 8.6e5

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

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

    anis = UniaxialAnisotropy(5e4)
    sim.add(anis)

    # beta is the parameter in the STT torque
    sim.a_J = global_const * 1e11
    sim.p = (1, 0, 0)
    sim.beta = beta

    # The simulation will run for 5 ns and save
    # 500 snapshots of the system in the process
    ts = np.linspace(0, 0.5e-9, 21)

    xs = []
    thetas = []

    for t in ts:
        print('time', t)
        sim.run_until(t)
        spin = sim.spin.copy()
        x, theta = extract_dw(spin)
        xs.append(x)
        thetas.append(theta)
        sim.save_vtk()

    np.savetxt('dw_%g.txt' % beta, np.transpose(np.array([ts, xs, thetas])))
示例#12
0
def excite_system(mesh, beta=0.0):

    # Specify the stt dynamics in the simulation
    sim = Sim(mesh, name='dyn_%g'%beta, driver='llg_stt_cpp')

    sim.driver.set_tols(rtol=1e-12, atol=1e-12)
    sim.driver.alpha = 0.1
    sim.driver.gamma = 2.211e5
    sim.Ms = 8.6e5

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

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

    anis = UniaxialAnisotropy(5e4)
    sim.add(anis)

    # beta is the parameter in the STT torque
    sim.a_J = global_const*1e11
    sim.p = (1,0,0)
    sim.beta = beta

    # The simulation will run for 5 ns and save
    # 500 snapshots of the system in the process
    ts = np.linspace(0, 0.5e-9, 21)

    xs=[]
    thetas=[]

    for t in ts:
        print('time', t)
        sim.run_until(t)
        spin = sim.spin.copy()
        x, theta = extract_dw(spin)
        xs.append(x)
        thetas.append(theta)
        sim.save_vtk()

    np.savetxt('dw_%g.txt'%beta,np.transpose(np.array([ts, xs,thetas])))
示例#13
0
def excite_system(mesh, time=5, snaps=501):

    # Specify the stt dynamics in the simulation
    sim = Sim(mesh, name='dyn', driver='llg_stt')

    # Set the simulation parameters
    sim.set_tols(rtol=1e-12, atol=1e-14)
    sim.alpha = 0.05
    sim.gamma = 2.211e5
    sim.Ms = 8.6e5

    # Load the initial state from the npy file saved
    # in the realxation
    sim.set_m(np.load('m0.npy'))

    # Add the energies
    A = 1.3e-11
    exch = UniformExchange(A=A)
    sim.add(exch)

    anis = UniaxialAnisotropy(5e4)
    sim.add(anis)

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

    # Set the current in the x direction, in A / m
    # beta is the parameter in the STT torque
    sim.jx = -1e12
    sim.beta = 1

    # The simulation will run for x ns and save
    # 'snaps' snapshots of the system in the process
    ts = np.linspace(0, time * 1e-9, snaps)

    for t in ts:
        print('time', t)
        sim.run_until(t)
        sim.save_vtk()
        sim.save_m()
示例#14
0
def excite_system(mesh, time=5, snaps=501):

    # Specify the stt dynamics in the simulation
    sim = Sim(mesh, name='dyn', driver='llg_stt')

    # Set the simulation parameters
    sim.set_tols(rtol=1e-12, atol=1e-14)
    sim.alpha = 0.05
    sim.gamma = 2.211e5
    sim.Ms = 8.6e5

    # Load the initial state from the npy file saved
    # in the realxation
    sim.set_m(np.load('m0.npy'))

    # Add the energies
    A = 1.3e-11
    exch = UniformExchange(A=A)
    sim.add(exch)

    anis = UniaxialAnisotropy(5e4)
    sim.add(anis)

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

    # Set the current in the x direction, in A / m
    # beta is the parameter in the STT torque
    sim.jx = -1e12
    sim.beta = 1

    # The simulation will run for x ns and save
    # 'snaps' snapshots of the system in the process
    ts = np.linspace(0, time * 1e-9, snaps)

    for t in ts:
        print 'time', t
        sim.run_until(t)
        sim.save_vtk()
        sim.save_m()
示例#15
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()
示例#16
0
文件: main.py 项目: fangohr/fidimag
def excite_system(mesh):
    sim = Sim(mesh, name='dyn', driver='llg_stt')
    sim.set_tols(rtol=1e-8, atol=1e-10)
    sim.alpha = 0.5
    sim.gamma = 2.211e5
    sim.Ms = 8.6e5

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

    exch = UniformExchange(A=1.3e-11)
    sim.add(exch)
    dmi = DMI(D=-4e-3)
    sim.add(dmi)
    zeeman = Zeeman((0, 0, 4e5))
    sim.add(zeeman, save_field=True)

    sim.jx = -5e12
    sim.beta = 0

    ts = np.linspace(0, 0.5e-9, 101)
    for t in ts:
        print 'time', t
        sim.run_until(t)
        sim.save_vtk()
示例#17
0
文件: main.py 项目: fangohr/fidimag
def excite_system(mesh):
    sim = Sim(mesh, name='dyn', driver='llg_stt')
    sim.set_tols(rtol=1e-8, atol=1e-10)
    sim.alpha = 0.5
    sim.gamma = 2.211e5
    sim.Ms = 8.6e5

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

    exch = UniformExchange(A=1.3e-11)
    sim.add(exch)
    dmi = DMI(D=-4e-3)
    sim.add(dmi)
    zeeman = Zeeman((0, 0, 4e5))
    sim.add(zeeman, save_field=True)

    sim.jx = -5e12
    sim.beta = 0

    ts = np.linspace(0, 0.5e-9, 101)
    for t in ts:
        print 'time', t
        sim.run_until(t)
        sim.save_vtk()
    # Interactive mode (this needs so set up a proper backend
    # when importing matplotlib for the first time)
    plt.ion()
    # Set False to avoid the execution of the following code
    plt.show(False)

    # ---------------------------------------------------------------------

    # Now run the simulation printing the energy
    for time in times:
        if not run_from_ipython():
            print 'Time: ', time, ' s'
            print 'Total energy: ', sim.compute_energy(), ' J'
            print '\n'
        sim.run_until(time)

        # Update the vector data for the plot (the spins do not move
        # so we don't need to update the coordinates) and redraw
        m = np.copy(sim.spin)
        # reshape rows, transpose and filter according to top layer
        m = m.reshape(3, -1).T[top_z]
        quiv.set_UVC(m[:, 0], m[:, 1], m[:, 2])

        # Update title
        ttime.set_text('Time: {:.4f} ns'.format(time * 1e9))
        tenergy.set_text('Energy: {:.6e} ns'.format(sim.compute_energy()))

        # fig.show()
        fig.canvas.draw()
示例#19
0
    # Interactive mode (this needs so set up a proper backend
    # when importing matplotlib for the first time)
    plt.ion()
    # Set False to avoid the execution of the following code
    plt.show(False)

    # ---------------------------------------------------------------------

    # Now run the simulation printing the energy
    for time in times:
        if not run_from_ipython():
            print 'Time: ', time, ' s'
            print 'Total energy: ', sim.compute_energy(), ' J'
            print '\n'
        sim.run_until(time)

        # Update the vector data for the plot (the spins do not move
        # so we don't need to update the coordinates) and redraw
        m = np.copy(sim.spin)
        # reshape rows, transpose and filter according to top layer
        m = m.reshape(3, -1).T[top_z]
        quiv.set_UVC(m[:, 0], m[:, 1], m[:, 2])

        # Update title
        ttime.set_text('Time: {:.4f} ns'.format(time * 1e9))
        tenergy.set_text('Energy: {:.6e} ns'.format(sim.compute_energy()))

        # fig.show()
        fig.canvas.draw()
示例#20
0
# Finite difference mesh.
mesh = FDMesh(nx=1, ny=1, dx=10, dy=10, unit_length=1e-9)

sim = Sim(mesh)
sim.Ms = Ms
sim.alpha = alpha
sim.gamma = gamma
sim.add(Zeeman((0, 0, H)))
sim.set_m((1, 0, 0))  # initial magnetisation

# Sampling time steps.
t_array = np.arange(0, 5e-9, 0.01e-9)

mx_simulation = []
for t in t_array:
    sim.run_until(t)
    m = sim.spin.reshape((len(sim.spin) / 3, 3))
    mx_simulation.append(m[:, 0][0])


###################
# Analytic solution
###################
mx_analytic = macrospin_analytic_solution(alpha, gamma, H, t_array)

###################
# Plot comparison.
###################
plt.figure(figsize=(8, 5))
plt.plot(t_array / 1e-9, mx_analytic, "o", label="analytic")
plt.plot(t_array / 1e-9, mx_simulation, linewidth=2, label="simulation")