Exemplo n.º 1
0
def test_cubic_against_nmag(finmag=conftest.setup_cubic()):

    REL_TOLERANCE = 1e-6

    m_ref = np.genfromtxt(os.path.join(conftest.MODULE_DIR, "m0_nmag.txt"))
    m_computed = vectors(finmag["m"].get_numpy_array_debug())
    assert m_ref.shape == m_computed.shape

    H_ref = np.genfromtxt(
        os.path.join(conftest.MODULE_DIR, "H_cubic_anis_nmag.txt"))
    H_computed = vectors(finmag["H"].vector().array())
    assert H_ref.shape == H_computed.shape

    assert m_ref.shape == H_ref.shape
    mxH_ref = np.cross(m_ref, H_ref)
    mxH_computed = np.cross(m_computed, H_computed)
    print mxH_ref
    print mxH_computed

    diff = np.abs(mxH_computed - mxH_ref)
    rel_diff = diff / \
        np.sqrt(np.max(mxH_ref[0] ** 2 + mxH_ref[1] ** 2 + mxH_ref[2] ** 2))

    print "comparison with nmag, m x H, difference:"
    print stats(diff)
    print "comparison with nmag, m x H, relative difference:"
    print stats(rel_diff)

    finmag["table"] += conftest.table_entry("nmag", REL_TOLERANCE, rel_diff)
    assert np.max(rel_diff) < REL_TOLERANCE
Exemplo n.º 2
0
def test_m_cross_H():
    """
    compares m x H_exc at the beginning of the simulation.

    """
    REL_TOLERANCE = 8e-8

    m_ref = np.genfromtxt(os.path.join(MODULE_DIR, "m_t0_ref.txt"))
    m_computed = h.vectors(m_t0)
    assert m_ref.shape == m_computed.shape

    H_ref = np.genfromtxt(os.path.join(MODULE_DIR, "exc_t0_ref.txt"))
    H_computed = h.vectors(H_exc_t0)
    assert H_ref.shape == H_computed.shape

    assert m_ref.shape == H_ref.shape
    m_cross_H_ref = np.cross(m_ref, H_ref)
    m_cross_H_computed = np.cross(m_computed, H_computed)

    diff = np.abs(m_cross_H_ref - m_cross_H_computed)
    max_norm = max([h.norm(v) for v in m_cross_H_ref])
    rel_diff = diff / max_norm

    print "test_m_cross_H, max. relative difference per axis:"
    print np.nanmax(rel_diff, axis=0)
    assert np.max(rel_diff) < REL_TOLERANCE
Exemplo n.º 3
0
def test_m_cross_H():
    """
    compares m x H_anis at the beginning of the simulation.
    motivation: Hans on IRC, 13.04.2012 10:45

    """
    REL_TOLERANCE = 7e-5

    m_ref = np.genfromtxt(os.path.join(MODULE_DIR, "m_t0_ref.txt"))
    m_computed = h.vectors(m_t0)
    assert m_ref.shape == m_computed.shape

    H_ref = np.genfromtxt(os.path.join(MODULE_DIR, "anis_t0_ref.txt"))
    H_computed = h.vectors(H_anis_t0)
    assert H_ref.shape == H_computed.shape

    assert m_ref.shape == H_ref.shape
    m_cross_H_ref = np.cross(m_ref, H_ref)
    m_cross_H_computed = np.cross(m_computed, H_computed)

    diff = np.abs(m_cross_H_ref - m_cross_H_computed)
    max_norm = max([h.norm(v) for v in m_cross_H_ref])
    rel_diff = diff / max_norm

    print "test_m_cross_H: max rel diff=", np.max(rel_diff)
    assert np.max(rel_diff) < REL_TOLERANCE
Exemplo n.º 4
0
def test_against_nmag(finmag):
    REL_TOLERANCE = 2e-14

    m_ref = np.genfromtxt(os.path.join(MODULE_DIR, "m0_nmag.txt"))
    m_computed = vectors(finmag["m"].get_numpy_array_debug())
    assert m_ref.shape == m_computed.shape

    H_ref = np.genfromtxt(os.path.join(MODULE_DIR, "H_exc_nmag.txt"))
    H_computed = vectors(finmag["H"].vector().array())
    assert H_ref.shape == H_computed.shape

    assert m_ref.shape == H_ref.shape
    m_cross_H_ref = np.cross(m_ref, H_ref)
    m_cross_H_computed = np.cross(m_computed, H_computed)

    diff = np.abs(m_cross_H_ref - m_cross_H_computed)
    rel_diff = diff / max([norm(v) for v in m_cross_H_ref])

    finmag["table"] += table_entries.format("nmag", s(REL_TOLERANCE, 0),
                                            s(np.max(rel_diff)),
                                            s(np.mean(rel_diff)),
                                            s(np.std(rel_diff)))

    print "comparison with nmag, m x H, relative difference:"
    print stats(rel_diff)
    assert np.max(rel_diff) < REL_TOLERANCE
Exemplo n.º 5
0
def angles_after_a_nanosecond(initial_M, pins=[]):
    sim = Sim(mesh, Ms)
    sim.set_m(initial_M, L=length)
    sim.add(Exchange(A))
    sim.pins = pins
    sim.run_until(1e-9)

    m = vectors(sim.m)
    angles = np.array([angle(m[i], m[i + 1]) for i in xrange(len(m) - 1)])
    return angles
Exemplo n.º 6
0
def test_angles():
    TOLERANCE = 5e-8

    m = h.vectors(sim.m)
    angles = np.array([h.angle(m[i], m[i + 1]) for i in xrange(len(m) - 1)])

    max_diff = abs(angles.max() - angles.min())
    mean_angle = np.mean(angles)
    print "test_angles: max_difference= {}.".format(max_diff)
    print "test_angles: mean= {}.".format(mean_angle)
    assert max_diff < TOLERANCE
    assert np.abs(mean_angle - np.pi / 10) < TOLERANCE
Exemplo n.º 7
0
import numpy
import pylab
from finmag.util.helpers import vectors, norm, angle

# Load the data which dolfin has created and odeint has integrated.
Ms = numpy.genfromtxt("1d_M.txt")
# Each entry in ys is M for a particular moment in time.
# Each M is all the x-values of M on the mesh, followed by the y and z-values.
"""
Norm of M at each node, and the angles between M at
the nodes for the first and last moment of the simulation.

"""

M0 = vectors(Ms[0])
M1 = vectors(Ms[-1])

norms0 = [norm(M) for M in M0]
norms1 = [norm(M) for M in M1]

angles0 = [angle(M0[i], M0[i + 1]) for i in xrange(len(M0) - 1)]
angles1 = [angle(M1[i], M1[i + 1]) for i in xrange(len(M1) - 1)]

print "Initial configuration."
print M0, "\n", norms0
print "Final configuration."
print M1, "\n", norms1
print "Angles in the initial configuration."
print angles0
print "Angles at the end of the simulation."
print angles1