First OOMMFC notebook

After testing the installation of both OOMMF Calculator and OOMMF (on host machine or Docker), we can now run the first Jupyter notebook.

Running Jupyter notebook

The Jupyter notebook can be started by executing

jupyter notebook

command in your terminal (command prompt). A detailed documentation of all powerful Jupyter notebook features can be found at the Project Jupyter website:

However, all you need to know to execute your first OOMMFC notebook is that individual cells containing Python code are executed by pressing Shift + Return.

Note: If you are reading this notebook online (as a part of OOMMFC documentation), you can download the file linked to this URL on your machine:

Alternatively, you can download the entire repository from GitHub from:

unzip the downloaded file, and access all notebooks in docs/ipynb (navigate to this directory and run jupyter notebook in it).

Simple micromagnetic problem

As the first step, we need to import oommfc and discretisedfield.

In [1]:
import oommfc as oc
import discretisedfield as df

Now, we create a very simple system object and provide:

  • Hamiltonian,
  • dynamics, and
  • magnetisation configuration.
In [2]:
system = oc.System(name="first_notebook")

We define the mesh by providing two points between which the domain spans as well as the size of the discretisation cell.

In [3]:
L = 100e-9
d = 10e-9
mesh = oc.Mesh(p1=(0, 0, 0), p2=(L, L, L), cell=(d, d, d))

Our Hamiltonian contains only exchange, demagnetisation, and Zeeman energy terms. We will apply the external magnetic field in the “x” direction, because that allows us to easily predict the equilibrium state of such micromagnetic system.

In [4]:
A = 1e-12
H = (8e6, 0, 0)
system.hamiltonian = oc.Exchange(A=A) + oc.Demag() + oc.Zeeman(H=H)

Dynamics of the system is governed by the LLG equation containing precession and damping terms.

In [5]:
alpha = 0.2
system.dynamics = oc.Precession(gamma=oc.gamma0) + oc.Damping(alpha=alpha)

We initialise the system in (0, 0, 1) direction, which is clearly different from our expected equlibrium state.

In [6]:
system.m = df.Field(mesh, value=(0, 1, 0), norm=8e6)

We can check the characteristics of the system we defined

In [7]:
%matplotlib inline
In [8]:
$\mathcal{H}=A (\nabla \mathbf{m})^{2}-\frac{1}{2}\mu_{0}M_\text{s}\mathbf{m} \cdot \mathbf{H}_\text{d}-\mu_{0}M_\text{s} \mathbf{m} \cdot \mathbf{H}$
In [9]:
$\frac{\partial \mathbf{m}}{\partial t}=-\gamma_{0}^{*} \mathbf{m} \times \mathbf{H}_\text{eff}+\alpha \mathbf{m} \times\frac{\partial \mathbf{m}}{\partial t}$
In [10]:
fig = system.m.plot_plane("z")

After the system object is created, we can minimise its energy (relax it) using the Minimisation Driver (MinDriver).

In [11]:
md = oc.MinDriver()
2018/3/26 16:34: Calling OOMMF (first_notebook/first_notebook.mif) ... [0.6s]

The system is now relaxed, and we can plot its slice and compute its average magnetisation.

In [12]:
fig = system.m.plot_plane("z")
In [13]:
(7943727.692409088, 3.3781556878238917e-05, -1.1175870895385742e-11)

We can see that the magnetisation is aligned along the “x” direction, as expected having in mind we applied the external magnetic field in that direction.