Exemple #1
0
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)

sim.hysteresis(Hs, save=[('fields', 'averages', at('convergence'))])
Exemple #2
0
            llg_gamma_G=SI(0.2211e6, "m/ A s"),
            llg_normalisationfactor=SI(0.001e12, "1/s"))

mesh_name = "uniaxial_1d"
mesh_unit = SI(1e-9, "m")
new_mesh = True

#--------------------------------------------
## The initial configuration and how the applied field should change

m0 = [1, 0, 1] # Initial direction for the magnetisation

# From the norms and the direction (which is constant) we derive
# all the values that the applied field will take during the simulation
Hs = vector_set(direction=[1, -2, 3],
                norm_list=[-3.0, [200], 3.0],
                units=SI(1e6, "A/m"))

#--------------------------------------------
## Here we set up the simulation

# Create the simulation object
sim = nmag.Simulation("uniaxial_1d", do_demag=True)

# Creates the mesh from the layer structure
sim.load_mesh("bar.nmesh.h5", [("Co", mat_Co)], unit_length=SI(1e-9, "m"))

with open("debug.txt", "w") as f:
  sim.model.write_debug_info(f)

Exemple #3
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'))

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

Hs = nmag.vector_set(direction=[0, 0, 1],
                     norm_list=[0.0, -0.01, [], -1.0],
                     units=H_max * SI('A/m'))


def my_save(sim):
    # only save M, m, H_ext
    sim.save_data(fields=['M', 'm', 'H_ext'])


def print_time(sim):
    sim_time = float(sim.time / SI(1e-12, 's'))
    print('----SIM Time %f ps----' % sim_time)


# start time
start_time = time.time()
Exemple #4
0
# 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_vortex/nanodot.nmesh.h5",
               [("cylinder", Py)],
               unit_length=SI(100e-9,"m")
             )

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

Hs = nmag.vector_set( direction=[1.,0.,0.],
                      norm_list=[12.0, 7.0, [], -200.0],
                      units=1e3*SI('A/m')
                    )


# loop over the applied fields Hs
sim.hysteresis(Hs,
               save=[('averages', at('convergence')),
                     ('fields',   at('convergence')),
		     ('restart',  at('convergence')) 
                    ]
               )

Exemple #5
0
  m_Py = nmag.MagMaterial(name="Py",
                          Ms=SI(8.0e5, "A/m"),
                          exchange_coupling=SI(1.3e-11, "J/m"),
                          llg_damping=alpha,
                          llg_gamma_G=SI(2.211e5, "m/A s"))

  s = nmag.Simulation(name, phi_BEM=hmatrix)
  s.load_mesh("sp4.nmesh.h5", [('bar', m_Py)], unit_length=SI(1e-9, 'm'))
  return s

# Obtain the initial magnetisation configuration (S-state) if necessary
m0_file = "m0.h5"
if "relax" in sys.argv:
  s = new_simulation('relaxation', alpha=1.0)
  Hs = nmag.vector_set(direction=[1, 1, 1],
                       norm_list=[1.00, 0.95, [], 0.0],
                       units=2e6*SI("A/m"))

  s.set_m([1, 1, 1])
  s.hysteresis(Hs)
  s.save_restart_file(m0_file)
  del s

# Run the dynamic simulation for field 1
if "field1" in sys.argv:
  s = new_simulation('field1')
  s.load_m_from_h5file(m0_file)
  s.set_H_ext([-24.6, 4.3, 0.0], mT/mu0)
  s.relax(save=[('averages', every('time', SI(10e-12, "s"))),
                ('fields', at('convergence'))])
Exemple #6
0
exchange_coupling = SI(13.0e-12, "J/m") # Exchange coupling constant
m_sat = SI(0.86e6, "A/m")               # Saturation magnetisation

#--------------------------------------------
## The initial configuration and how the applied field should change

m0 = [1, 0, 1] # Initial direction for the magnetisation

