Пример #1
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.driver.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.driver.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)
def relax_system(mesh):

    sim = Sim(mesh, chi=1e-3, name='relax', driver='llbar_full')

    sim.driver.set_tols(rtol=1e-7, atol=1e-7)
    sim.Ms = 8.0e5
    sim.driver.alpha = 0.1
    sim.beta = 0
    sim.driver.gamma = 2.211e5

    sim.set_m((1, 0.25, 0.1))
    # sim.set_m(np.load('m0.npy'))

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

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

    demag = Demag()
    sim.add(demag)

    ONE_DEGREE_PER_NS = 17453292.52

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

    np.save('m0.npy', sim.spin)
Пример #3
0
def compute_field():

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

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

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

    sim.set_m((0, 0, 1))
    # 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)
    field = demag.compute_field()
    print(field)

    np.save('m0.npy', sim.spin)
Пример #4
0
def test_dmi_field_oommf(D=4.1e-3, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    dmi = DMI(D=D, type='interfacial')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = dmi.compute_field()

    init_m0 = """
        return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
        """
    # TODO: check the sign of DMI in OOMMF.
    #field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=-D)
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_dmi_field_oommf.ohf')
    ovf = OMF2(omf_file)
    field_oommf = ovf.get_all_mags()

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12
Пример #5
0
def relax_system(mesh):

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

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

    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

    ONE_DEGREE_PER_NS = 17453292.52

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

    np.save('m0.npy', sim.spin)
Пример #6
0
def test_zeeman_energy():

    mu0 = 4 * np.pi * 1e-7
    # A system of 8 cells ( not using nm units)
    mesh = CuboidMesh(dx=2, dy=2, dz=2,
                      nx=2, ny=2, nz=2
                      )

    sim = Sim(mesh)
    Ms = 1e5
    sim.set_Ms(Ms)

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

    H = 0.1 / mu0
    zeeman = Zeeman((0, 0, H))
    sim.add(zeeman)

    field = zeeman.compute_field()
    zf = sim.get_interaction('Zeeman')

    #                             ->    ->
    # Expected energy: Int ( -mu0 M  *  H  )  dV
    # Since we have 8 cells with the same M, we just sum their contrib 
    exp_energy = 8 * (-mu0 * H * Ms * mesh.dx * mesh.dy * mesh.dz)

    assert np.abs(zf.compute_energy() - exp_energy) < 1e-10
Пример #7
0
def test_exch_field_oommf(A=1e-11, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

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

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = exch.compute_field()

    init_m0 = """
    return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
    """
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'omfs',
                            'test_exch_field_oommf.ohf'
                            )
    ovf = OMF2(omf_file)
    field_oommf = ovf.get_all_mags()

    #field_oommf = compute_exch_field(mesh, Ms=Ms, init_m0=init_m0, A=A)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)
    assert max([mx0, mx1, mx2]) < 1e-12
Пример #8
0
def test_dmi_field_oommf(D=4.1e-3, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    dmi = DMI(D=D, type='interfacial')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = dmi.compute_field()

    init_m0 = (r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] '
               + r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] '
               + r'0 '
               + r'] ')

    # TODO: check the sign of DMI in OOMMF.
    field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=-D)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12
Пример #9
0
def test_dmi_field_oommf(D=4.1e-3, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    dmi = DMI(D=D, type='interfacial')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = dmi.compute_field()

    init_m0 = (
        r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] ' +
        r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] ' + r'0 ' + r'] ')

    # TODO: check the sign of DMI in OOMMF.
    field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=-D)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12
Пример #10
0
def relax_system(mesh):

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

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

    sim.set_m(init_m)

    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.relax(dt=1e-13, stopping_dmdt=1e-2,
              save_m_steps=None, save_vtk_steps=50)

    np.save('m0.npy', sim.spin)
Пример #11
0
def compute_field():

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

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

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

    sim.set_m((0,0,1))
    # 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)
    field=demag.compute_field()
    print field

    np.save('m0.npy', sim.spin)
Пример #12
0
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)
Пример #13
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.driver.run_until(t)
        print('sim t=%g' % t)
