Ejemplo n.º 1
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.1

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

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

    w0 = 2 * np.pi * 1e9

    def sin_fun(t):
        return np.sin(w0 * t)

    h0 = 1e3
    theta = np.pi / 20
    hx = h0 * np.sin(theta)
    hz = h0 * np.cos(theta)
    hx = TimeZeeman([hx, 0, hz], sin_fun, name='h')
    sim.add(hx, save_field=True)

    ts = np.linspace(0, 5e-9, 5001)

    for t in ts:
        sim.run_until(t)
Ejemplo n.º 2
0
def relax_system():
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    sim = Sim(mesh, name='relax')
    sim.set_tols(rtol=1e-10, atol=1e-10)
    sim.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)
Ejemplo n.º 3
0
    for t in ts:
        print 'time', t
        sim.run_until(t)
        sim.save_vtk()
        sim.save_m()


if __name__ == '__main__':

    # We will crate a mesh with 1000 elements of elements
    # in the x direction, and 1 along y and z
    # (so we have a 1D system)
    mesh = CuboidMesh(nx=1000,
                      ny=1,
                      nz=1,
                      dx=2,
                      dy=2,
                      dz=2.0,
                      unit_length=1e-9)

    # Relax the initial state
    relax_system(mesh)
    deal_plot([['m0.npy', 'mx']], 'initial_state.pdf')

    # Now we excite the system with the current
    excite_system(mesh)

    # Plot the dynamics of a single spin
    # deal_plot_dynamics()

    # We can plot the m_z component for a number snapshots
Ejemplo n.º 4
0
    # sim.set_m(np.load('m0.npy'))

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

    dmi = DMI(D=1.3e-3)
    sim.add(dmi)

    anis = UniaxialAnisotropy(-3.25e4, axis=(0, 0, 1))
    sim.add(anis)

    zeeman = Zeeman((0, 0, 6.014576e4))
    sim.add(zeeman, save_field=True)

    sim.relax(dt=1e-13, stopping_dmdt=1e-2, max_steps=5000,
              save_m_steps=None, save_vtk_steps=50)

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


if __name__ == '__main__':

    mesh = CuboidMesh(
        nx=501, ny=501, nz=1, dx=2.0, dy=2.0, dz=2.0, unit_length=1e-9, periodicity=(True, True, False))

    relax_system(mesh)

    # apply_field1(mesh)
    # deal_plot()
Ejemplo n.º 5
0
    plt.plot(ts, mx, '--', label='m_fidimag', dashes=(2, 2))
    plt.plot(ts, my, '--', label='', dashes=(2, 2))
    plt.plot(ts, mz, '--', label='', dashes=(2, 2))
    plt.plot(ts2, mx2, '--', label='m_oommf')
    plt.plot(ts2, my2, '--', label='')
    plt.plot(ts2, mz2, '--', label='')

    plt.title('std4')
    plt.legend()
    #plt.xlim([0, 0.012])
    #plt.ylim([-5, 100])
    plt.xlabel(r'Ts (ns)')
    # plt.ylabel('Susceptibility')
    plt.savefig('cmp.pdf')


if __name__ == '__main__':

    mesh = CuboidMesh(nx=200,
                      ny=50,
                      nz=1,
                      dx=2.5,
                      dy=2.5,
                      dz=3,
                      unit_length=1e-9)

    relax_system(mesh)

    apply_field1(mesh)
    deal_plot()
