Ejemplo n.º 1
0
def run_simulation(periodic=False, use_hlib=False):
  phi_BEM = (nmag.default_hmatrix_setup if use_hlib else None)
  if periodic:
    pts = [[i*(15.0 + 0.1), 0, 0] for i in (-3, -2, -1, 1, 2, 3)]
    pbc = nmag.SetLatticePoints(vectorlist=pts, scalefactor=nm)
    sim = nmag.Simulation("periodic", periodic_bc=pbc.structure,
                          phi_BEM=phi_BEM)

  else:
    sim = nmag.Simulation("full", phi_BEM=phi_BEM)

  mat = nmag.MagMaterial("Py",
                         Ms=SI(0.86e6, "A/m"),
                         exchange_coupling=SI(13e-12, "J/m"),
                         llg_damping=0.5)

  mesh_file = "periodic.nmesh.h5" if periodic else "full.nmesh.h5"
  sim.load_mesh(mesh_file, [("mesh", mat)], unit_length=nm)

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

  sim.relax(do=[("exit", at("time", 0.5*ns))],
            save=[("averages", every("time", 10*ps))])
Ejemplo n.º 2
0
  v = (1.0e-9, dz, -dy)
  vn = (1.0e-9**2 + dy*dy + dz*dz)**0.5
  return tuple(vi/vn for vi in v)

sim.set_m(m0)

sim.set_H_ext([0, 0, 0], SI("A/m"))

# Direction of the polarization
sim.model.quantities["sl_fix"].set_value(Value([0, 1, 0]))

# Current density
sim.model.quantities["sl_current_density"].set_value(Value(SI(0.1e12, "A/m^2")))


if do_relaxation:
  print "DOING RELAXATION"
  sim.relax(save=[("fields", at("time", 0*ps) | at("convergence"))])
  sim.save_m_to_file(relaxed_m)
  sys.exit(0)

else:
  print "DOING DYNAMICS"
  sim.load_m_from_h5file(relaxed_m)
  sim.set_params(stopping_dm_dt=0*degrees_per_ns)
  sim.relax(save=[("averages", every("time", 5*ps))],
            do=[("exit", at("time", 10000*ps))])

#ipython()

Ejemplo n.º 3
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)
from nmag import every, at
sim.hysteresis(Hs,
               save=[('averages', 'fields', at('stage_end')),
                     ('restart', at('stage_end') | every('step', 1000))])
Ejemplo n.º 4
0
import nmag
from nmag import SI, every, at

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

#create simulation object
sim = nmag.Simulation()

# load mesh
sim.load_mesh("prism.nmesh.h5", [("no-periodic", Py)], unit_length=SI(1e-9,"m") )

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

# loop over the applied field
s = SI(1,"s")

sim.relax(save=[('averages','fields', every('time',5e-12*s) | at('convergence'))])

Ejemplo n.º 5
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'))])

Ejemplo n.º 6
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'))])

Ejemplo n.º 7
0
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*ns)),
                  ('fields', every('time', 0.05*ns) | at('convergence'))])

Ejemplo n.º 8
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')) 
                    ]
               )

Ejemplo n.º 9
0
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")
Ejemplo n.º 10
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'))])
Ejemplo n.º 11
0
              unit_length=SI(1e-9, 'm'))
# set initial magnetisation
sim.set_m([0, 0, 1])


def my_save(sim):
    # only save these Terms and Subfields
    H_ext = sim.get_subfield_average_siv('H_ext')
    print('Save fields of stage %d with H_ext %s' %(sim.stage, str(H_ext)))
    sim.save_data(fields=['id', 'time', 'step', 'stage_time', 'stage_step', 'H_ext', 'M', 'm'])


def my_stage(sim):
    # run the function before every stage start
    H_ext = sim.get_subfield_average_siv('H_ext')
    print('Set new H_ext of stage %d with H_ext %s' %(sim.stage, str(H_ext)))
    def set_H(position):
        x = position[0]
        y = position[1]
        z = position[2]
        return H_ext
    sim.set_H_ext(set_H, unit=SI(1,'A/m'))

