Ejemplo n.º 1
0
def relax_system(mesh):

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

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

    sim.set_m(init_m)

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

    demag = Demag()
    sim.add(demag)

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

    dmi2 = DMI(D=2e-3, dmi_type="interfacial")
    sim.add(dmi2)

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

    sim.relax(dt=1e-13,
              stopping_dmdt=5e4,
              max_steps=5000,
              save_m_steps=100,
              save_vtk_steps=50)

    #np.save('m0.npy', sim.spin)
    fd = demag.compute_field(sim.spin)
    fe = exch.compute_field(sim.spin)
    fdmi = dmi.compute_field(sim.spin)
    fdmi2 = dmi2.compute_field(sim.spin)
    fanis = anis.compute_field(sim.spin)
    np.savetxt(
        "test_fields.txt",
        np.transpose([
            np.concatenate((sim.Ms, sim.Ms, sim.Ms, [0.0])),
            np.concatenate((sim.spin, [100])),
            np.concatenate((fd, [demag.compute_energy()])),
            np.concatenate((fe, [exch.compute_energy()])),
            np.concatenate((fdmi, [dmi.compute_energy()])),
            np.concatenate((fdmi2, [dmi2.compute_energy()])),
            np.concatenate((fanis, [anis.compute_energy()]))
        ]),
        header=
        "Generated by Fidimag. Size=20x5x3, 2.5nm x 2.5nm x 3nm, Ms=8.0e5A/m, A=1.3e-11 J/m,"
        +
        "  D=4e-3 J/m^2, D_int=2e-3 J/m^2, Ku=-3e4 J/m^3 axis=(0,0,1).\n  Ms "
        + "".ljust(20) + " m0 " + "".ljust(20) + "demag" + "".ljust(20) +
        "exch" + "".ljust(22) + "dmi" + "".ljust(22) + "dmi_interfacial" +
        "".ljust(22) + "anis")
Ejemplo n.º 2
0
def test_dw_dmi(mesh=mesh, do_plot=False):

    Ms = 8.0e5
    sim = Sim(mesh, name='relax')

    sim.set_m(m_init_dw)

    sim.set_tols(rtol=1e-8, atol=1e-12)
    sim.Ms = Ms
    sim.alpha = 0.5
    sim.do_precession = False

    A = 1.3e-11
    D = 4e-4
    Kx = 8e4
    Kp = -6e5

    sim.add(UniformExchange(A))
    sim.add(DMI(D))
    sim.add(UniaxialAnisotropy(Kx, axis=[1, 0, 0], name='Kx'))

    sim.relax(stopping_dmdt=0.01)

    xs = np.array([p[0] for p in mesh.coordinates])
    mx, my, mz = analytical(xs, A=A, D=D, K=Kx)
    mxyz = sim.spin.copy()
    mxyz = mxyz.reshape(-1, 3)

    assert max(abs(mxyz[:, 0] - mx)) < 0.002
    assert max(abs(mxyz[:, 1] - my)) < 0.002
    assert max(abs(mxyz[:, 2] - mz)) < 0.0006

    if do_plot:

        save_plot(mxyz, mx, my, mz)
Ejemplo n.º 3
0
def relax_system(mesh):

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

    sim.set_tols(rtol=1e-6, atol=1e-6)
    sim.alpha = 0.5
    sim.gamma = 2.211e5
    sim.Ms = 8.6e5
    sim.do_precession = False

    sim.set_m(init_m)
    #sim.set_m((0,0.1,1))
    #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=0.5,
              max_steps=5000,
              save_m_steps=None,
              save_vtk_steps=50)

    np.save('m0.npy', sim.spin)
Ejemplo n.º 4
0
def relax_system(mesh):

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

    # Simulation parameters
    sim.set_tols(rtol=1e-8, atol=1e-10)
    sim.alpha = 0.5
    sim.gamma = 2.211e5
    sim.Ms = 8.6e5
    sim.do_procession = False

    # The initial state passed as a function
    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)

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

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

    np.save('m0.npy', sim.spin)