H_direction = [1, 1, 1] # The direction of the applied field
#The list of values taken by the norm of the applied field
H_norms = [10.0, 9.5, [], 0.0]
H_unit = SI(1e6, "A/m") # The unit for these values

# From the norms and the direction (which is constant) we derive
# all the values that the applied field will take during the simulation
Hs = vector_set(direction=H_direction, norm_list=H_norms, units=H_unit)

#--------------------------------------------
## Here we set up the simulation

# Create the material
mat_Py = nmag.MagMaterial(
           name="Py",
           Ms=m_sat,
           exchange_coupling=exchange_coupling,
           anisotropy=nmag.uniaxial_anisotropy(
                        axis=[1,0,0],
                        K1=SI(5e6, "J/m^3")),
           llg_gamma_G=SI(0.2211e6, "m/A s"),
           llg_damping=SI(0.5),
           llg_normalisationfactor=SI(0.001e12, "1/s"))
Exemple #7
0
import nmag, nsim
from nmag import SI, at, every
from nmag import Simulation, MagMaterial
from nmag.constants import degrees_per_ns

mat_Py = MagMaterial(name='Py',
                     Ms=SI(0.86e6, 'A/m'),
                     exchange_coupling=SI(13.0e-12, 'J/m'))

s = Simulation(do_demag=True)
s.set_params(stopping_dm_dt=1*degrees_per_ns)

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

s.set_m([1, 1, 1])

Hs = nmag.vector_set(direction=[1.0, 1.0, 1.0],
                     norm_list=[1.00, 0.95, [], 0.1, 0.09, [],
                                -0.1, -0.15, [], -1.00],
                     units=1e6*SI('A/m'))

s.hysteresis(Hs, save=[('averages', at('convergence'))])

Exemple #8
0
# Nmag example: briefly describe what it does

from nmag.tools import *
from nmag import vector_set

mat_Py = MagMaterial('Py')

s = Simulation()

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

s.set_m([1, 1, 1])

Hs = vector_set(direction=[1., 0.01, 0],
                norm_list=[ 1.00,  0.95, [], -1.00,
                           -0.95, -0.90, [],  1.00],
                units=SI(0.4e6, 'A/m'))

s.hysteresis(Hs, save=[('restart', 'fields', at('convergence'))])

Exemple #9
0
# 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)

# 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)

sim.hysteresis(Hs, save=[('fields', 'averages', at('convergence'))])
Exemple #10
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))])
Exemple #11
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'))])
Exemple #12
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, 0.0, 1.0], 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"))])
Exemple #13
0
                     Ms=SI(0.86e6, 'A/m'),
                     exchange_coupling=SI(13.0e-12, 'J/m'))

s = FDSimulation(do_demag=True)
s.set_params(stopping_dm_dt=20*degrees_per_ns)

nm = SI(1e-9, "m")
def rectangle(pos):
#    if (pos[0] >=10e-9 and pos[0] <= 20e-9 and 
#       pos[1] >=10e-9 and pos[1] <= 20e-9):
        return 'magnetic' 
#    else:
#        return None

s.create_mesh([5, 5, 1], [5.0*nm, 5.0*nm, 3.0*nm], mat_Py,regions=rectangle)
    
s.set_m([1, 1, 1])

Hs = nmag.vector_set(direction=[1.0, 1.0, 1.0],
                     norm_list=[1.00, 0.95, [], 0.1, 0.09, [],
                                -0.1, -0.15, [], -1.00],
                     units=1e6*SI('A/m'))

s.hysteresis(Hs, save=[('field_m', at('time', SI(0, 's')) | at('convergence'))])

# Process the results
NCOL=os.path.join(os.path.dirname(os.path.abspath(nmag.__file__)), "../../bin/ncol")
os.system(NCOL + " run_fdsimulation H_ext_0 H_ext_1 H_ext_2   M_Py_0 M_Py_1 M_Py_2 > fd.dat")
os.system("gnuplot plot.gnp")

