示例#1
0
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"))
示例#2
0
文件: run.py 项目: Venkat004/nmag-doc
def run_sim(sim):
    # 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

    results = []

    for i in range(-5, 6):
        x = i * 1e-9
        Hdemag = sim.probe_subfield_siv('H_demag', [x, 0, 0])
        results.append(Hdemag)
        print "x=", x, ": H_demag = ", Hdemag

    return results
示例#3
0
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]
示例#4
0
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"))
示例#5
0
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
示例#6
0
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()
示例#7
0
Stability_constant = 55*1.38e-23*350  # Stability Constant
Area_constant = 25e-27  # Area Constant = area * 1e-9
ku_soft = 2.5e5
ku_hard = (Stability_constant/Area_constant-ku_soft*soft_h)/hard_h
print('ku_hard %f' % ku_hard)
K_hard = SI(ku_hard, "J/m^3")
K_soft = SI(ku_soft, "J/m^3")
# LLG damping
LLG_damping = 1.0

# create a simulation
sim = nmag.Simulation()
# --------------------------------------------------------------------------- #
H_1 = nmag.MagMaterial(name='H_1',
    Ms=M_hard,
    exchange_coupling=A_hard,
    anisotropy=nmag.uniaxial_anisotropy(axis=KA_hard, K1=K_hard),
    llg_damping=LLG_damping)
S_2 = nmag.MagMaterial(name='S_2',
    Ms=M_soft,
    exchange_coupling=A_soft,
    anisotropy=nmag.uniaxial_anisotropy(axis=KA_soft, K1=K_soft),
    llg_damping=LLG_damping)
H_3 = nmag.MagMaterial(name='H_3',
    Ms=M_hard,
    exchange_coupling=A_hard,
    anisotropy=nmag.uniaxial_anisotropy(axis=KA_hard, K1=K_hard),
    llg_damping=LLG_damping)