Пример #14
0
def test_energy_dmi(Ms=8e5, D=1.32e-3):

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

    sim.Ms = Ms

    dmi = DMI(D=D, type='interfacial')
    #dmi = DMI(D=D, type='bulk')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 1)

    sim.set_m(init_m)

    dmi_energy = dmi.compute_energy()

    # init_m0="""
    # return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 1]
    #"""

    #field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=D)

    dmi_energy_oommf = -4.5665527749090378e-20

    print 'dmi energy', dmi_energy

    assert abs(dmi_energy - dmi_energy_oommf) / dmi_energy_oommf < 1e-15
Пример #15
0
def test_exch_field_oommf(A=1e-11, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

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

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = exch.compute_field()

    init_m0 = """
    return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
    """
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'omfs',
                            'test_exch_field_oommf.ohf'
                            )
    ovf = OMF2(omf_file)
    field_oommf = ovf.get_all_mags()

    #field_oommf = compute_exch_field(mesh, Ms=Ms, init_m0=init_m0, A=A)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)
    assert max([mx0, mx1, mx2]) < 1e-12
Пример #16
0
def relax_system(mesh):

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

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

    sim.set_m((1, 0.25, 0.1))
    # sim.set_m(np.load('m0.npy'))

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

    demag = Demag()
    sim.add(demag)

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

    np.save('m0.npy', sim.spin)
Пример #17
0
def test_dmi_field_oommf(D=4.1e-3, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    dmi = DMI(D=D, dmi_type='interfacial')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = dmi.compute_field()

    init_m0 = """
        return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
        """
    # TODO: check the sign of DMI in OOMMF.
    #field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=-D)
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_dmi_field_oommf.ohf')
    ovf = OMF2(omf_file)
    field_oommf = ovf.get_all_mags()

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12
Пример #18
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)
Пример #19
0
def test_exch_field_oommf(A=1e-11, Ms=2.6e5):
    """
    Compare the exchange field from Fidimag with an equivalent
    OOMMF simulation. OOMMF field data is taken from an OVF file.
    """
    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

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

    def init_m(pos):
        x, y, z = pos
        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = exch.compute_field()

    # An equivalent initial magnetisation for OOMMF
    # The spatial variables are rescale since they are in nm
    init_m0 = (r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] '
               + r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] '
               + r'0 '
               + r'] ')

    field_oommf = compute_exch_field(mesh, Ms=Ms, init_m0=init_m0, A=A)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    # Test if the maximum relative errors between both simulations
    # is small enough, for every field component
    assert max([mx0, mx1, mx2]) < 1e-12
Пример #20
0
def test_sim_init_m():
    mesh = CuboidMesh(nx=3, ny=4, nz=5)
    sim = Sim(mesh)
    sim.set_m((0, 1, 0))
    sim.spin.shape = (-1, 3)
    spin_y = sim.spin[:, 1]
    assert(spin_y.any() == 1)
Пример #21
0
def test_compute_field():
    """In an infinite film, we expect the demag tensor to be (0, 0, -1), and thus the
    magnetisation, if aligned in 0, 0, 1 direction, to create a demag field pointing
    with equal strength in the opposite direction.
    """

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

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

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

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

    demag = Demag(pbc_2d=True)
    sim.add(demag)
    field = demag.compute_field()
    print((1 + field[2] / 8.6e5))
    assert abs(1 + field[2] / 8.6e5) < 1e-10
Пример #22
0
def relax_system(mesh):

    sim = Sim(mesh, chi=1e-3, name='relax', driver='llbar_full')

    sim.set_tols(rtol=1e-7, atol=1e-7)
    sim.Ms = 8.0e5
    sim.alpha = 0.1
    sim.beta = 0
    sim.gamma = 2.211e5

    sim.set_m((1, 0.25, 0.1))
    # sim.set_m(np.load('m0.npy'))

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

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

    demag = Demag()
    sim.add(demag)

    ONE_DEGREE_PER_NS = 17453292.52

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

    np.save('m0.npy', sim.spin)
