def run_finmag(demagsolver):
    """Run the finmag simulation and store data in (demagsolvertype)averages.txt."""

    sim = Sim(mesh, Ms, unit_length=unit_length)
    sim.alpha = 0.5
    sim.set_m((1, 0, 1))

    exchange = Exchange(13.0e-12)
    sim.add(exchange)
    demag = Demag(solver=demagsolver)
    sim.add(demag)

    fh = open(os.path.join(MODULE_DIR, demagsolver + "averages.txt"), "w")
    fe = open(os.path.join(MODULE_DIR, demagsolver + "energies.txt"), "w")

    # Progressbar
    bar = pb.ProgressBar(maxval=60, \
                    widgets=[pb.ETA(), pb.Bar('=', '[', ']'), ' ', pb.Percentage()])

    logger.info("Time integration")
    times = np.linspace(0, 3.0e-10, 61)
    #times = np.linspace(0, 3.0e-10, 100000)
    for counter, t in enumerate(times):
        bar.update(counter)

        # Integrate
        sim.run_until(t)
        print counter
        print("press return to continue")
        _ = raw_input()

        # Save averages to file
        mx, my, mz = sim.m_average
        fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n")

        # Energies
        E_e = exchange.compute_energy()
        E_d = demag.compute_energy()
        fe.write(str(E_e) + " " + str(E_d) + "\n")

        # Energy densities
        if counter == 10:
            exch_energy = exchange.energy_density_function()
            demag_energy = demag.demag.energy_density_function()
            finmag_exch, finmag_demag = [], []
            R = range(100)
            for i in R:
                finmag_exch.append(exch_energy([15, 15, i]))
                finmag_demag.append(demag_energy([15, 15, i]))
            # Store data
            np.save(
                os.path.join(MODULE_DIR,
                             "finmag%s_exch_density.npy" % demagsolver),
                np.array(finmag_exch))
            np.save(
                os.path.join(MODULE_DIR,
                             "finmag%s_demag_density.npy" % demagsolver),
                np.array(finmag_demag))
    fh.close()
    fe.close()
示例#2
0
def demag_energy():
    mesh = from_geofile(os.path.join(MODULE_DIR, "sphere_fine.geo"))
    S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1)
    m_function = df.interpolate(df.Constant((1, 0, 0)), S3)
    m = Field(S3, m_function)

    demag = Demag('FK')
    demag.setup(m, Field(df.FunctionSpace(mesh, 'DG', 0), Ms), unit_length=1)

    E = demag.compute_energy()
    rel_error = abs(E - E_analytical) / abs(E_analytical)
    print "Energy with FK method: {}.".format(E)
    return E, rel_error
示例#3
0
def run_finmag():
    """Run the finmag simulation and store data in averages.txt."""

    sim = Sim(mesh, Ms, unit_length=unit_length)
    sim.alpha = 0.5
    sim.set_m((1, 0, 1))

    exchange = Exchange(13.0e-12)
    sim.add(exchange)
    demag = Demag(solver="FK")
    sim.add(demag)

    fh = open(os.path.join(MODULE_DIR, "averages.txt"), "w")
    fe = open(os.path.join(MODULE_DIR, "energies.txt"), "w")

    logger.info("Time integration")
    times = np.linspace(0, 3.0e-10, 61)
    for counter, t in enumerate(times):

        # Integrate
        sim.run_until(t)

        # Save averages to file
        mx, my, mz = sim.m_average
        fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n")

        # Energies
        E_e = exchange.compute_energy()
        E_d = demag.compute_energy()
        fe.write(str(E_e) + " " + str(E_d) + "\n")

        # Energy densities
        if counter == 10:
            exch_energy = exchange.energy_density_function()
            demag_energy = demag.energy_density_function()
            finmag_exch, finmag_demag = [], []
            R = range(100)
            for i in R:
                finmag_exch.append(exch_energy([15, 15, i]))
                finmag_demag.append(demag_energy([15, 15, i]))
            # Store data
            np.save(os.path.join(MODULE_DIR, "finmag_exch_density.npy"),
                    np.array(finmag_exch))
            np.save(os.path.join(MODULE_DIR, "finmag_demag_density.npy"),
                    np.array(finmag_demag))

    fh.close()
    fe.close()
示例#4
0
文件: run.py 项目: whshangl/finmag
def run_simulation(lfactor, m_init, m_init_name=""):
    L = lfactor * lexch
    divisions = int(round(lfactor * 2))  # that magic number influences L
    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(L, L, L), divisions,
                      divisions, divisions)

    exchange = Exchange(A)
    anisotropy = UniaxialAnisotropy(K1, [0, 0, 1])
    demag = Demag()

    sim = Simulation(mesh, Ms)
    sim.set_m(m_init)
    sim.add(exchange)
    sim.add(anisotropy)
    sim.add(demag)
    sim.relax()

    # Save average magnetisation.
    mx, my, mz = sim.m_average
    with open(os.path.join(MODULE_DIR, "data_m.txt"), "a") as f:
        t = time.asctime()
        f.write("{} {} {} {} {} {}\n".format(m_init_name, lfactor, mx, my, mz,
                                             t))

    # Save energies.
    # We could call sim.total_energy, but we want the individual contributions.
    e_exc = exchange.compute_energy() / (sim.Volume * Km)
    e_anis = anisotropy.compute_energy() / (sim.Volume * Km)
    e_demag = demag.compute_energy() / (sim.Volume * Km)
    e_total = e_exc + e_anis + e_demag  # relative total energy density

    with open(os.path.join(MODULE_DIR, "data_energies.txt"), "a") as f:
        t = time.asctime()
        f.write("{} {} {} {} {} {} {}\n".format(m_init_name, lfactor, e_total,
                                                e_exc, e_anis, e_demag, t))

    return e_total