Ejemplo n.º 1
0
def test_anisotropy_energy_analytical(fixt):
    """
    Compare one UniaxialAnisotropy energy with the corresponding analytical result.

    The magnetisation is m = (0, sqrt(1 - x^2), x) and the easy axis still
    a = (0, 0, 1). The squared dot product in the energy integral thus gives
    dot(a, m)^2 = x^2. Integrating x^2 gives (x^3)/3 and the analytical
    result with the constants we have chosen is 1 - 1/3 = 2/3.

    """
    mesh = df.UnitCubeMesh(1, 1, 1)
    functionspace = df.VectorFunctionSpace(mesh, "Lagrange", 1)
    K1 = 1
    Ms = Field(df.FunctionSpace(mesh, 'DG', 0), 1)
    a = df.Constant((0, 0, 1))
    m = Field(functionspace)
    m.set(df.Expression(("0", "sqrt(1 - pow(x[0], 2))", "x[0]"), degree=1))
    anis = UniaxialAnisotropy(K1, a)
    anis.setup(m, Ms)

    E = anis.compute_energy()
    expected_E = float(2) / 3

    print "With m = (0, sqrt(1-x^2), x), expecting E = {}. Got E = {}.".format(
        expected_E, E)
    #assert abs(E - expected_E) < TOLERANCE
    assert np.allclose(E, expected_E, atol=1e-14, rtol=TOLERANCE)
Ejemplo n.º 2
0
def test_anisotropy_energy_simple_configurations(fixt, m, expected_E):
    """
    Test some parallel and orthogonal configurations of m and a.

    """
    mesh = df.UnitCubeMesh(1, 1, 1)
    functionspace = df.VectorFunctionSpace(mesh, "Lagrange", 1)
    K1 = 1
    Ms = Field(df.FunctionSpace(mesh, 'DG', 0), 1)
    a = df.Constant((0, 0, 1))
    m_field = Field(functionspace)
    m_field.set(df.Constant(m))
    anis = UniaxialAnisotropy(K1, a)
    anis.setup(m_field, Ms)

    E = anis.compute_energy()

    print "With m = {}, expecting E = {}. Got E = {}.".format(m, expected_E, E)
    #assert abs(E - expected_E) < TOLERANCE
    assert np.allclose(E, expected_E, atol=1e-14, rtol=TOLERANCE)
Ejemplo n.º 3
0
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