Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
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