Ejemplo n.º 6
0
def test_prb88_184422():
    mu0 = 4 * np.pi * 1e-7

    Ms = 8.6e5
    A = 16e-12
    D = 3.6e-3
    K = 510e3

    mesh = CuboidMesh(nx=100, dx=1, unit_length=1e-9)

    sim = Sim(mesh)

    sim.driver.set_tols(rtol=1e-10, atol=1e-14)

    sim.driver.alpha = 0.5
    sim.driver.gamma = 2.211e5
    sim.Ms = Ms
    sim.do_precession = False

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

    sim.add(UniformExchange(A=A))
    sim.add(DMI(-D, type='interfacial'))
    sim.add(UniaxialAnisotropy(K, axis=(0, 0, 1)))

    sim.relax(dt=1e-13,
              stopping_dmdt=0.01,
              max_steps=5000,
              save_m_steps=None,
              save_vtk_steps=50)

    m = sim.spin

    mx, my, mz = np.split(m, 3)

    x_array = np.linspace(-49.5, 49.5, 100)

    #plt.plot(x_array, mx)
    #plt.plot(x_array, my)
    #plt.plot(x_array, mz)

    mesh = df.IntervalMesh(100, -50, 50)

    Delta = np.sqrt(A / K)
    xi = 2 * A / D

    Delta_s = Delta * 1e9

    V = df.FunctionSpace(mesh, "Lagrange", 1)
    u = df.TrialFunction(V)
    v = df.TestFunction(V)
    u_ = df.Function(V)
    F = -df.inner(df.nabla_grad(u), df.nabla_grad(v)) * df.dx - \
        (0.5 / Delta_s**2) * df.sin(2 * u) * v * df.dx
    F = df.action(F, u_)

    J = df.derivative(F, u_, u)

    # the boundary condition is from equation (8)
    theta0 = np.arcsin(Delta / xi)
    ss = 'x[0]<0? %g: %g ' % (-theta0, theta0)

    u0 = df.Expression(ss)

    def u0_boundary(x, on_boundary):
        return on_boundary

    bc = df.DirichletBC(V, u0, u0_boundary)

    problem = df.NonlinearVariationalProblem(F, u_, bcs=bc, J=J)
    solver = df.NonlinearVariationalSolver(problem)
    solver.solve()

    u_array = u_.vector().array()

    mx_df = []
    for x in x_array:
        mx_df.append(u_(x))

    #plt.plot(x_array, mx_df)

    assert abs(np.max(mx - mx_df)) < 0.05
Ejemplo n.º 7
0
    anis = UniaxialAnisotropy(-3.25e4, axis=(0, 0, 1))
    sim.add(anis)

    zeeman = Zeeman((0, 0, 6.014576e4))
    sim.add(zeeman, save_field=True)

    sim.relax(dt=1e-13,
              stopping_dmdt=1e-2,
              max_steps=5000,
              save_m_steps=None,
              save_vtk_steps=50)

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


if __name__ == '__main__':

    mesh = CuboidMesh(nx=501,
                      ny=501,
                      nz=1,
                      dx=2.0,
                      dy=2.0,
                      dz=2.0,
                      unit_length=1e-9,
                      pbc='xy')

    relax_system(mesh)

    # apply_field1(mesh)
    # deal_plot()
Ejemplo n.º 8
0
    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()


if __name__ == '__main__':

    mesh = CuboidMesh(nx=80,
                      ny=80,
                      nz=2,
                      dx=2.5,
                      dy=2.5,
                      dz=5.0,
                      unit_length=1e-9)

    # relax_system(mesh)

    excite_system(mesh)

    # apply_field1(mesh)
    # deal_plot()
Ejemplo n.º 9
0
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt

import numpy as np
from micro import Sim
from common import CuboidMesh
from micro import Zeeman
from fidimag.common.fileio import DataReader

from util.omf import OMF2

mesh = CuboidMesh(nx=100, dx=1, unit_length=1e-9)


def plot_all():

    font = {'family': 'serif',
            'weight': 'normal',
            'size': 12,
            }

    plt.rc('font', **font)

    Ms = 8.6e5
    omf = OMF2('oommf/dmi-Oxs_TimeDriver-Magnetization-00-0000963.omf')
    mx = omf.get_all_mag(comp='x') / Ms
    my = omf.get_all_mag(comp='y') / Ms
    mz = omf.get_all_mag(comp='z') / Ms
    xs = np.linspace(0.5, 100 - 0.5, 100)
Ejemplo n.º 10
0
    """
    n=20
    for i in range(1,n):
        theta = i*np.pi/n
        mx = -np.cos(theta)
        my = np.sin(theta)
        init_images.append((mx,my,0))
    """

    # init_images.append(np.load('m_final.npy'))

    init_images = [(-1, 0, 0), init_dw, (1, 0, 0)]

    neb = NEB_Sundials(
        sim, init_images, interpolations=[6, 6], name='neb', spring=1e8)

    # neb.add_noise(0.1)

    neb.relax(dt=1e-8, max_steps=5000, save_vtk_steps=500,
              save_npy_steps=500, stopping_dmdt=100)

if __name__ == "__main__":

    mesh = CuboidMesh(nx=160, ny=1, nz=1, dx=4.0, dy=4.0, dz=4.0, unit_length=1e-9)

    sim = create_simulation(mesh)
    # relax_two_state(mesh)
    relax_system(sim)
    plot_energy_2d('neb')
    plot_energy_3d('neb')