# start time
start_time = time.time()
# start hysteresis
sim.hysteresis(Hs, save=[(my_save, at('convergence'))],
               do=[(my_stage, every('stage', 1) & at('stage_step', 0))])
# print simulate time
use_time = (time.time() - start_time) / 60
print('Use Time %f min' % use_time)
Ejemplo n.º 12
0
        u = min(1.0, max(0.0, (x - x0) / (x1 - x0)))
        angle = math.pi * (1.0 - u)
        return [math.cos(angle), math.sin(angle), 0]

    def m0_FePt(r):
        return m0_Py(r)

    def save_m(s):
        s.save_restart_file(relaxed_m_file)

    s = simulation(
        sim_name="relax",
        damping_Py=1.0,
        damping_FePt=1.0,
        initial_m=[m0_Py, m0_FePt],
        save=[("averages", every(1000, "step")), ("fields", at("step", 0) | at("stage_end"))],
        do=[(save_m, at("stage_end"))],
    )
    del s


def set_current(j):
    def j_setter(sim):
        sim.set_current_density([j, 0.0, 0.0], unit=SI("A/m^2"))

    return j_setter


ns = SI(1e-9, "s")
simulation(
    sim_name="stt",
Ejemplo n.º 13
0
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=1e-06 , ts_abs_tol=1.0e-06,stopping_dm_dt = 10*si.degrees_per_ns)

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


time_initialising += time.time()
time_loop = -time.time()

sim.relax(save = [('averages', every('time', 25*ps)|at('convergence')),
                  ('fields',at('convergence'))])

time_loop += time.time()

time_simulating = time_loop - nmag.timing['save_data']
print "Setup took %g seconds" % time_initialising
print "Simulation loop took %g seconds" % time_loop
print "Writing data took: %g seconds" % nmag.timing['save_data']
print "Timestepper took: %g seconds" % time_simulating
print "Total time: %g seconds" % time_total

def out(line, header=False, file="bigbar_timings.log"):
    import os
    if header and os.path.exists(file): return
    f = open(file, "a")
Ejemplo n.º 14
0
# 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)


# set initial magnetisation
sim.set_m([0, 0, 1])
sim.set_params(stopping_dm_dt=2*degrees_per_ns)

def my_save(sim):
    sim.save_data(fields=['id', 'time', 'step', 'stage_time', 'stage_step', 'H_ext', 'M', 'm'])

# save initial data
sim.relax(save=[(my_save, at('convergence'))])

# make H_ext = -H_max where y > 10
def set_H(position):
    # positions unit is nm
    x = position[0] / 1e-9
    y = position[1] / 1e-9
    z = position[2] / 1e-9
    if y < 10:
        return [0, 0, 0]
    return [0, 0, -H_max]
sim.set_H_ext(set_H, unit=SI(1, 'A/m'))
sim.relax(save=[(my_save, at('convergence'))])

print('------make H_ext reserve------')
Ejemplo n.º 15
0
    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])

H_max = 17 * 1e3 * 1e3/(4*math.pi)  # koe to A/m

Hs = nmag.vector_set(direction=[0, 0, 1], norm_list=[-1.0, 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()

sim.hysteresis(Hs, save=[(my_save, at('convergence'))],
               do=[(print_time, every('time',SI(50e-12, 's')) | at('convergence'))])

use_time = (time.time() - start_time) / 60
print('Use Time %f min' % use_time)
Ejemplo n.º 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)
from nmag import every, at
sim.hysteresis(Hs, save=[('averages', 'fields', at('stage_end')),
                         ('restart', at('stage_end') | every('step', 1000))])
Ejemplo n.º 17
0
disturb_duration = 1 * ps

m0_filename = "m0.h5"


def simulate_nanowire(name, damping):
    permalloy = nmag.MagMaterial("Py", Ms=SI(0.86e6, "A/m"), exchange_coupling=SI(13e-12, "J/m"), llg_damping=damping)

    s = nmag.Simulation(name)
    s.load_mesh("cylinder.nmesh.h5", [("nanopillar", permalloy)], unit_length=nm)
    return s


s = simulate_nanowire("relaxation", 0.5)
s.set_m([1, 0, 0])
s.relax(save=[("fields", at("time", 0 * ps) | at("convergence"))])
s.save_restart_file(m0_filename)
del s


def set_to_zero(sim):
    def H_ext(r):
        return [0.0, 0.0, 0.0]

    sim.set_H_ext(H_ext, unit=disturb_amplitude)


c = float(nm / SI("m"))


def set_disturbance(sim):
Ejemplo n.º 18
0
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-6, abs_tolerance=1e-6)

