def main(): MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) L = 10 mesh_unit = SI(1e-9, "m") # mesh unit (1 nm) layers = [(0.0, L)] # the mesh discretization = 0.1 # discretization # Initial magnetization xfactor = float(SI("m") / (L * mesh_unit)) def m0(r): return [ np.cos(r[0] * np.pi * xfactor), np.sin(r[0] * np.pi * xfactor), 0 ] mat_Py = nmag.MagMaterial(name="Py", Ms=SI(1, "A/m")) sim = nmag.Simulation("Hans' configuration", do_demag=False) mesh_file_name = '1d.nmesh' mesh_lists = unidmesher.mesh_1d(layers, discretization) unidmesher.write_mesh(mesh_lists, out=mesh_file_name) sim.load_mesh(mesh_file_name, [("Py", mat_Py)], unit_length=mesh_unit) sim.set_m(m0) np.save(os.path.join(MODULE_DIR, "nmag_hansconf.npy"), sim.get_subfield("E_exch_Py"))
def run_simulation(simname, meshfile, hmatrix=None, tol=0.000001): T_start = time.time() sim = nmag.Simulation(name=simname, phi_BEM=hmatrix) Ni = nmag.MagMaterial(name="Ni", Ms=SI(493380, "A/m"), exchange_coupling=SI(7.2e-12, "J/m"), llg_damping=1.0) ps = SI(1e-12, "s") sim.load_mesh(meshfile, [("thinfilm", Ni)], unit_length=SI(1e-9, "m")) sim.set_m([0.05, 0.02, 1.00]) sim.set_params(ts_abs_tol=tol, ts_rel_tol=tol) sim.set_H_ext([0, 0, 0], SI('A/m')) dt = SI(5e-12, "s") T_end = time.time() T_setup = T_end - T_start T_start = time.time() sim.relax(save=[('averages', every('time', 10 * ps))]) T_end = time.time() T_sim = T_end - T_start sim.save_data(['m']) number_nodes = len(sim.mesh.points) mem_rss = get_memory_of_process() / 1024.0 return [number_nodes, mem_rss, T_setup, T_sim]
def test_hlib(): with DirectoryOf(__file__): #delete old data files to avoid failure due to this def remove_if_exists(filename): if os.path.exists(filename): os.remove(filename) remove_if_exists("plain_dat.ndt") remove_if_exists("plain_dat.h5") remove_if_exists("hlib_dat.ndt") remove_if_exists("hlib_dat.h5") sim_plain = nmag.Simulation(name='plain') sim_hlib = nmag.Simulation(name='hlib', phi_BEM=nmag.default_hmatrix_setup) res_plain = run_sim(sim_plain) res_hlib = run_sim(sim_hlib) # extract x-components of results hdx1 = [h[0] for h in res_plain] hdx2 = [h[0] for h in res_hlib] # Output as of 13 December 2009, svn 6453, HF # #for r1,r2 in zip(hdx1,hdx2): # print r1-r2,(r1-r2)/r1,r1,r2 # # produces: # -1.10303013207 3.31174926024e-06 -333065.714037 -333064.611006 # -1.18373466324 3.55403967073e-06 -333067.374849 -333066.191114 # -1.26686538779 3.80361435718e-06 -333068.831071 -333067.564206 # -1.32740328263 3.98536687005e-06 -333069.28218 -333067.954776 # -1.34173143021 4.02840496219e-06 -333067.663951 -333066.32222 # -1.35605957796 4.07144347306e-06 -333066.045723 -333064.689663 # -1.37001170352 4.11335588419e-06 -333064.228355 -333062.858343 # -1.34486746625 4.03791095727e-06 -333060.208727 -333058.863859 # -1.30307299155 3.91246719093e-06 -333056.592671 -333055.289598 # -1.26131784206 3.78713877786e-06 -333052.976414 -333051.715096 # -1.19995578279 3.60291609527e-06 -333051.270434 -333050.070478 # the actual test for r1, r2 in zip(hdx1, hdx2): assert (r1 - r2) / float(r1) < 1e-5
def generate_anisotropy_data(anis, name='anis'): # Create the material mat_Py = nmag.MagMaterial(name="Py", Ms=SI(Ms, "A/m"), anisotropy=anis) # Create the simulation object sim = nmag.Simulation(name, do_demag=False) # Load the mesh sim.load_mesh("bar.nmesh.h5", [("Py", mat_Py)], unit_length=SI(1e-9, "m")) # Set the initial magnetisation sim.set_m(lambda r: m_gen(np.array(r) * 1e9)) #sim.advance_time(SI(1e-12, 's') ) # Save the exchange field and the magnetisation once at the beginning # of the simulation for comparison with finmag np.savetxt("H_%s_nmag.txt" % name, sim.get_subfield("H_anis_Py")) np.savetxt("m0_nmag.txt", sim.get_subfield("m_Py"))
def run_simulation(sim_name, initial_m, damping, stopping_dm_dt, j, P=0.0, save=[], do=[], do_demag=True): # Define the material mat = nmag.MagMaterial( name="mat", Ms=SI(0.8e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_damping=damping, llg_xi=SI(0.01), llg_polarisation=P) # Create the simulation object and load the mesh sim = nmag.Simulation(sim_name, do_demag=do_demag) sim.load_mesh(mesh_name, [("np", mat)], unit_length=mesh_unit) # Set the pinning at the top and at the bottom of the nanopillar def pinning(p): x, y, z = p tmp = float(SI(x, "m")/(mesh_unit*hl)) if abs(tmp) >= 0.999: return 0.0 else: return 1.0 sim.set_pinning(pinning) if type(initial_m) == str: # Set the initial magnetisation sim.load_m_from_h5file(initial_m) # a) from file if a string is provided else: sim.set_m(initial_m) # b) from function/vector, otherwise if j != 0.0: # Set the current, if needed sim.set_current_density([j, 0.0, 0.0], unit=SI("A/m^2")) # Set additional parameters for the time-integration and run the simulation sim.set_params(stopping_dm_dt=stopping_dm_dt, ts_rel_tol=1e-7, ts_abs_tol=1e-7) sim.relax(save=save, do=do) return sim
def run_sim(tol): """Function that is called repeatedly with different tolerance values. Each function call is carrying out one simulation. """ mat_Py = nmag.MagMaterial(name="Py", Ms=SI(0.86e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_damping=0.5) #compose name of simulation to inlude value of tolerance sim = nmag.Simulation("bar_%.6f" % tol) sim.load_mesh("bar30_30_100.nmesh.h5", [("Py", mat_Py)], unit_length=SI(1e-9, "m")) sim.set_m([1, 0, 1]) #set tolerance (has to be called after set_m()) sim.set_params(ts_abs_tol=tol, ts_rel_tol=tol) dt = SI(2.5e-12, "s") timing = 0 #initialise variable to measure execution time for i in range(0, 121): timing -= time.time() #start measuring time sim.advance_time(dt * i) #compute time development for 300ps timing += time.time() #stop measuring time #we exclude time required to save data sim.save_data() #save averages every 2.5 ps #at end of simulation, write performance data into summary file f = open('resultsummary.txt', 'a') #open file to append f.write('%g %d %g\n' % (tol, sim.clock['step'], timing)) f.close()
import nmag from nmag import SI, every, at mat_Py = nmag.MagMaterial(name="Py", Ms=SI(0.86e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_damping=0.5, do_precession=False) sim = nmag.Simulation("bar_relax2") sim.load_mesh("bar30_30_100.nmesh.h5", [("Py", mat_Py)], unit_length=SI(1e-9, "m")) sim.set_m([1, 0, 1]) ps = SI(1e-12, "s") sim.relax(save=[('averages', every('time', 5 * ps)), ('fields', at('convergence'))])
import nmag from nmag import SI, mesh import os mat_Py = nmag.MagMaterial(name="Py", Ms=SI(1e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m")) #sim = nmag.Simulation() sim = nmag.Simulation(ddd_use_linalg_machine=True) sim.set_H_ext([0, 0, 0], SI(1, "A/m")) meshfile = os.path.join("barmini.nmesh.h5") if os.path.exists(meshfile): sim.load_mesh(meshfile, [("PyX", mat_Py)], unit_length=SI(1e-9, "m")) else: sim.defregion("Py", mesh.box([0.0, 0.0, 0.0], [20, 20, 80]), mat_Py) mesh = sim.generate_mesh( ([0.0, 0.0, 0.0], [20.0, 20.0, 80.0]), # bounding box a0=4.0, max_steps=10, unit_length=SI(1e-9, "m")) mesh.save(meshfile) def initial_magnetization(xyz, mag_type): import math return [math.cos(xyz[2]), math.sin(xyz[2]), 0.0]
import nmag import time from nmag import SI # Create an HMatrix setup object hms = nmag.HMatrixSetup(nmin=50, eps_aca=1e-5, quadorder=2) # When creating the simulation object, specify that the BEM hmatrix # should be set up using the object hms. sim = nmag.Simulation(phi_BEM=hms) #specify magnetic material, parameters chosen as in example 1 Py = nmag.MagMaterial(name="Py", Ms=SI(1e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m")) #load the mesh sim.load_mesh('sphere.nmesh.h5', [('sphere', Py)], unit_length=SI(1e-9, 'm')) #set the initial magnetisation sim.set_m([1, 0, 0]) #save the demagnetisation field sim.save_data(fields=['H_demag']) #probe the demagnetisation field at ten points within the sphere for i in range(-5, 6): x = i * 1e-9 Hdemag = sim.probe_subfield_siv('H_demag', [x, 0, 0]) print "x=", x, ": H_demag = ", Hdemag
import nmag from nmag import SI mat_Py = nmag.MagMaterial(name="Py", Ms=SI(0.86e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_damping=0.5) sim = nmag.Simulation("bar") sim.load_mesh("coarse_bar.nmesh.h5", [("Py", mat_Py)], unit_length=SI(1e-9, "m")) #sim.load_mesh("bar.nmesh.h5", # [("Py", mat_Py)], # unit_length=SI(1e-9,"m")) sim.set_m([1, 0, 1]) dt = SI(5e-12, "s") ###### # After ten time steps, plot the energy density # from z=0nm to z=100nm through the center of the body. ###### sim.advance_time(dt * 10) f = open("nmag_exch_Edensity.txt", "w") f2 = open("nmag_demag_Edensity.txt", "w") for i in range(100): f.write("%g " %
import os H_x = SI(0.0e6, "A/m") H_y = SI(0.0e6, "A/m") H_z = SI(0.0e6, "A/m") intensive_param_by_name = {"H_x": H_x, "H_y": H_y, "H_z": H_z} mat_void = nmag.MagMaterial(name="void", Ms=SI(0.1e6, "A/m"), exchange_coupling=SI(0.0e-12, "J/m")) mat_Py = nmag.MagMaterial(name="Py", Ms=SI(1e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m")) sim = nmag.Simulation("sphere", mesh_unit_length=SI(1e-9, "m"), fem_only=False) meshfile = "sphere-fem-bem.nmesh.h5" sim.load_mesh(meshfile, [("Py", mat_Py)]) sim.save_mesh("/tmp/debug.mesh") def initial_magnetization(coords, mag_type): if coords[0] > 0: return [1, 0, 0] else: return [-1, 0, 0] sim.set_magnetization(initial_magnetization)
#import ocaml #print "DDD SPEEDTEST: ",ocaml.ddd_speedtest_lindholm(939*939*2) time_total = -time.time() time_writing = 0.0 time_initialising = -time.time() mat_Py = nmag.MagMaterial( name="Py", Ms=SI(0.86e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_gamma_G=SI(0.2211e6, "m/A s"), # llg_damping=SI(0,"") ) sim = nmag.Simulation(use_pvode=True) meshfile = "bar30_30_100.nmesh.h5" sim.load_mesh(meshfile, [("Py", mat_Py)], unit_length=SI(1e-9, "m")) import math angle_deg = 45 angle_rad = angle_deg / 360. * 2 * math.pi sim.set_m([math.cos(angle_rad), 0, math.sin(angle_rad)]) sim.set_params(ts_rel_tol=2.7e-05, ts_abs_tol=2.7e-05) dt = SI(5e-12, "s") time_initialising += time.time() time_loop = -time.time()
import nmag import time from nmag import SI # When creating the simulation object, specify that the BEM hmatrix should be # set up by using the default parameters. sim = nmag.Simulation(phi_BEM=nmag.default_hmatrix_setup) # Specify magnetic material, parameters chosen as in example 1 Py = nmag.MagMaterial(name="Py", Ms=SI(1e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m")) # Load the mesh sim.load_mesh('sphere.nmesh.h5', [('sphere', Py)], unit_length=SI(1e-9, 'm')) # Set the initial magnetisation sim.set_m([1, 0, 0]) # Save the demagnetisation field sim.save_data(fields=['H_demag']) # Probe the demagnetisation field at ten points within the sphere for i in range(-5, 6): x = i * 1e-9 Hdemag = sim.probe_subfield_siv('H_demag', [x, 0, 0]) print "x=", x, ": H_demag = ", Hdemag
import time import nmag from nmag import SI start = time.time() mat_Py = nmag.MagMaterial(name="Py", Ms=SI(0.86e6,"A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_damping=0.5) sim = nmag.Simulation("nmag_bar") sim.load_mesh("bar.nmesh.h5", [("Py", mat_Py)], unit_length=SI(1e-9,"m")) sim.set_m([1,0,1]) dt = SI(5e-12, "s") for i in range(0, 61): sim.advance_time(dt*i) #compute time development sim.save_data() #save averages print "Simulation took {:.3} s.".format(time.time() - start)
mz = 0.1 my = (1.0 - (mx * mx * 0.99 + mz * mz)) ** 0.5 return [mx, my, mz] # Create the material mat_Py = nmag.MagMaterial(name="Py", Ms=SI(0.86e6, "A/m"), exchange_coupling=SI(0, "J/m"), # disables exchange? anisotropy=nmag.uniaxial_anisotropy( axis=[0, 0, 1], K1=SI(520e3, "J/m^3")), llg_gamma_G=SI(0.2211e6, "m/A s"), llg_damping=SI(0.2), llg_normalisationfactor=SI(0.001e12, "1/s")) # Create the simulation object sim = nmag.Simulation("1d", do_demag=False) # Creates the mesh from the layer structure mesh_file_name = '1d.nmesh' mesh_lists = unidmesher.mesh_1d(layers, discretization) unidmesher.write_mesh(mesh_lists, out=mesh_file_name) # Load the mesh sim.load_mesh(mesh_file_name, [("Py", mat_Py)], unit_length=mesh_unit) # Set the initial magnetisation sim.set_m(m0) # Save the anisotropy field once at the beginning of the simulation # for comparison with finmag np.savetxt("anis_t0_ref.txt", sim.get_subfield("H_anis_Py"))
import nmag from nmag import SI, at #create simulation object sim = nmag.Simulation() # define magnetic material Py = nmag.MagMaterial(name="Py", Ms=SI(1e6,"A/m"), exchange_coupling=SI(13.0e-12, "J/m")) # load mesh: the mesh dimensions are scaled by 0.5 nm sim.load_mesh("ellipsoid.nmesh.h5", [("ellipsoid", Py)], unit_length=SI(1e-9,"m")) # set initial magnetisation sim.set_m([1.,0.,0.]) Hs = nmag.vector_set(direction=[1.,0.01,0], norm_list=[ 1.00, 0.95, [], -1.00, -0.95, -0.90, [], 1.00], units=1e6*SI('A/m')) # loop over the applied fields Hs sim.hysteresis(Hs, save=[('restart','fields', at('convergence'))])
) distrib = None if ocaml.petsc_is_mpi(): print "MPI!" print "NODES: ", ocaml.petsc_mpi_nr_nodes() sys.stdout.flush() if ocaml.petsc_mpi_nr_nodes() == 2: distrib = [14280, 14281] else: error( "This example can only run in single-CPU mode or on two machines!") sim = nmag.Simulation( #temperature=SI(0,"K"), #thermal_delta_t=SI(1e-14,"s") ) #meshfile = "bigbar_par.nmesh.h5" #meshfile = "/tmp/bigmesh10000.mesh" meshfile = "/tmp/meshbigbar28000nodes.nmesh" sim.load_mesh(meshfile, [("Py", mat_Py)], unit_length=SI(1e-9, "m"), distrib=distrib) import math angle_deg = 45 angle_rad = angle_deg / 360. * 2 * math.pi sim.set_m([math.cos(angle_rad), 0, math.sin(angle_rad)])
from nmag import SI import nmeshlib.unidmesher as unidmesher mesh_unit = SI(1e-9, "m") # mesh unit (1 nm) layers = [(0.0, 1.0)] # the mesh discretization = 0.2 # discretization def m0(r): """Initial magnetisation 45 degrees between x- and z-axis.""" return [1 / np.sqrt(2), 0, 1 / np.sqrt(2)] mat_Py = nmag.MagMaterial(name="Py", Ms=SI(1, "A/m"), anisotropy=nmag.uniaxial_anisotropy(axis=[0, 0, 1], K1=SI( 1, "J/m^3"))) sim = nmag.Simulation("Simple anisotropy", do_demag=False) # Write mesh to file mesh_file_name = '1d_x6.nmesh' mesh_lists = unidmesher.mesh_1d(layers, discretization) unidmesher.write_mesh(mesh_lists, out=mesh_file_name) sim.load_mesh(mesh_file_name, [("Py", mat_Py)], unit_length=mesh_unit) sim.set_m(m0) print sim.get_subfield("E_anis_Py")
# Set Demag tolerances. ksp_tols = { "DBC.rtol": 1e-7, "DBC.atol": 1e-7, "DBC.maxits": 1000000, "NBC.rtol": 1e-7, "NBC.atol": 1e-7, "NBC.maxits": 1000000, "PC.rtol": 1e-3, "PC.atol": 1e-6, "PC.maxits": 1000000 } # Create the simulation object sim = nmag.Simulation(ksp_tolerances=ksp_tols) # Load the mesh sim.load_mesh(mesh_name, [("Permalloy", Py)], unit_length=SI(1e-9, "m")) # Load the initial magnetisation sim.load_m_from_h5file(relax_name + ".h5") # Set the applied magnetic field sim.set_H_ext(H_direction_normalized, SI(H, 'A/m')) # Set convergence parameters sim.set_params(stopping_dm_dt=0.0, ts_abs_tol=1e-7, ts_rel_tol=1e-7) # Save the information ever 5ps, and exit after 20ns. sim.relax(save=[('fields', every('time', SI(dt, "s")))],
y_lattice = 0.0 z_lattice = 0.0 # list to store the lattice points where the periodic # copies will be placed lattice_points = [] for xi in range(-1, 2): lattice_points.append([xi * x_lattice, 0.0 * y_lattice, 0.0 * z_lattice]) # copies of the system along the x-axis pbc = nmag.SetLatticePoints(vectorlist=lattice_points, scalefactor=SI(1e-9, 'm')) #create simulation object sim = nmag.Simulation(periodic_bc=pbc.structure) # load mesh sim.load_mesh("periodic.nmesh", [("periodic-film", Py)], unit_length=SI(1e-9, "m")) print ocaml.mesh_plotinfo_periodic_points_indices(sim.mesh.raw_mesh) # function to set the magnetisation def perturbed_magnetisation(pos): x, y, z = pos newx = x * 1e9 newy = y * 1e9 if 8 < newx < 14 and -3 < newy < 3: # the magnetisation is twisted a bit
import math """ periodic spinwaves example straight from nmag's documentation http://nmag.soton.ac.uk/nmag/0.2/manual/html/example_periodic_spinwaves/doc.html minus the periodic part... """ # define magnetic material Py = nmag.MagMaterial(name="Py", Ms=SI(1e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_damping=SI(0.02, "")) # create simulation object sim = nmag.Simulation("spinwaves", do_demag=False) # load mesh sim.load_mesh("film.nmesh", [("film", Py)], unit_length=SI(1e-9, "m")) # function to set the magnetisation def perturbed_magnetisation(pos): x, y, z = pos newx = x * 1e9 newy = y * 1e9 if 8 < newx < 14 and -3 < newy < 3: # the magnetisation is twisted a bit return [ 1.0, 5. * (math.cos(math.pi * ((newx - 11) / 6.)))**3 *
import nmag from nmag import SI, every, at from nsim.si_units import si import math # Create simulation object (no demag field!) sim = nmag.Simulation(do_demag=False) # Function to compute the scalar product of the vectors a and b def scalar_product(a, b): return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] # Here we define a function which returns the energy for a uniaxial # anisotropy of order 4. K1 = SI(43e3, "J/m^3") K2 = SI(21e3, "J/m^3") axis = [0, 0, 1] # The (normalised) axis def my_anisotropy(m): a = scalar_product(axis, m) return -K1 * a**2 - K2 * a**4 my_material = nmag.MagMaterial(name="MyMat", Ms=SI(1e6, "A/m"), exchange_coupling=SI(10e-12, "J/m"), anisotropy=my_anisotropy, anisotropy_order=4)
# example 2 of the nmag documentation # without demag but with external field mat_Py = nmag.MagMaterial(name="Py", Ms=SI(0.86e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m"), llg_damping=0.1) L = 30.0e-9 H = 10.0e-9 W = 10.0e-9 def m0(r): mx = 2 * r[0] / L - 1 my = 2 * r[1] / W - 1 mz = 1 return [mx, my, mz] sim = nmag.Simulation("bar", do_demag=False) sim.load_mesh("bar.nmesh.h5", [("Py", mat_Py)], unit_length=SI(1e-9, "m")) sim.set_H_ext([1, 0, 0], SI(0.43e6, "A/m")) sim.set_m(m0) sim.set_params(stopping_dm_dt=1 * degrees_per_ns, ts_rel_tol=1e-6, ts_abs_tol=1e-6) sim.relax(save=[('averages', every('time', SI(5e-11, "s")))])
import nmag from nmag import SI, mesh import nmesh import os H_x = SI(0.0e6, "A/m") H_y = SI(0.0e6, "A/m") H_z = SI(0.0e6, "A/m") intensive_param_by_name = {"H_x": H_x, "H_y": H_y, "H_z": H_z} mat_Py = nmag.MagMaterial(name="Py", Ms=SI(1e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m")) sim = nmag.Simulation("sphere", fem_only=False) unit_length = SI(1e-9, "m") meshfile = "central-sphere-fine.nmesh.h5" sim.load_mesh(meshfile, [("Py", mat_Py)], unit_length=unit_length) def initial_magnetization((x, y, z), mag_type): return [1, 0, 0] sim.set_magnetization(initial_magnetization) sim.compute_H_fields() sim.fun_update_energies([])
from nmag import SI import nmeshlib.unidmesher as unidmesher L = 10 mesh_unit = SI(1e-9, "m") # mesh unit (1 nm) layers = [(0.0, L)] # the mesh discretization = 0.1 # discretization # Initial magnetization xfactor = float(SI("m") / (L * mesh_unit)) def m0(r): return [np.cos(r[0] * np.pi * xfactor), np.sin(r[0] * np.pi * xfactor), 0] mat_Py = nmag.MagMaterial(name="Py", Ms=SI(42, "A/m")) sim = nmag.Simulation("Hans' configuration", do_demag=False) mesh_file_name = '1d.nmesh' mesh_lists = unidmesher.mesh_1d(layers, discretization) unidmesher.write_mesh(mesh_lists, out=mesh_file_name) sim.load_mesh(mesh_file_name, [("Py", mat_Py)], unit_length=mesh_unit) sim.set_m(m0) mod_dir = os.path.dirname(os.path.abspath(__file__)) np.savetxt(os.path.join(mod_dir, "nmag_exchange_energy_density.txt"), sim.get_subfield("E_exch_Py"))
import nmag from nmag import SI, mesh import nmesh import os, sys H_x = SI(0.0e6, "A/m") H_y = SI(0.0e6, "A/m") H_z = SI(0.0e6, "A/m") intensive_param_by_name = {"H_x": H_x, "H_y": H_y, "H_z": H_z} mat_Py = nmag.MagMaterial(name="Py", Ms=SI(1e6, "A/m"), exchange_coupling=SI(13.0e-12, "J/m")) sim = nmag.Simulation("sphere", fem_only=True) unit_length = SI(1e-9, "m") meshfile = "sphere-test-rho-phi2.nmesh" sim.load_mesh(meshfile, [("void", []), ("Py", mat_Py)], unit_length=unit_length) def initial_magnetization((x, y, z), mag_type): return [1, 0, 0] sim.set_magnetization(initial_magnetization) sim.compute_H_fields() sim.fun_update_energies([])
import nmag from nmag import SI, si temperature = SI(2.0, "K") ps = SI(1e-12, "s") sim = nmag.Simulation(temperature=temperature, user_seed_T = 0, 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):