예제 #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")
예제 #2
0
def test_energy(Ms=8e5, A=1.3e-11, 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

    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_energy = demag.compute_energy()
    exch_energy = exch.compute_energy()

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

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

    exch_energy_oommf = 1.9885853028738599e-19
    demag_energy_oommf = 5.5389695779175673e-19
    dmi_energy_oommf = 2.6657360769014251e-20

    print(demag_energy, exch_energy)

    assert abs(exch_energy - exch_energy_oommf) / exch_energy_oommf < 3e-15
    assert abs(demag_energy - demag_energy_oommf) / demag_energy_oommf < 1e-10
예제 #3
0
def test_energy(Ms=8e5, A=1.3e-11, 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

    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_energy = demag.compute_energy()
    exch_energy = exch.compute_energy()

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

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

    exch_energy_oommf = 1.9885853028738599e-19
    demag_energy_oommf = 5.5389695779175673e-19
    dmi_energy_oommf = 2.6657360769014251e-20

    print demag_energy, exch_energy

    assert abs(exch_energy - exch_energy_oommf) / exch_energy_oommf < 3e-15
    assert abs(demag_energy - demag_energy_oommf) / demag_energy_oommf < 1e-10