Пример #23
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()
Пример #24
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, dmi_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()
Пример #25
0
def create_simulation(mesh, simname):
    # Initiate a simulation object. PBCs are specified in the mesh
    sim = Sim(mesh, name=simname)
    # Use default gamma value
    # sim.gamma = const.gamma

    # Magnetisation in A/m
    sim.Ms = 148367

    # We could change the parameters using this option
    # sim.set_options(gamma=const.gamma)

    # Initial magnetisation profile from the function
    sim.set_m((0, 0.2, 0.8))

    # Exchange constant
    A = 1.602e-12
    exch = UniformExchange(A)
    sim.add(exch)

    # DMI constant
    D = 3.84e-3
    dmi = DMI(D, dmi_type='interfacial')
    sim.add(dmi)

    # Zeeman field
    sim.add(Zeeman((0, 0, 25. / c.mu_0)))

    # Tune the damping for faster convergence
    sim.driver.alpha = 0.5
    # Remove precession
    sim.driver.do_precession = False
    sim.driver.set_tols(rtol=1e-12, atol=1e-12)

    return sim
Пример #26
0
def relax_system(mesh):

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

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

    sim.set_m((1,1,1))
    # sim.set_m(np.load('m0.npy'))

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

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

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

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

    np.save('m0.npy', sim.spin)
Пример #27
0
def relax_system(mesh):

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

    # Simulation parameters
    sim.driver.set_tols(rtol=1e-8, atol=1e-10)
    sim.driver.alpha = 0.5
    sim.driver.gamma = 2.211e5
    sim.Ms = 8.6e5
    sim.do_precession = 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)

    # 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)
Пример #28
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)
Пример #29
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)
Пример #30
0
def relax_system(mesh):

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

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

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

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

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

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

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

    np.save("m0.npy", sim.spin)
Пример #31
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)
Пример #32
0
def excite_system(mesh):

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

    sim.driver.set_tols(rtol=1e-8, atol=1e-8)
    sim.driver.alpha = 0.1
    sim.driver.gamma = 2.211e5
    sim.Ms = 8.0e5
    sim.driver.p = 1

    sim.set_m(np.load('npys/m0_cpu.npy'))

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

    sim.add(Demag())

    sim.driver.jx = -1e12
    sim.driver.beta = 0.05

    ts = np.linspace(0, 8e-9, 801)

    for t in ts:
        print('time', t)
        sim.driver.run_until(t)
Пример #33
0
def test_sim_init_m():
    mesh = CuboidMesh(nx=3, ny=4, nz=5)
    sim = Sim(mesh)
    sim.set_m((0, 1, 0))
    sim.spin.shape = (-1, 3)
    spin_y = sim.spin[:, 1]
    assert (spin_y.any() == 1)
Пример #34
0
def test_exch_field_oommf(A=1e-11, Ms=2.6e5):
    """
    Compare the exchange field from Fidimag with an equivalent
    OOMMF simulation. OOMMF field data is taken from an OVF file.
    """
    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

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

    def init_m(pos):
        x, y, z = pos
        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = exch.compute_field()

    # An equivalent initial magnetisation for OOMMF
    # The spatial variables are rescale since they are in nm
    init_m0 = (
        r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] ' +
        r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] ' + r'0 ' + r'] ')

    field_oommf = compute_exch_field(mesh, Ms=Ms, init_m0=init_m0, A=A)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    # Test if the maximum relative errors between both simulations
    # is small enough, for every field component
    assert max([mx0, mx1, mx2]) < 1e-12
Пример #35
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)

    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.relax(dt=1e-13,
              stopping_dmdt=1e-2,
              save_m_steps=None,
              save_vtk_steps=50)

    np.save('m0.npy', sim.spin)
Пример #36
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")
def setup_simulation(mesh, m0, simulation_name, integrator="sundials", use_jac=False):
    sim = Sim(mesh, name=simulation_name, integrator=integrator, use_jac)
    sim.set_m(m0)
    sim.Ms = Ms
    sim.alpha = alpha
    sim.gamma = gamma
    sim.add(UniformExchange(A))
    sim.add(Demag())
    return sim
