Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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")
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 8
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
Esempio n. 9
0
def test_demag_field_oommf(Ms=6e5):
    mesh = CuboidMesh(nx=5, ny=2, nz=3, unit_length=1e-9)
    sim = Sim(mesh)

    sim.Ms = Ms

    demag = Demag()
    sim.add(demag)

    def init_m(pos):

        x = pos[0]

        if x <= 2:
            return (1, 0, 0)
        elif x >= 4:
            return (0, 0, 1)
        else:
            return (0, 1, 0)

    sim.set_m(init_m)
    field = demag.compute_field()
    exact = demag.compute_exact()

    init_m0 = """

    if { $x <=2e-9 } {
        return "1 0 0"
    } elseif { $x >= 4e-9 } {
        return "0 0 1"
    } else {
        return "0 1 0"
    }
    """

    field_oommf = compute_demag_field(mesh, Ms=Ms, init_m0=init_m0)

    mx0, mx1, mx2 = compare_fields(field_oommf, exact)
    print mx0, mx1, mx2
    assert max([mx0, mx1, mx2]) < 2e-14

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

    assert np.max(abs(field - field_oommf)) < 2e-9
Esempio n. 10
0
def test_demag_field_oommf(Ms=6e5):
    mesh = CuboidMesh(nx=5, ny=2, nz=3, unit_length=1e-9)
    sim = Sim(mesh)

    sim.Ms = Ms

    demag = Demag()
    sim.add(demag)

    def init_m(pos):

        x = pos[0]

        if x <= 2:
            return (1, 0, 0)
        elif x >= 4:
            return (0, 0, 1)
        else:
            return (0, 1, 0)

    sim.set_m(init_m)
    field = demag.compute_field()
    exact = demag.compute_exact()

    init_m0 = """

    if { $x <=2e-9 } {
        return "1 0 0"
    } elseif { $x >= 4e-9 } {
        return "0 0 1"
    } else {
        return "0 1 0"
    }
    """

    field_oommf = compute_demag_field(mesh, Ms=Ms, init_m0=init_m0)

    mx0, mx1, mx2 = compare_fields(field_oommf, exact)
    print(mx0, mx1, mx2)
    assert max([mx0, mx1, mx2]) < 2e-14

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

    assert np.max(abs(field - field_oommf)) < 2e-9
Esempio n. 11
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 = (
        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'] ')

    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)

    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
Esempio n. 12
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 = (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'] ')

    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)

    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
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.driver.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
Esempio n. 14
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 = """
    return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
    """

    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

    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)

    field = exch.compute_field()
    #field_oommf = compute_exch_field(mesh, init_m0=init_m0, A=A, spatial_Ms=init_Ms)

    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_with_oommf_spatial_Ms_Exchange.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

    field = demag.compute_field()
    #field_oommf = compute_demag_field(mesh, spatial_Ms=init_Ms, init_m0=init_m0)
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_with_oommf_spatial_Ms_Demag.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-11
Esempio n. 15
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 = """
    return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
    """

    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

    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)

    field = exch.compute_field()
    #field_oommf = compute_exch_field(mesh, init_m0=init_m0, A=A, spatial_Ms=init_Ms)

    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_with_oommf_spatial_Ms_Exchange.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

    field = demag.compute_field()
    #field_oommf = compute_demag_field(mesh, spatial_Ms=init_Ms, init_m0=init_m0)
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_with_oommf_spatial_Ms_Demag.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-11