def test_against_oommf(finmag=conftest.setup_cubic()): REL_TOLERANCE = 7e-2 oommf_mesh = mesh.Mesh((20, 20, 20), size=(conftest.x1, conftest.y1, conftest.z1)) # FIXME: why our result is three times of oommf's?? oommf_anis = oommf_cubic_anisotropy(m0=oommf_m0(conftest.m_gen, oommf_mesh), Ms=conftest.Ms, K1=conftest.K1, K2=conftest.K2, u1=conftest.u1, u2=conftest.u2).flat finmag_anis = finmag_to_oommf(finmag["H"], oommf_mesh, dims=3) assert oommf_anis.shape == finmag_anis.shape diff = np.abs(oommf_anis - finmag_anis) print 'diff', diff rel_diff = diff / \ np.sqrt( (np.max(oommf_anis[0] ** 2 + oommf_anis[1] ** 2 + oommf_anis[2] ** 2))) print "comparison with oommf, H, relative_difference:" print stats(rel_diff) finmag["table"] += conftest.table_entry("oommf", REL_TOLERANCE, rel_diff) assert np.max(rel_diff) < REL_TOLERANCE
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
def test_against_magpar(): finmag = conftest.setup(K2=0) REL_TOLERANCE = 5e-7 magpar_result = os.path.join(MODULE_DIR, 'magpar_result', 'test_anis') magpar_nodes, magpar_anis = magpar.get_field(magpar_result, 'anis') ## Uncomment the lines below to invoke magpar to compute the results, ## rather than using our previously saved results. # magpar_nodes, magpar_anis = magpar.compute_anis_magpar(finmag["m"], # K1=conftest.K1, a=conftest.u1, Ms=conftest.Ms) _, _, diff, rel_diff = magpar.compare_field( finmag["S3"].mesh().coordinates(), finmag["H"].vector().array(), magpar_nodes, magpar_anis) print "comparison with magpar, H, relative_difference:" print stats(rel_diff) finmag["table"] += conftest.table_entry("magpar", REL_TOLERANCE, rel_diff) assert np.max(rel_diff) < REL_TOLERANCE
def test_against_oommf(): finmag = conftest.setup(K2=0) REL_TOLERANCE = 9e-2 oommf_mesh = mesh.Mesh((20, 20, 20), size=(conftest.x1, conftest.y1, conftest.z1)) oommf_anis = oommf_uniaxial_anisotropy( oommf_m0(conftest.m_gen, oommf_mesh), conftest.Ms, conftest.K1, conftest.u1).flat finmag_anis = finmag_to_oommf(finmag["H"], oommf_mesh, dims=3) assert oommf_anis.shape == finmag_anis.shape diff = np.abs(oommf_anis - finmag_anis) rel_diff = diff / \ np.sqrt( (np.max(oommf_anis[0] ** 2 + oommf_anis[1] ** 2 + oommf_anis[2] ** 2))) print "comparison with oommf, H, relative_difference:" print stats(rel_diff) finmag["table"] += conftest.table_entry("oommf", REL_TOLERANCE, rel_diff) assert np.max(rel_diff) < REL_TOLERANCE