Пример #38
0
def test_with_oommf_spatial_Ms(A=1e-11):
    def spatial_Ms(pos):
        x, y = pos[0], pos[1]

        if x**2 + y**2 < 5**2:
            return 2e4
        else:
            return 0

    init_m0 = (
        r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] ' +
        r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] ' + r'0 ' + r'] ')

    init_Ms = """

    if { ($x * $x + $y * $y) < 5e-9 * 5e-9 } {
        return 2e4
    } else {
        return 0
    }

    """

    mesh = CuboidMesh(nx=12, ny=10, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = spatial_Ms

    def init_m(pos):
        x, y, z = pos
        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

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

    demag = Demag()
    sim.add(demag)

    field = exch.compute_field()
    field_oommf = compute_exch_field(mesh,
                                     init_m0=init_m0,
                                     A=A,
                                     spatial_Ms=init_Ms)
    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12

    field = demag.compute_field()
    field_oommf = compute_demag_field(mesh,
                                      spatial_Ms=init_Ms,
                                      init_m0=init_m0)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-11
Пример #39
0
def test_with_oommf_spatial_Ms(A=1e-11):

    def spatial_Ms(pos):
        x, y = pos[0], pos[1]

        if x ** 2 + y ** 2 < 5 ** 2:
            return 2e4
        else:
            return 0

    init_m0 = (r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] '
               + r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] '
               + r'0 '
               + r'] ')

    init_Ms = """

    if { ($x * $x + $y * $y) < 5e-9 * 5e-9 } {
        return 2e4
    } else {
        return 0
    }

    """

    mesh = CuboidMesh(nx=12, ny=10, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = spatial_Ms

    def init_m(pos):
        x, y, z = pos
        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

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

    demag = Demag()
    sim.add(demag)

    field = exch.compute_field()
    field_oommf = compute_exch_field(
        mesh, init_m0=init_m0, A=A, spatial_Ms=init_Ms)
    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12

    field = demag.compute_field()
    field_oommf = compute_demag_field(
        mesh, spatial_Ms=init_Ms, init_m0=init_m0)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-11
Пример #40
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
Пример #41
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
Пример #42
0
def test_sim_init_m_fun():
    mesh = CuboidMesh(nx=3, ny=4, nz=5)
    sim = Sim(mesh)
    sim.set_m(init_m, normalise=False)

    print sim.spin.reshape(-1, 3).shape
    print sim.mesh.index(1, 2, 3)

    assert(sim.spin_at(1, 2, 3)[0] == 1)
    assert(sim.spin_at(1, 2, 3)[1] == 2)
    assert(sim.spin_at(1, 2, 3)[2] == 3)
Пример #43
0
def test_sim_init_m_fun():
    mesh = CuboidMesh(nx=3, ny=4, nz=5)
    sim = Sim(mesh)
    sim.set_m(init_m, normalise=False)

    print(sim.spin.reshape(-1, 3).shape)
    print(sim.mesh.index(1, 2, 3))

    assert (sim.spin_at(1, 2, 3)[0] == 1)
    assert (sim.spin_at(1, 2, 3)[1] == 2)
    assert (sim.spin_at(1, 2, 3)[2] == 3)
Пример #44
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
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
Пример #46
0
def test_init():
    """
    This tests (mx, my, mx) for the first 2 spins
    """
    mesh = CuboidMesh(nx=100, ny=1, nz=1)
    sim = Sim(mesh)
    sim.set_m(init_m)

    expected = np.array([0, 0, 1,
                         0, np.sin(0.1), np.cos(0.1)])

    assert max(abs(sim.spin[:6] - expected)) < 1e-15
def setup_simulation(mesh,
                     m0,
                     simulation_name,
                     integrator="sundials",
                     use_jac=False):
    sim = Sim(mesh, name=simulation_name, integrator=integrator, use_jac)
    sim.set_m(m0)
    sim.Ms = Ms
    sim.alpha = alpha
    sim.gamma = gamma
    sim.add(UniformExchange(A))
    sim.add(Demag())
    return sim
Пример #48
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
Пример #49
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
Пример #50
0
def test_zeeman():

    mesh = CuboidMesh(nx=5, ny=2, nz=1)

    sim = Sim(mesh)
    sim.set_m((1, 0, 0))

    zeeman = Zeeman(varying_field)
    sim.add(zeeman)

    field = zeeman.compute_field()

    assert field[6] == 1.2 * (2 + 0.5)
    assert field[7] == 2.3 * 0.5
Пример #51
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)
Пример #52
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.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)
Пример #53
0
def run_sim():
    mesh = CuboidMesh()
    sim = Sim(mesh, name='spin')
    alpha = 0.1
    gamma = 2.21e5
    sim.alpha = alpha
    sim.driver.gamma = gamma
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))
    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))
    sim.driver.run_until(1e-10)
    sim.driver.run_until(0.5e-10)