starttime = time.time()

sim.relax(save=[('averages',
                 every('time', 5 * ps)), ('fields', at('convergence'))])

stoptime = time.time()

print "Time spent is %5.2f seconds" % (stoptime - starttime)
Ejemplo n.º 19
0
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")))],
          do=[('exit', at('time', SI(T, "s")))])
Ejemplo n.º 20
0
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()

sim.relax(save = [('averages', every('time', 5*ps)),
                  ('fields', at('convergence'))])


stoptime = time.time()

print "Time spent is %5.2f seconds" % (stoptime-starttime)


Ejemplo n.º 21
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")))])
Ejemplo n.º 22
0
    # ^^^ this is a technicality: functions have to return pure number.
    #     H_setter returns the field in units of gaussian_amplitude.
    #     We then compute H, the float components in such units.

    def H_setter(r):
        x, y, z = r
        return ([H[0], H[1], H[2]+amplitude]
                if x < 6.5e-9 else H)
        # ^^^ apply the pulse only to the first dot

    H_value = H_setter if abs(amplitude) > 1e-4 else H
    # ^^^ to speed up things

    fieldname = 'H_ext'
    sim._fields.set_subfield(None, # subfieldname
                             H_value,
                             gaussian_amplitude,
                             fieldname=fieldname,
                             auto_normalise=False)
    (mwe, field) = sim._master_mwes_and_fields_by_name[fieldname]
    ocaml.lam_set_field(sim._lam, field, "v_" + fieldname)
    print "*",

sim.pre_rhs_funs.append(update_H_ext)

sim.set_params(stopping_dm_dt=0) # Never stop for convergence
sim.relax(save=[#('averages', every('time', 2.5*ps)),
                ('fields', every('time', 20*ps))],
          do=[('exit', at('stage_time', 5000*ps))])

Ejemplo n.º 23
0
  # 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

# If the initial magnetisation has not been calculated and saved into
# the file relaxed_m_file, then do it now!
if not os.path.exists(relaxed_m_file):
  # Initial direction for the magnetisation
  def m0(p):
      x, y, z = p
      tmp = min(1.0, max(-1.0, float(SI(x, "m")/(mesh_unit*hl))))
      angle = 0.5*math.pi*tmp
      return [math.sin(angle), math.cos(angle), 0.0]

  save = [('fields', at('step', 0) | at('stage_end')),
          ('averages', every('time', SI(5e-12, 's')))]

  sim = run_simulation(sim_name="relaxation", initial_m=m0,
                       damping=0.5, j=0.0, save=save,
                       stopping_dm_dt=1.0*degrees_per_ns)
  sim.save_restart_file(relaxed_m_file)
  del sim

# Now we simulate the magnetisation dynamics
save = [('averages', every('time', SI(9e-12, 's')))]
do   = [('exit', at('time', SI(6e-9, 's')))]
run_simulation(sim_name="dynamics", initial_m=relaxed_m_file, damping=0.02,
               j=0.1e12, P=1.0, save=save, do=do, stopping_dm_dt=0.0)
Ejemplo n.º 24
0
# We model a bar 100 nm x 100 nm x 10 nm where a vortex sits in the center.
# This is part I: we just do a relaxation to obtain the shape of the vortex.
import math, nmag
from nmag import SI, at
from nsim.si_units.si import degrees_per_ns