Exemple #14
0
#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))])
Exemple #15
0
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( "nanodot1.nmesh.h5",
               [("cylinder", Py)],
               unit_length=SI(100e-9,"m")
             )

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

Hs = nmag.vector_set( direction=[1.,0.,0.],
                      norm_list=[1000.0, 900.0, [],
                                 95.0, 90.0, [],
                                 -100.0, -200.0, [],
                                 -1000.0, -900.0, [],
                                 -95.0, -90.0, [],
                                 100.0, 200.0, [], 1000.0],
                      units=1e3*SI('A/m')
                    )


# loop over the applied fields Hs
sim.hysteresis(Hs,
               save=[('averages', 'fields', 'restart', at('convergence'))]
               )

Exemple #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)
Exemple #17
0
anis_B = nmag.uniaxial_anisotropy(axis=[1, 0, 0], K1=SI(0.1e6, "J/m^3"))
mat_B =  nmag.MagMaterial(name="B",
                          Ms=SI(0.5e6, "A/m"),
                          exchange_coupling=SI(10.0e-12, "J/m"),
                          anisotropy=anis_B,
                          llg_damping=0.1)

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

# Set the coupling between the two magnetisations
sim.set_local_magnetic_coupling(mat_A, mat_B, SI(-1.0e-5, "N/A^2"))

# Load the mesh
sim.load_mesh("thinfilm.nmesh.h5", [("mesh", [mat_A, mat_B])], unit_length=1*nm)

# Set additional parameters for the time-integration
sim.set_params(stopping_dm_dt=1*degrees_per_ns,
               ts_rel_tol=1e-6, ts_abs_tol=1e-6)

sim.set_m([1, 0, 0], 'm_A') # Set the initial magnetisation
sim.set_m([-1, 0, 0], 'm_B')

Hs = vector_set(direction=[0.01, 0.01, 1],
                norm_list=[1.0, 0.95, [], -1.0],
                units=SI(1e6, "A/m"))

sim.hysteresis(Hs, save=[('averages', at('convergence'))])
#sim.hysteresis(Hs, save=[('averages', every('time', 1e5*ps) | at('convergence'))])

Exemple #18
0
    if (x >= -half_sx_m and x <= half_sx_m and
        y >= -half_sy_m and y <= half_sy_m):
        return 'magnetic'

    else:
        return None

s.create_mesh([container_discr, container_discr, pb.nz],
              [pb.dx_dy, pb.dx_dy, pb.dz],
              mat_Py, regions=film,
              origin=(pb.sx*0.5, pb.sy*0.5, pb.sz*0.5))

s.set_m(pb.m0)

Hs = nmag.vector_set(direction=rotate([0.0, 1.0, 0.0], pb.angle),
                     norm_list=[0.0, 0.0015, 0.003, 0.004,
                                0.0045, 0.0001, 0.0065],
                     units=1e6*SI('A/m'))

reference_mz = []
def check_switching_field(s):
    m = s.get_subfield_average('m')
    mz = abs(m[2])
    if len(reference_mz) == 0:
        reference_mz.append(mz)

    else:
        (mz0, ) = reference_mz
        if mz < 0.05*mz0:
            f = open("switching_fields.dat", "a")
            H = [float(Hi/SI('A/m')) for Hi in Hs[s.stage-1]]
            f.write("%g %g %g %g\n" % tuple([pb.angle] + H))
Exemple #19
0
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'))])

Exemple #20
0
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("nanodot1.nmesh.h5", [("cylinder", Py)],
              unit_length=SI(100e-9, "m"))

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

Hs = nmag.vector_set(direction=[1., 0., 0.],
                     norm_list=[
                         1000.0, 900.0, [], 95.0, 90.0, [],
                         -100.0, -200.0, [], -1000.0, -900.0, [], -95.0, -90.0,
                         [], 100.0, 200.0, [], 1000.0
                     ],
                     units=1e3 * SI('A/m'))

# loop over the applied fields Hs
sim.hysteresis(Hs, save=[('averages', 'fields', 'restart', at('convergence'))])