S_4 = nmag.MagMaterial(name='S_4',
    Ms=M_soft,
    exchange_coupling=A_soft,
示例#8
0
import nmag
from nmag import SI, every, at

mat_Py1 = nmag.MagMaterial(name="Py1",
                           Ms=SI(0.86e6, "A/m"),
                           exchange_coupling=SI(13.0e-12, "J/m"),
                           llg_damping=0.5)

mat_Py2 = nmag.MagMaterial(name="Py2",
                           Ms=SI(0.86e6, "A/m"),
                           exchange_coupling=SI(13.0e-12, "J/m"),
                           llg_damping=0.5)

#Example 1: both materials have same magnetisation

sim = nmag.Simulation()

sim.load_mesh("sphere_in_box.nmesh.h5", [("Py1", mat_Py1), ("Py2", mat_Py2)],
              unit_length=SI(15e-9, "m"))

sim.set_m([1, 0, 0])

sim.relax(save=[('averages', 'fields', 'restart',
                 every('step', 1000) | at('convergence'))])
gamma = 2.210173e5  # gyromagnetic ratio (m/As)
alpha = 1  # Gilbert damping

# External magnetic field.
H = 80e3  # A/m
x_direction = 0.813405448449
y_direction = 0.581697151818
z_direction = 0.0

# Total simulation time
T = 5e-9

# Define magnetic material: PermAlloy
Py = nmag.MagMaterial(name="Py",
                      Ms=SI(Ms, 'A/m'),
                      exchange_coupling=SI(A, "J/m"),
                      llg_gamma_G=SI(gamma, 'm/A s'),
                      llg_damping=alpha)

# Create the simulation object
sim = nmag.Simulation()

# Load the mesh
sim.load_mesh(mesh_name, [("Permalloy", Py)], unit_length=SI(1e-9, "m"))

# Set initial magnetization state in positive z direction
sim.set_m([0.0, 0.0, 1.0])

# And set the external field
sim.set_H_ext([x_direction, y_direction, z_direction], SI(H, 'A/m'))
示例#10
0
import nmag
from nmag import SI, every, at

sim = nmag.Simulation()

# define magnetic material Cobalt (data from OOMMF materials file)
Co = nmag.MagMaterial(name="Co",
                      Ms=SI(1400e3, "A/m"),
                      exchange_coupling=SI(30e-12, "J/m"),
                      anisotropy=nmag.uniaxial_anisotropy(axis=[0, 0, 1],
                                                          K1=SI(
                                                              520e3, "J/m^3")))

# define magnetic material Permalley
Py = nmag.MagMaterial(name="Py",
                      Ms=SI(860e3, "A/m"),
                      exchange_coupling=SI(13.0e-12, "J/m"))

# load mesh
sim.load_mesh("two_cubes.nmesh.h5", [("cube1", Py), ("cube2", Co)],
              unit_length=SI(1e-9, "m"))

# set initial magnetisation along the
# positive x axis for both cubes, slightly off in z-direction
sim.set_m([0.999847695156, 0, 0.01745240643731])

ns = SI(1e-9, "s")  # corresponds to one nanosecond

sim.relax(
    save=[('averages',
           every('time', 0.01 *
示例#11
0
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'))])
示例#12
0
# Initial magnetization
xfactor = float(SI("m") / (length * mesh_unit))


def m0(r):
    x = max(0.0, min(1.0, r[0] * xfactor))
    mx = x
    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)
示例#13
0
import time #need this to measure execution time 
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=SI(0.5,""))

sim = nmag.Simulation()

sim.load_mesh("bar30_30_100.nmesh.h5",
              [("Py", mat_Py)],
              unit_length=SI(1e-9,"m"))

sim.set_m([1,0,1])


#Need to call advance time to create timestepper

ps = SI(1e-12, "s") 

sim.advance_time(0*ps)





sim.get_timestepper().set_params(rel_tolerance=1e-8,abs_tolerance=1e-8)

starttime = time.time()
示例#14
0
import nmag
from nmag import SI, every, at
sim = nmag.Simulation()

Pz = nmag.MagMaterial(name= "Pz", Ms=SI(1100e3,"A/m"))
Py = nmag.MagMaterial(name= "Py", Ms=SI(1714e3,"A/m"))

#load mesh
# This works
# sim.load_mesh("sep_cubes.nmesh.h5", [("box1", Pz), ("box2", Py)], unit_length=SI(1e-9,"m"))
# This doesn't
sim.load_mesh("sep_cubes.nmesh.h5",
              [("box1", Pz), ("box2", Py)],
	      unit_length=SI(1e-9,"m"))

# set initial magnetisation
sim.set_m([0.0, 0.0, 1])

sim.advance_time(SI(1e-12, "s"))

示例#15
0

dx = 0.5 * float(discretization * mesh_unit / SI("m"))
xmin = dx
xmax = float(length * mesh_unit / SI("m")) - dx


def pin(r):
    p = (1.0 if xmin <= r[0] <= xmax else 0.0)
    return p


# Create the material
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.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)

sim.set_m(m0)  # Set the initial magnetisation
示例#16
0
import nmag
from nmag import SI, si

# Create the simulation object
sim = nmag.Simulation()

# Define the magnetic material (data from OOMMF materials file)
Fe = nmag.MagMaterial(name="Fe",
                      Ms=SI(1700e3, "A/m"),
                      exchange_coupling=SI(21e-12, "J/m"),
                      anisotropy=nmag.cubic_anisotropy(axis1=[1, 0, 0],
                                                       axis2=[0, 1, 0],
                                                       K1=SI(48e3, "J/m^3")))

# Load the mesh
sim.load_mesh("cube.nmesh", [("cube", Fe)], unit_length=SI(1e-9, "m"))

# Set the initial magnetisation
sim.set_m([0, 0, 1])

# Launch the hysteresis loop
Hs = nmag.vector_set(direction=[1.0, 0, 0.0001],
                     norm_list=[0, 1, [], 19, 19.1, [], 21, 22, [], 50],
                     units=0.001*si.Tesla/si.mu0)
sim.hysteresis(Hs)
示例#17
0
# We model a bar 100 nm x 100 nm x 10 nm where a vortex sits in the center.
# This is part II: we load the vortex from file and apply a spin-polarised current

import nmag
from nmag import SI, every, at

# Define the material
mat_Py = nmag.MagMaterial(name="Py",
                          Ms=SI(0.8e6, "A/m"),
                          exchange_coupling=SI(13.0e-12, "J/m"),
                          llg_gamma_G=SI(0.2211e6, "m/A s"),
                          llg_polarisation=1.0,
                          llg_xi=0.05,
                          llg_damping=0.1)

# Define the simulation object and load the mesh
sim = nmag.Simulation()
sim.load_mesh("pyfilm.nmesh.h5", [("Py", mat_Py)], unit_length=SI(1e-9, "m"))

# Set the initial magnetisation: part II uses the one saved by part I
sim.load_m_from_h5file("vortex_m.h5")
sim.set_current_density([1e12, 0, 0], unit=SI("A/m^2"))

sim.set_params(
    stopping_dm_dt=0.0)  # * WE * decide when the simulation should stop!

sim.relax(save=[('fields', at('convergence') | every('time', SI(1.0e-9, "s"))),
                ('averages', every('time', SI(0.05e-9, "s")) | at('stage_end'))
                ],
          do=[('exit', at('time', SI(10e-9, "s")))])
示例#18
0
import os
import numpy as np
import nmag
from nmag import SI

MODULE_DIR = os.path.dirname(os.path.abspath(__file__))

# create simulation object
sim = nmag.Simulation()

# define magnetic material
Py = nmag.MagMaterial(name='Py', Ms=SI(1.0, 'A/m'))

# load mesh
sim.load_mesh("sphere.nmesh.h5", [('main', Py)], unit_length=SI(1e-9, 'm'))

# set initial magnetisation
sim.set_m([1, 0, 0])

# set external field
sim.set_H_ext([0, 0, 0], SI('A/m'))

H = sim.get_subfield('H_demag')
np.savetxt("H_demag_nmag.txt", H)
示例#19
0
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"))
示例#20
0
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")
示例#21
0
A_soft = SI(2.8e-11, "J/m")
# Anisotropy -- K
Stability_constant = 55 * 1.38e-23 * 350  # Stability Constant
Area_constant = 25e-27  # Area Constant = area * 1e-9
ku_soft = 100.0
ku_hard = (Stability_constant / Area_constant - ku_soft * soft_h) / hard_h
print('ku_hard %f' % ku_hard)
K_hard = SI(ku_hard, "J/m^3")
K_soft = SI(ku_soft, "J/m^3")
# Max Apply Field
H_max = 2 * ku_hard * 1e4 / ms_hard
H_max = H_max * 1e3 / (4 * math.pi)  # koe to A/m
print('H_max %f' % H_max)
Mat_Hard = nmag.MagMaterial(name='Mat_Hard',
                            Ms=M_hard,
                            exchange_coupling=A_hard,
                            anisotropy=nmag.uniaxial_anisotropy(
                                axis=[0, -0.05, -1.0], K1=K_hard),
                            llg_damping=1.0)

Mat_Soft = nmag.MagMaterial(name='Mat_Soft',
                            Ms=M_soft,
                            exchange_coupling=A_soft,
                            anisotropy=nmag.uniaxial_anisotropy(
                                axis=[0, 0, -1.0], K1=K_soft),
                            llg_damping=1.0)

# load mesh
sim.load_mesh('%s' % mesh_file, [('Mat_Hard', Mat_Hard),
                                 ('Mat_Soft', Mat_Soft)],
              unit_length=SI(1e-9, 'm'))
示例#22
0
import nmag
from nmag import SI, every, at, si

#create simulation object and switch off
#the computation of the demagnetising field
sim = nmag.Simulation(do_demag=False)

# define magnetic material so that Js = mu0*Ms = 1 T
Py = nmag.MagMaterial(name="Py",
                      Ms=1.0 * si.Tesla / si.mu0,
                      exchange_coupling=SI(13.0e-12, "J/m"),
                      llg_damping=SI(0.0))
# load mesh
sim.load_mesh("sphere1.nmesh.h5", [("sphere", Py)], unit_length=SI(1e-9, "m"))

# set initial magnetisation
sim.set_m([1, 1, 1])

# set external field
Hs = nmag.vector_set(direction=[0., 0., 1.],
                     norm_list=[1.0],
                     units=1e6 * SI('A/m'))

ps = SI(1e-12, "s")  # ps corresponds to one picosecond

# let the magnetisation precess around the direction of the applied field
sim.hysteresis(Hs,
               save=[('averages', every('time', 0.1 * ps))],
               do=[('exit', at('time', 300 * ps))])
示例#23
0
import nmag, sys
from nmag import SI

try:
    meshfile = sys.argv[1]
    datafile = sys.argv[2]
except IndexError:
    print 'Usage: nmsim %s meshfile outputdatafile' % sys.argv[0]
    sys.exit(1)

#create simulation object
sim = nmag.Simulation()

# define magnetic material
Py = nmag.MagMaterial(name='Py',
                      Ms=SI(1.0, 'A/m'),
                      exchange_coupling=SI(13.0e-12, 'J/m'))

# load mesh
sim.load_mesh(meshfile, [('sphere', Py)], unit_length=SI(1e-9, 'm'))

# set initial magnetisation
sim.set_m([1, 0, 0])

# set external field
sim.set_H_ext([0, 0, 0], SI('A/m'))

# Save and display data in a variety of ways
sim.save_data(fields='all')  # save all fields spatially resolved
# together with average data
示例#24
0
import nmag
from nmag import SI, si, at

# create simulation object
ps = SI(1e-12, "s")

sim = nmag.Simulation()

# define magnetic material (data from Kronmueller's book)
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")))

sim.load_mesh("cube.nmesh.h5", [("cube", NdFeB)], unit_length=SI(1.0e-9, "m"))

sim.set_m([-0.01, -0.01, 1])

Hs = nmag.vector_set(
    direction=[0., 0., 1.],
    norm_list=[-1, -2, [], -4, -4.2, [], -4.9, -4.91, [], -4.94],
    units=1e6 * SI('A/m'))

sim.hysteresis(Hs, save=[('fields', 'restart', at('convergence'))])
示例#25
0
# 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)

# Load the mesh
sim.load_mesh("coin.nmesh.h5", [("coin", my_material)],
              unit_length=SI(1e-9, "m"))

# Set the magnetization
sim.set_m([-1, 0, 0])

# Compute the hysteresis loop
Hs = nmag.vector_set(
    direction=[1.0, 0, 0.0001],
    norm_list=[-0.4, -0.35, [], 0, 0.005, [], 0.15, 0.2, [], 0.4],
    units=si.Tesla / si.mu0)
示例#26
0
Stability_constant = 55*1.38e-23*350  # Stability Constant
Area_constant = 25e-27  # Area Constant = area * 1e-9
ku_soft = 2.5e5
ku_hard = (Stability_constant/Area_constant-ku_soft*soft_h)/hard_h
print('ku_hard %f' % ku_hard)
K_hard = SI(ku_hard, "J/m^3")
K_soft = SI(ku_soft, "J/m^3")
# LLG damping
LLG_damping = 1.0

# create a simulation
sim = nmag.Simulation()
# --------------------------------------------------------------------------- #
H_1 = nmag.MagMaterial(name='H_1',
    Ms=M_hard,
    exchange_coupling=A_hard,
    anisotropy=nmag.uniaxial_anisotropy(axis=KA_hard, K1=K_hard),
    llg_damping=LLG_damping)
S_2 = nmag.MagMaterial(name='S_2',
    Ms=M_soft,
    exchange_coupling=A_soft,
    anisotropy=nmag.uniaxial_anisotropy(axis=KA_soft, K1=K_soft),
    llg_damping=LLG_damping)
H_3 = nmag.MagMaterial(name='H_3',
    Ms=M_hard,
    exchange_coupling=A_hard,
    anisotropy=nmag.uniaxial_anisotropy(axis=KA_hard, K1=K_hard),
    llg_damping=LLG_damping)
S_4 = nmag.MagMaterial(name='S_4',
    Ms=M_soft,
    exchange_coupling=A_soft,
示例#27
0
import nmag
from nmag import SI, every

# This basic simulation gives us an idea about the relaxation properties
# of the system.

# We find that it takes about 200 frames to do one full oscillation,
# which corresponds to a frequency of about f=1 GHz.

#create simulation object
sim = nmag.Simulation()

# define magnetic material
Py = nmag.MagMaterial(name='Py',
                      Ms=SI(1e6, 'A/m'),
                      llg_damping=0.02,
                      exchange_coupling=SI(13.0e-12, 'J/m'))

# load mesh
sim.load_mesh('rod.nmesh.h5', [('rod', Py)], unit_length=SI(1e-9, 'm'))

# set initial magnetisation
sim.set_m([1, 0, 0.1])

# set external field
sim.set_H_ext([0, 0, 0], SI('A/m'))

sim.relax(save=[('fields', every('time', SI(5e-12, "s")))])
示例#28
0
import nmag
from nmag import SI, mesh
import os

#execfile("../msat.inc")

#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)
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([])
示例#30
0
import time
import nmag
from nmag import SI, mesh
import os, math

msat1 = msat2 = 1e6 * SI("A/m")
mat1 = nmag.MagMaterial(name="M1",
                        Ms=msat1,
                        exchange_coupling=SI(13.0e-12, "J/m"))

mat2 = nmag.MagMaterial(name="M2",
                        Ms=msat2,
                        exchange_coupling=SI(13.0e-12, "J/m"))

sim = nmag.Simulation()

sim.load_mesh("touching.nmesh.h5", [("M1", mat1), ("M2", mat2)],
              unit_length=SI(1e-9, "m"))


def m0(r):
    x, y, z = [ri * 1e9 for ri in r]
    return [1, 1, 1]


target_time = sim.advance_time(0)