def test_slow_hysteresis_ellipsoid(): #py.test will pass on any command line arguments to the code it tests. #This will confuse nmag (as it doesn't know how to handle py.test's '-k' #and '--verbose' switches, etc. # #We thus manually delete all other entries that the name of the executable #from sys.argv. import sys proper_sysargv = sys.argv sys.argv = sys.argv[0:1] #work out in which directory the data files are org_dir = os.getcwd() os.chdir(os.path.split(__file__)[0]) #compute new data (this can take a while, will delete old data files automatically) os.system("make run > test_make_run1.out") import nmag #load saved magnetisation before switching before_switching=nmag.get_subfield_from_h5file('ellipsoid_dat.h5','m_Py',id=26) Mx = before_switching[:,0] My = before_switching[:,1] Mz = before_switching[:,2] average_Mx = Mx.sum()/len(Mx) average_My = My.sum()/len(Mx) average_Mz = Mz.sum()/len(Mx) #with svnrev=5886: Average mx, my, mz = (0.995631 -0.093231 0.002322) print "Average mx, my, mz = (%f %f %f)" % (average_Mx,average_My,average_Mz) assert average_Mx > 0.99, "Expect <Mx> at id=26 to be > 0.99 but is %f" % average_Mx assert abs(average_My) < 0.1, "Expect <My> at id=26 to be < 0.1 but is %f" % average_My assert abs(average_Mz) < 0.01, "Expect <Mz> at id=26 to be < 0.1 but is %f" % average_Mz after_switching=nmag.get_subfield_from_h5file('ellipsoid_dat.h5','m_Py',id=27) Mx = after_switching[:,0] My = after_switching[:,1] Mz = after_switching[:,2] average_Mx = Mx.sum()/len(Mx) average_My = My.sum()/len(Mx) average_Mz = Mz.sum()/len(Mx) #with svnrev=5886: Average mx, my, mz = (-0.999987 -0.005147 -0.000053) print "Average mx, my, mz = (%f %f %f)" % (average_Mx,average_My,average_Mz) assert average_Mx < -0.99, "Expect <Mx> at id=26 to be > 0.99 but is %f" % average_Mx assert abs(average_My) < 0.1, "Expect <My> at id=26 to be < 0.1 but is %f" % average_My assert abs(average_Mz) < 0.01, "Expect <Mz> at id=26 to be < 0.1 but is %f" % average_Mz #this avoids getting relative paths in the checking progress output os.chdir(org_dir)
def test_slow_mfm(): #py.test will pass on any command line arguments to the code it tests. #This will confuse nmag (as it doesn't know how to handle py.test's '-k' #and '--verbose' switches, etc. # #We thus manually delete all other entries that the name of the executable #from sys.argv. import sys proper_sysargv = sys.argv sys.argv = sys.argv[0:1] #work out in which directory the data files are org_dir = os.getcwd() os.chdir(os.path.split(__file__)[0]) #remove old data file remove_if_exists('disk_dat.h5') #get the mesh in place (this requires netgen, so we have #included the mesh file in the repository) #os.system("make remesh > test_make_remesh.out") #compute new data (this can take a while) os.system("make run1 > test_make_run1.out") import nmag #load saved magnetisation relaxed_m = nmag.get_subfield_from_h5file('disk_dat.h5', 'm_Py', row=0) Mx = relaxed_m[:, 0] My = relaxed_m[:, 1] Mz = relaxed_m[:, 2] average_Mx = Mx.sum() / len(Mx) average_My = My.sum() / len(Mx) average_Mz = Mz.sum() / len(Mx) print "Average mx, my, mz = (%f %f %f)" % (average_Mx, average_My, average_Mz) #we expect a vortex, so Mx and My should be fairly small, and Mz non-zero #On 23 July 2008 (rev 5640), I get # """Average mx, my, mz = (0.001327 0.006164 0.031480)""" #Let's check for that: assert abs(average_Mx) < 0.01, "Mx=%f is too large" % average_Mx assert abs(average_My) < 0.01, "My=%f is too large" % average_My assert abs(average_Mz) > 0.03, "Mz=%f is too small" % average_Mz #this avoids getting relative paths in the checking progress output os.chdir(org_dir)
def test_slow_mfm(): # py.test will pass on any command line arguments to the code it tests. # This will confuse nmag (as it doesn't know how to handle py.test's '-k' # and '--verbose' switches, etc. # # We thus manually delete all other entries that the name of the executable # from sys.argv. import sys proper_sysargv = sys.argv sys.argv = sys.argv[0:1] # work out in which directory the data files are org_dir = os.getcwd() os.chdir(os.path.split(__file__)[0]) # remove old data file remove_if_exists("disk_dat.h5") # get the mesh in place (this requires netgen, so we have # included the mesh file in the repository) # os.system("make remesh > test_make_remesh.out") # compute new data (this can take a while) os.system("make run1 > test_make_run1.out") import nmag # load saved magnetisation relaxed_m = nmag.get_subfield_from_h5file("disk_dat.h5", "m_Py", row=0) Mx = relaxed_m[:, 0] My = relaxed_m[:, 1] Mz = relaxed_m[:, 2] average_Mx = Mx.sum() / len(Mx) average_My = My.sum() / len(Mx) average_Mz = Mz.sum() / len(Mx) print "Average mx, my, mz = (%f %f %f)" % (average_Mx, average_My, average_Mz) # we expect a vortex, so Mx and My should be fairly small, and Mz non-zero # On 23 July 2008 (rev 5640), I get # """Average mx, my, mz = (0.001327 0.006164 0.031480)""" # Let's check for that: assert abs(average_Mx) < 0.01, "Mx=%f is too large" % average_Mx assert abs(average_My) < 0.01, "My=%f is too large" % average_My assert abs(average_Mz) > 0.03, "Mz=%f is too small" % average_Mz # this avoids getting relative paths in the checking progress output os.chdir(org_dir)
def test_slow_hysteresis_ellipsoid(): #py.test will pass on any command line arguments to the code it tests. #This will confuse nmag (as it doesn't know how to handle py.test's '-k' #and '--verbose' switches, etc. # #We thus manually delete all other entries that the name of the executable #from sys.argv. import sys proper_sysargv = sys.argv sys.argv = sys.argv[0:1] #work out in which directory the data files are org_dir = os.getcwd() os.chdir(os.path.split(__file__)[0]) #compute new data (this can take a while, will delete old data files automatically) os.system("make run > test_make_run1.out") import nmag #load saved magnetisation before switching before_switching = nmag.get_subfield_from_h5file('ellipsoid_dat.h5', 'm_Py', id=26) Mx = before_switching[:, 0] My = before_switching[:, 1] Mz = before_switching[:, 2] average_Mx = Mx.sum() / len(Mx) average_My = My.sum() / len(Mx) average_Mz = Mz.sum() / len(Mx) #with svnrev=5886: Average mx, my, mz = (0.995631 -0.093231 0.002322) print "Average mx, my, mz = (%f %f %f)" % (average_Mx, average_My, average_Mz) assert average_Mx > 0.99, "Expect <Mx> at id=26 to be > 0.99 but is %f" % average_Mx assert abs( average_My ) < 0.1, "Expect <My> at id=26 to be < 0.1 but is %f" % average_My assert abs( average_Mz ) < 0.01, "Expect <Mz> at id=26 to be < 0.1 but is %f" % average_Mz after_switching = nmag.get_subfield_from_h5file('ellipsoid_dat.h5', 'm_Py', id=27) Mx = after_switching[:, 0] My = after_switching[:, 1] Mz = after_switching[:, 2] average_Mx = Mx.sum() / len(Mx) average_My = My.sum() / len(Mx) average_Mz = Mz.sum() / len(Mx) #with svnrev=5886: Average mx, my, mz = (-0.999987 -0.005147 -0.000053) print "Average mx, my, mz = (%f %f %f)" % (average_Mx, average_My, average_Mz) assert average_Mx < -0.99, "Expect <Mx> at id=26 to be > 0.99 but is %f" % average_Mx assert abs( average_My ) < 0.1, "Expect <My> at id=26 to be < 0.1 but is %f" % average_My assert abs( average_Mz ) < 0.01, "Expect <Mz> at id=26 to be < 0.1 but is %f" % average_Mz #this avoids getting relative paths in the checking progress output os.chdir(org_dir)
import nmag m = nmag.get_subfield_from_h5file('bar_dat.h5', 'm_py', row=0) pos = nmag.get_subfield_positions_from_h5file('bar_dat.h5', 'm_Py') site = nmag.get_subfield_sites_from_h5file('bar_dat.h5', 'm_Py') assert m.shape == pos.shape assert len(m) == len(site) for i in range(len(m)): print site[i], pos[i], m[i]
#create simulation object sim = nmag.Simulation() # define magnetic material Py = nmag.MagMaterial( name="Py", Ms=SI(795774,"A/m"), exchange_coupling=SI(13.0e-12, "J/m") ) # load mesh: the mesh dimensions are scaled by 100nm sim.load_mesh( "../example_mfm/disk.nmesh.h5", [("disk", Py)], unit_length=SI(1e-9,"m")) relaxed_m=nmag.get_subfield_from_h5file('disk_dat.h5','m_Py',row=0) sim.set_m(relaxed_m) #seems I need to do that to up-date-H_demag -> bug! sim.advance_time(SI(1e-12,'s')) #probe H_demag import numpy nx,ny=40,40 zlevel=7e-9 Hd=numpy.zeros((nx,ny))
thermal_delta_t=0.001*ps) # define magnetic material (data from Kronmueller) NdFeB = nmag.MagMaterial(name="NdFeB", Ms=1.6*si.Tesla/si.mu0, exchange_coupling=SI(7.3e-12, "J/m"), anisotropy=nmag.uniaxial_anisotropy(axis=[0.01,0.01,1],\ K1=SI(4.3e6, "J/m^3"),\ K2=SI(0*0.65e6, "J/m^3"))) # load mesh sim.load_mesh("cube.nmesh.h5", [("cube", NdFeB)], unit_length=SI(1.0e-9,"m") ) # set initial magnetisation from the equilibrium configuration # with the field = 4.92e6 A/m which has id=19 (check with 'ncol thermal-0K id H_ext_2') magn_from_file = nmag.get_subfield_from_h5file('thermal-0K_dat.h5','m_NdFeB',id=10) sim.set_m(magn_from_file) # apply external field in -z direction sim.set_H_ext([0,0,-4.92],unit=SI(1e6,'A/m')) num_steps = 100 for n in range(0, num_steps): print "Step %i/%i" % (n,num_steps) sim.advance_time(n*ps) if (n % 5) == 0: sim.save_data(fields='all') else: sim.save_data()
import nmag #read data, positions, and sites from h5 file m=nmag.get_subfield_from_h5file('bar_dat.h5','m_Py',id=0) pos=nmag.get_subfield_positions_from_h5file('bar_dat.h5','m_Py') site=nmag.get_subfield_sites_from_h5file('bar_dat.h5','m_Py') #can carry out some sanity checks (but is not necessary) assert m.shape == pos.shape assert len(m) == len(site) #print the data for i in range(len(m)): print site[i], pos[i], m[i]
import nmag m = nmag.get_subfield_from_h5file("bar_dat.h5", "m_py", row=0) pos = nmag.get_subfield_positions_from_h5file("bar_dat.h5", "m_Py") site = nmag.get_subfield_sites_from_h5file("bar_dat.h5", "m_Py") assert m.shape == pos.shape assert len(m) == len(site) for i in range(len(m)): print site[i], pos[i], m[i]
import nmag #read data, positions, and sites from h5 file m = nmag.get_subfield_from_h5file('bar_dat.h5', 'm_Py', id=0) pos = nmag.get_subfield_positions_from_h5file('bar_dat.h5', 'm_Py') site = nmag.get_subfield_sites_from_h5file('bar_dat.h5', 'm_Py') #can carry out some sanity checks (but is not necessary) assert m.shape == pos.shape assert len(m) == len(site) #print the data for i in range(len(m)): print site[i], pos[i], m[i]
import nmag from nmag import SI, at #create simulation object sim = nmag.Simulation() # define magnetic material Py = nmag.MagMaterial(name="Py", Ms=SI(795774, "A/m"), exchange_coupling=SI(13.0e-12, "J/m")) # load mesh: the mesh dimensions are scaled by 100nm sim.load_mesh("../example_mfm/disk.nmesh.h5", [("disk", Py)], unit_length=SI(1e-9, "m")) relaxed_m = nmag.get_subfield_from_h5file('disk_dat.h5', 'm_Py', row=0) sim.set_m(relaxed_m) #seems I need to do that to up-date-H_demag -> bug! sim.advance_time(SI(1e-12, 's')) #probe H_demag import numpy nx, ny = 40, 40 zlevel = 7e-9 Hd = numpy.zeros((nx, ny)) xpos = numpy.linspace(-100e-9, 100e-9, nx) ypos = numpy.linspace(-100e-9, 100e-9, ny) for i in range(nx):