# 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_damping=1.0)

# 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 a initial magnetisation which will relax into a vortex
def initial_m(p):
  x, y, z = p
  return [-(y-50.0e-9), (x-50.0e-9), 40.0e-9]

sim.set_m(initial_m)

# Set convergence parameters and run the simulation
sim.set_params(stopping_dm_dt=1.0*degrees_per_ns)
sim.relax(save=[('fields', at('step', 0) | at('stage_end'))])

# Write the final magnetisation to file "vortex_m.h5"
sim.save_restart_file("vortex_m.h5")
Ejemplo n.º 25
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))])
Ejemplo n.º 26
0
# Pinning at the borders
def pinning(p):
    x = float(SI(p[0], "m")/(hl*unit_length))
    if abs(x) >= 0.999:
        return 0.0
    else:
        return 1.0

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

s = Simulation()

s.load_mesh(run.get_mesh_file_name(),
            [('region1', mat_Py)],
            unit_length=unit_length)

s.set_m(m0)

s.set_pinning(pinning)

s.relax(save=[('fields', at('time', SI(0, 's')) | at('convergence'))])

s.set_m(m1)
s.relax(save=[('fields', at('stage_time', SI(0, 's'))
                         | at('convergence'))])


Ejemplo n.º 27
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("../example_mfm/disk.nmesh.h5", [("disk", Py)],
              unit_length=SI(1e-9, "m"))

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

# loop over the applied fields Hs
sim.relax(save=[('averages', 'fields', 'restart', at('convergence'))])
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'))

# Set convergence parameters
sim.set_params(stopping_dm_dt=0)

# Save all the information out at the start and at the end
sim.relax(save=[('fields', at('stage_end'))],
          do=[('exit', at('time', SI(T, "s")))])

# Finally, save the system state for the dynamic stage to run from
sim.save_restart_file(sim_output_name + '.h5')
Ejemplo n.º 29
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")

Ejemplo n.º 30
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'))])
Ejemplo n.º 31
0
    v = (1.0e-9, dz, -dy)
    vn = (1.0e-9**2 + dy * dy + dz * dz)**0.5
    return tuple(vi / vn for vi in v)


sim.set_m(m0)

sim.set_H_ext([0, 0, 0], SI("A/m"))

# Direction of the polarization
sim.model.quantities["sl_fix"].set_value(Value([0, 1, 0]))

# Current density
sim.model.quantities["sl_current_density"].set_value(Value(SI(0.1e12,
                                                              "A/m^2")))

if do_relaxation:
    print "DOING RELAXATION"
    sim.relax(save=[("fields", at("time", 0 * ps) | at("convergence"))])
    sim.save_m_to_file(relaxed_m)
    sys.exit(0)

else:
    print "DOING DYNAMICS"
    sim.load_m_from_h5file(relaxed_m)
    sim.set_params(stopping_dm_dt=0 * degrees_per_ns)
    sim.relax(save=[("averages", every("time", 5 * ps))],
              do=[("exit", at("time", 10000 * ps))])

# ipython()
Ejemplo n.º 32
0
# The magnetisation is defined over all the three regions,
# but is pinned in region A and C.
offset = 2e-9   # m (meters)
length = 500e-9 # m

# Set initial magnetisation
def sample_m0((x, y, z)):
  # relative_position goes linearly from -1 to +1 in region B
  relative_position = -2*(x - offset)/length + 1
  mz = min(1.0, max(-1.0, relative_position))
  return [0, math.sqrt(1 - mz*mz), mz]

sim.set_m(sample_m0)

# Pin magnetisation outside region B
def sample_pinning((x, y, z)):
  return x >= offset and x <= offset + length

sim.set_pinning(sample_pinning)

# Save the magnetisation along the x-axis
def save_magnetisation_along_x(sim):
  f = open('bar_mag_x.dat', 'w')
  for i in range(0, 504):
    x = array([i+0.5, 0.5, 0.5]) * 1e-9
    M = sim.probe_subfield_siv('M_Co', x)
    print >>f, x[0], M[0], M[1], M[2]