Ejemplo n.º 5
0
def run_fidimag(mesh):

    mu0 = 4 * np.pi * 1e-7

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

    sim = Sim(mesh)

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

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

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

    sim.add(UniformExchange(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
    return m.copy()
Ejemplo n.º 6
0
def relax_neb(k, maxst, simname, init_im, interp, save_every=10000,
              coordinates='Cartesian'):
    """
    Execute a simulation with the NEB function of the FIDIMAG code, for an
    elongated particle (long cylinder)

    The simulations are made for a specific spring constant 'k' (a float),
    number of images 'init_im', interpolations between images 'interp'
    (an array) and a maximum of 'maxst' steps.
    'simname' is the name of the simulation, to distinguish the
    output files.

    --> vtks and npys are saved in files starting with the 'simname' string

    """

    # Prepare simulation
    # We define the cylinder with the Magnetisation function
    sim = Sim(mesh)
    sim.Ms = two_part

    # sim.add(UniformExchange(A=A))

    # Uniaxial anisotropy along x-axis
    sim.add(UniaxialAnisotropy(Kx, axis=(1, 0, 0)))

    # Define many initial states close to one extreme. We want to check
    # if the images in the last step, are placed mostly in equally positions
    init_images = init_im

    # Number of images between each state specified before (here we need only
    # two, one for the states between the initial and intermediate state
    # and another one for the images between the intermediate and final
    # states). Thus, the number of interpolations must always be
    # equal to 'the number of initial states specified', minus one.
    interpolations = interp

    if coordinates == 'Spherical':
        neb = NEBM_Spherical(sim,
                             init_images,
                             interpolations=interpolations,
                             spring_constant=k,
                             name=simname
                             )
    if coordinates == 'Geodesic':
        neb = NEBM_Geodesic(sim,
                            init_images,
                            interpolations=interpolations,
                            spring_constant=k,
                            name=simname,
                            integrator='sundials'
                            )

    neb.relax(max_iterations=2000,
              save_vtks_every=save_every,
              save_npys_every=save_every,
              stopping_dYdt=1e-4,
              dt=1e-6
              )
def elongated_part_sim():
    sim = Sim(mesh)
    sim.Ms = lambda r: cylinder(r, centre, 8)
    sim.add(UniformExchange(A=A))
    sim.add(UniaxialAnisotropy(Kx, axis=(0, 1, 0)))  # Anisotropy along y
    sim.add(Demag())

    return sim
Ejemplo n.º 8
0
def setup_domain_wall_cobalt(node_count=NODE_COUNT, A=A_Co, Ms=Ms_Co, K1=K1_Co, length=LENGTH, do_precession=True, unit_length=UNIT_LENGTH):
    a = length / node_count  # cell size
    mesh = CuboidMesh(dx=a, dy=a, dz=a, nx=node_count, ny=1, nz=1, unit_length=unit_length)
    sim = Sim(mesh, "dw_cobalt")
    sim.Ms = Ms
    sim.set_m(lambda r: initial_m(r, length))
    sim.do_precession = do_precession
    sim.add(UniformExchange(A))
    sim.add(UniaxialAnisotropy(K1, (0, 0, 1)))
    sim.pins = lambda r: 1 if (r[0] < a or r[0] > LENGTH - a) else 0
    return sim
Ejemplo n.º 9
0
def create_simulation(mesh):

    sim = Sim(mesh)
    sim.Ms = 8.6e5

    sim.set_m((1, 0, 0))
    sim.add(UniformExchange(A=1.3e-11))
    # sim.add(Demag())
    #sim.add(UniaxialAnisotropy(Kx, (1, 0, 0), name='Kx'))
    anis = UniaxialAnisotropy(1e5, axis=(1, 0, 0))
    sim.add(anis)

    return sim
Ejemplo n.º 10
0
def test_sim_pin():
    mesh = CuboidMesh(nx=3, ny=2, nz=1)
    sim = Sim(mesh, integrator='sundials_openmp')
    sim.set_m((0, 0.8, 0.6))
    sim.alpha = 0.1
    sim.driver.gamma = 1.0
    sim.pins = pin_fun

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

    sim.driver.run_until(1.0)
    print(sim.spin)
    assert sim.spin[0] == 0
    assert sim.spin[2] != 0
Ejemplo n.º 11
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
Ejemplo n.º 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])))
Ejemplo n.º 13
0
def excite_system(mesh):

    # Specify the stt dynamics in the simulation
    sim = Sim(mesh, name='dyn2', driver='llg_stt')
    sim.driver.set_tols(rtol=1e-12, atol=1e-14)
    sim.driver.alpha = 0.2
    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)

    # 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
    def jx_func(pos, t):
        T = 1e-9
        return (-1e12 + -0.1e12 * np.sin(t / T))

    sim.driver.jx_function = jx_func
    sim.driver.beta = 0.01

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

    for t in ts:
        print('time', t)
        sim.driver.run_until(t)
        print('j = {}'.format(sim.driver._jx[0]))
        sim.save_vtk()
        sim.save_m()
Ejemplo n.º 14
0
def relax_string(maxst, simname, init_im, interp, save_every=10000):
    """
    """

    # Prepare simulation
    # We define the cylinder with the Magnetisation function
    sim = Sim(mesh)
    sim.Ms = two_part

    # sim.add(UniformExchange(A=A))

    # Uniaxial anisotropy along x-axis
    sim.add(UniaxialAnisotropy(Kx, axis=(1, 0, 0)))

    # Define many initial states close to one extreme. We want to check
    # if the images in the last step, are placed mostly in equally positions
    init_images = init_im

    # Number of images between each state specified before (here we need only
    # two, one for the states between the initial and intermediate state
    # and another one for the images between the intermediate and final
    # states). Thus, the number of interpolations must always be
    # equal to 'the number of initial states specified', minus one.
    interpolations = interp

    string = StringMethod(sim,
                          init_images,
                          interpolations=interpolations,
                          name=simname,
                          integrator='verlet')
    string.integrator.stepsize = 1e-4

    # dt = integrator.stepsize means after every integrator step, the images
    # are rescaled. We can run more integrator steps if we decrease the
    # stepsize, e.g. dt=1e-3 and integrator.stepsize=1e-4
    string.relax(max_iterations=maxst,
                 save_vtks_every=save_every,
                 save_npys_every=save_every,
                 stopping_dYdt=1e-14,
                 dt=1e-4)

    return string
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
sim.Ms = args.Ms

exch = UniformExchange(A=args.A)
sim.add(exch)

dmi = DMI(D=(args.D * 1e-3), type='interfacial')
sim.add(dmi)

if args.B:
    zeeman = Zeeman((0, 0, args.B / mu0))
    sim.add(zeeman, save_field=True)

if args.k_u:
    # Uniaxial anisotropy along + z-axis
    sim.add(UniaxialAnisotropy(args.k_u, axis=(0, 0, 1)))

if args.Demag:
    print 'Using Demag!'
    sim.add(Demag())

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

# Load magnetisation profile ---------------------------------------------

# Change the skyrmion initial configuration according to the
# chirality of the system (give by the DMI constant)
if args.initial_state_skyrmion_down:
    if args.D > 0:
        sim.set_m(lambda x: generate_skyrmion_down(x, -1))
    else: