In order to calculate the stray field outside the sample, we have to define an "airbox" which is going to contain our sample. In this example we define a box with 100 nm edgle length as a mesh which then contains a magnetic sample which is a cube with 50 nm dimensions. We achieve this by implementing a Python fuction for defining the Ms (norm_fun
). Outside our sample the value of saturation magnetisation is zero.
import discretisedfield as df
import oommfc as oc
mesh = oc.Mesh(p1=(-100e-9, -100e-9, -100e-9), p2=(100e-9, 100e-9, 100e-9), cell=(5e-9, 5e-9, 5e-9))
def norm_fun(pos):
x, y, z = pos
if -50e-9 <= x <= 50e-9 and -50e-9 <= y <= 50e-9 and -50e-9 <= z <= 50e-9:
return 8e5
else:
return 0
system = oc.System(name='airbox_method')
system.hamiltonian = oc.Exchange(A=1e-12) + oc.Demag()
system.dynamics = oc.Precession(gamma=oc.gamma) + oc.Damping(alpha=1)
system.m = df.Field(mesh, value=(0, 0, 1), norm=norm_fun)
We can now plot the norm to confirm our definition.
system.m.norm.plot_plane("x")
In the next step, we can relax the system and show its magnetisation.
md=oc.MinDriver()
md.drive(system)
system.m.plot_plane("z", figsize=(8, 8))
2019/01/16 15:04: Running OOMMF (airbox_method/drive-3/airbox_method.mif) ... (1.8 s)
Stray field can now be calculated as an effective field for the demagnetisation energy.
stray_field = system.hamiltonian.demag.effective_field
2019/01/16 15:05: Running OOMMF (airbox_method/drive-4/airbox_method.mif) ... (2.0 s)
stray_field
is a df.Field
and all operations characteristic to vector fields can be performed.
stray_field.plot_plane("z", figsize=(8, 8))