# Relax the system
sim.relax(save=[(save_magnetisation_along_x, at('convergence'))])
Ejemplo n.º 33
0
import nmag
from nmag import SI, every, at

ocaml.init_hlib("/rhome/ak8w07/mumag/nmag/lib/libhmatrix-1.3.so")


# create simulation object
hp = {}
hp["nfdeg"] = 3
hp["nmin"] = 20
hp["p"] = 4
hp["eta"] = 2.0
hp["eps"] = 0.00001

sim = nmag.Simulation(name="bar_relax", use_hlib=True, use_pvode=False, hlib_params=hp)

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.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"))])
Ejemplo n.º 34
0
              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))
            s.hysteresis_exit()
            f.close()
    print "check_switching_field: done!"

s.hysteresis(Hs,
             save=[('field_m', at('convergence'))],
             do=[(check_switching_field, at('convergence'))])

Ejemplo n.º 35
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")))])
# 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")))],
          do=[('exit', at('time', SI(T, "s")))])
Ejemplo n.º 37
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"))])
Ejemplo n.º 38
0
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()

sim.hysteresis(Hs,
               save=[(my_save, at('convergence'))],
               do=[(print_time,
                    every('time', SI(50e-12, 's')) | at('convergence'))])

use_time = (time.time() - start_time) / 60
print('Use Time %f min' % use_time)
Ejemplo n.º 39
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))])
Ejemplo n.º 40
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'))]
               )

Ejemplo n.º 41
0
y_lattice = 10.01  # between repeated copies of the simualtion cell
z_lattice = 0.0

# list to store the lattice points where the periodic
# copies of the simulation cell will be placed
lattice_points = []

for xi in range(-4, 6):
    for yi in range(-19, 21):
        lattice_points.append(
            [xi * x_lattice, yi * y_lattice, 0.0 * z_lattice])

# create data structure pbc for this macro geometry
pbc = nmag.SetLatticePoints(vectorlist=lattice_points,
                            scalefactor=SI(1e-9, 'm'))

#create simulation object, passing macro geometry data structure
sim = nmag.Simulation(periodic_bc=pbc.structure)

# load mesh
sim.load_mesh("prism.nmesh.h5", [("repeated-prism-2D", Py)],
              unit_length=SI(1e-9, "m"))

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

# loop over the applied field
s = SI(1, "s")
sim.relax(save=[('averages', 'fields',
                 every('time', 5e-12 * s) | at('convergence'))])
Ejemplo n.º 42
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., 1., 0.])

Hs = nmag.vector_set(direction=[1., 1., 0.],
                     norm_list=[1.0, 0.995, [], -1.0, -0.995, -0.990, [], 1.0],
                     units=1e6 * SI('A/m'))

# loop over the applied fields Hs
sim.hysteresis(Hs, save=[('averages', at('convergence'))])
Ejemplo n.º 43
0
s.load_mesh(mesh_filename, [('bar', permalloy)], unit_length=1*nm)

def set_disturbance(is_on):
  c = float(nm/SI('m'))
  def setter(sim):
    def H_ext(r):
      x, y, z = [xi/c - x0i 
                 for xi, x0i in zip(r, disturb_origin)]
                # x, y and z are (floats) in nanometers
      d = math.sqrt(x*x + y*y + z*z)
      if is_on and d < disturb_radius:
        return disturb_direction
      else:
        return [0.0, 0.0, 0.0]
    sim.set_H_ext(H_ext, unit=disturb_amplitude)

  return setter

if not relaxed:
  s.set_m([1, 0, 0])
  s.relax()
  s.save_restart_file(m0_filename)

else:
  s.load_m_from_h5file(m0_filename)
  s.relax(save=[('field_m', every('time', 0.5*ps))],
          do=[(set_disturbance(True), at('time', 0*ps)),
              (set_disturbance(False), at('time', disturb_duration)),
              ('exit', at('time', 1000*ps))])