Пример #54
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)
def run_sim():
	mesh = CuboidMesh()
	sim = Sim(mesh, name='spin')
	alpha = 0.1
	gamma = 2.21e5
	sim.alpha = alpha
	sim.driver.gamma = gamma
	sim.mu_s = 1.0

	sim.set_m((1, 0, 0))
	H0 = 1e5
	sim.add(Zeeman((0, 0, H0)))
	sim.driver.run_until(1e-10)
	sim.driver.run_until(0.5e-10)
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
Пример #57
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
Пример #58
0
def test_exch_1d(do_plot=False):
    # Initiate the 1D mesh and magnetisation as before
    mesh = CuboidMesh(nx=100, ny=1, nz=1)
    sim = Sim(mesh)
    sim.set_m(init_m)

    # Simplify the magnetic parameters
    mu0 = 4 * np.pi * 1e-7
    sim.Ms = 1.0 / mu0

    exch = UniformExchange(1)
    sim.add(exch)

    # Compute the exchange field and reshape it in order
    # to leave every row as the [f_x, f_y, f_z] array
    # for every spin
    field = exch.compute_field()
    field.shape = (-1, 3)

    # We know that the field in x is always zero ( see the
    # analytical calculation at the beginning)
    assert max(abs(field[:, 0])) == 0

    # These are the analytical values for the exchange field in y,z
    # In this case, k=0.1 , then 2 * k^2 evaluates as 0.02
    xs = np.linspace(0, 99, 100)
    epy = -0.02 * np.sin(0.1 * xs)
    epz = -0.02 * np.cos(0.1 * xs)

    # Compare the analytical value
    # of the y component of the exchange field, with Fidimag's
    # result (second column of the reshaped field array)

    # WARNING: NOTICE that we are not considering the extremes since
    # there is a wrong expression in the border of the exchange field
    # with NO PBCs. We must FIX this test!
    assert max(abs(epy[1:-1] - field[1:-1, 1])) < 3e-5

    if do_plot:
        plt.plot(xs, field[:, 1], "-.", label="my", color='DarkGreen')
        plt.plot(xs, field[:, 2], "-.", label="mz", color='DarkGreen')
        plt.plot(xs, epy, "--", label="analytical", color='b')
        plt.plot(xs, epz, "--", color='r')
        plt.xlabel("xs")
        plt.ylabel("field")
        plt.legend()
        plt.savefig("exchange_field.pdf")
Пример #59
0
def test_demag_field_oommf_large(Ms=8e5, A=1.3e-11):
    mesh = CuboidMesh(nx=150, ny=50, nz=1, dx=2.5, dy=2.5, dz=3, unit_length=1e-9)
    sim = Sim(mesh)

    sim.Ms = Ms

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

    demag = Demag()
    sim.add(demag)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)
    demag_field = demag.compute_field()
    exch_field = exch.compute_field()

    #exact = demag.compute_exact()

    init_m0 = """
    return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
    """

    #demag_oommf = compute_demag_field(mesh, Ms=Ms, init_m0=init_m0)
    #exch_oommf = compute_exch_field(mesh, Ms=Ms, init_m0=init_m0, A=A)

    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_demag_field_oommf_large_Demag.ohf')
    ovf = OMF2(omf_file)
    demag_oommf = ovf.get_all_mags()

    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_demag_field_oommf_large_Exchange.ohf')
    ovf = OMF2(omf_file)
    exch_oommf = ovf.get_all_mags()

    mx0, mx1, mx2 = compare_fields(demag_oommf, demag_field)
    #print mx0, mx1, mx2
    assert max([mx0,mx1,mx2])< 5e-10

    mx0, mx1, mx2 = compare_fields(exch_oommf, exch_field)
    #print mx0, mx1, mx2
    assert max([mx0, mx1, mx2]) < 1e-11