H_direction_normalized = list(H_direction / np.linalg.norm(H_direction))

# 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(H_direction_normalized, SI(H, "A/m"))

# Set convergence parameters
sim.set_params(stopping_dm_dt=0)

# Save all the information out at the start and at the end
sim.relax(save=[("fields", at("stage_end"))], do=[("exit", at("time", SI(T, "s")))])

# Finally, save the system state for the dynamic stage to run from
sim.save_restart_file(sim_output_name + ".h5")
Ejemplo n.º 45
0
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 *
                 ns)), ('fields',
                        every('time', 0.05 * ns) | at('convergence'))])
Ejemplo n.º 46
0
H_pulse_data = sim.get_subfield("H_ext")

# Do the same for the bias field
sim.set_H_ext(bias_H)
H_bias_data = sim.get_subfield("H_ext")

# Now the applied field at time t will be expressed as
#   H_bias_data + f(t)*H_pulse_data,
# where f(t) is the time dependence of the pulse
def update_H_ext(t_su):
    ut = float(sinc_omega*(t_su*ps - sinc_t0*ps))
    t_amp = math.sin(ut)/ut if abs(ut) > 1e-10 else 1.0

    if abs(t_amp) > 1e-4:
        H_value = H_bias_data + t_amp*H_pulse_data
    else:
        H_value = map(lambda x: float(x/SI("A/m")), bias_H)

    fieldname = 'H_ext'
    sim._fields.set_subfield(None, H_value, SI("A/m"),
                             fieldname=fieldname, auto_normalise=False)
    (mwe, field) = sim._master_mwes_and_fields_by_name[fieldname]
    ocaml.lam_set_field(sim._lam, field, "v_" + fieldname)
    print "*",

sim.pre_rhs_funs.append(update_H_ext)

sim.set_params(stopping_dm_dt=0) # Never stop for convergence
sim.relax(save=[('fields', every('time', 10*ps))],
          do=[('exit', at('stage_time', 10240*ps))])
Ejemplo n.º 47
0
H_max = 17 * 1e3 * 1e3 / (4 * math.pi)  # koe to A/m

Hs = nmag.vector_set(direction=[0, 0, 1],
                     norm_list=[-1.0, 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()

sim.set_H_ext([0, 0, -H_max], SI('A/m'))
sim.relax(save=[(my_save, at('convergence'))],
          do=[(print_time, every('time', SI(50e-12, 's')) | at('convergence'))
              ])
sim.set_H_ext([0, 0, H_max], SI('A/m'))
sim.relax(save=[(my_save, at('convergence'))],
          do=[(print_time, every('time', SI(50e-12, 's')) | at('convergence'))
              ])

use_time = (time.time() - start_time) / 60
print('Use Time %f min' % use_time)
Ejemplo n.º 48
0
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-6,abs_tolerance=1e-6)

starttime = time.time()

sim.relax(save = [('averages', every('time', 5*ps)),
                  ('fields', at('convergence'))])


stoptime = time.time()

print "Time spent is %5.2f seconds" % (stoptime-starttime)


Ejemplo n.º 49
0
# Set initial magnetisation
def sample_m0((x, y, z)):
    # relative_position goes linearly from -1 to +1 in region B
    relative_position = -2 * (x - offset) / length + 1
    mz = min(1.0, max(-1.0, relative_position))
    return [0, math.sqrt(1 - mz * mz), mz]


sim.set_m(sample_m0)


# Pin magnetisation outside region B
def sample_pinning((x, y, z)):
    return x >= offset and x <= offset + length


sim.set_pinning(sample_pinning)


# Save the magnetisation along the x-axis
def save_magnetisation_along_x(sim):
    f = open('bar_mag_x.dat', 'w')
    for i in range(0, 504):
        x = array([i + 0.5, 0.5, 0.5]) * 1e-9
        M = sim.probe_subfield_siv('M_Co', x)
        print >> f, x[0], M[0], M[1], M[2]


# Relax the system
sim.relax(save=[(save_magnetisation_along_x, at('convergence'))])