Micromagnetics

Micromagnetics & Numerical Modelling

Computational tools and numerical methods for micromagnetic simulations, finite element analysis, and stochastic modelling.

Landau-Lifshitz-Gilbert Equation

The fundamental equation of micromagnetics governing magnetisation dynamics:

Where m is the unit magnetisation vector, γ is the gyromagnetic ratio, α is the Gilbert damping parameter, and H_eff is the effective field.

Tools

standard_problem_4.mx3
go
// Standard Problem 4: Magnetization reversal in a permalloy thin film
SetGridsize(128, 32, 1)
SetCellsize(500e-9/128, 125e-9/32, 3e-9)

// Permalloy parameters
Msat  = 800e3
Aex   = 13e-12
alpha = 0.02

// Initial magnetization: S-state
m = uniform(1, .1, 0)
relax()

// Apply field at 170 degrees
B_ext = vector(-24.6E-3 * cos(170 * pi/180), -24.6E-3 * sin(170 * pi/180), 0)

// Run simulation
TableAdd(B_ext)
TableAdd(m)
autosave(m, 5e-11)
tableautosave(1e-11)
run(1e-9)

MuMax3

Documented

GPU-accelerated micromagnetic simulation software using the finite-difference method. Solves the Landau-Lifshitz-Gilbert equation on NVIDIA GPUs for magnetisation dynamics.

standard_problem_4.mx3
go
// Standard Problem 4: Magnetization reversal in a permalloy thin film
SetGridsize(128, 32, 1)
SetCellsize(500e-9/128, 125e-9/32, 3e-9)

// Permalloy parameters
Msat = 800e3
Aex = 13e-12
alpha = 0.02

// Initial magnetization: S-state
m = uniform(1, .1, 0)
relax()

// Apply field at 170 degrees
B_ext = vector(-24.6E-3 * cos(170 * pi/180), -24.6E-3 * sin(170 * pi/180), 0)

// Run simulation
TableAdd(B_ext)
TableAdd(m)
autosave(m, 5e-11)
tableautosave(1e-11)
run(1e-9)

OOMMF

Documented

Object Oriented MicroMagnetic Framework by NIST. Mature, extensible platform for micromagnetic simulations using finite-difference discretisation on CPUs.

stdprob4.mif
tcl
Specify Oxs_StandardMagMaterial {
  Ms 800e3
  A 13e-12
}

Specify Oxs_UniformExchange {}

Specify Oxs_EulerEvolve {
  alpha 0.02
}

GNUPlot

Documented

Command-line driven graphing utility for scientific data visualisation. Used extensively for plotting simulation output, phase diagrams, and hysteresis loops.

plot_hysteresis.gp
gnuplot
set terminal pngcairo size 800,600
set output 'hysteresis.png'
set title 'Magnetic Hysteresis Loop'
set xlabel 'Applied Field (T)'
set ylabel 'Magnetization (M/Ms)'
plot 'data.txt' using 1:2 with lines lw 2 title 'Permalloy'

OpenFOAM

Documented

Open-source CFD toolbox for solving continuum mechanics problems. Finite volume method for fluid dynamics, heat transfer, and multiphysics simulations.

blockMeshDict
cpp
vertices
(
    (0 0 0)
    (1 0 0)
    (1 1 0)
    (0 1 0)
    (0 0 1)
    (1 0 1)
    (1 1 1)
    (0 1 1)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (20 20 20) simpleGrading (1 1 1)
);

Gmsh

Documented

Three-dimensional finite element mesh generator with built-in CAD engine and post-processor. Supports unstructured meshes for complex geometries.

plate_with_hole.geo
cpp
// Rectangle with circular hole - Gmsh .geo script
SetFactory("OpenCASCADE");

// Define rectangle
Rectangle(1) = {0, 0, 0, 10, 5};

// Define circle (hole)
Disk(2) = {5, 2.5, 0, 1.0};

// Boolean subtraction
BooleanDifference(3) = { Surface{1}; Delete; }{ Surface{2}; Delete; };

// Set mesh size
MeshSize{ PointsOf{ Surface{3}; } } = 0.3;

// Generate 2D mesh
Mesh 2;

FEniCS

Documented

Open-source computing platform for solving partial differential equations using the finite element method. Python and C++ interfaces with automated code generation.

poisson.py
python
import dolfinx
from dolfinx import fem, mesh
from mpi4py import MPI
import ufl

# Create unit square mesh
domain = mesh.create_unit_square(MPI.COMM_WORLD, 32, 32)
V = fem.FunctionSpace(domain, ("Lagrange", 1))

# Define boundary condition
u_bc = fem.Function(V)
u_bc.interpolate(lambda x: x[0] * 0.0)
boundary_dofs = fem.locate_dofs_geometrical(V, lambda x: (x[0] < 1e-10) | (x[0] > 1 - 1e-10))
bc = fem.dirichletbc(u_bc, boundary_dofs)

# Define variational problem
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
f = fem.Constant(domain, -6.0)

a = ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx
L = f * v * ufl.dx

# Solve
problem = fem.petsc.LinearProblem(a, L, bcs=[bc])
uh = problem.solve()

deal.II

Documented

C++ finite element library supporting adaptive meshes, multigrid methods, and massively parallel computations. Extensive support for hp-adaptivity.

step-3.cc
cpp
// Laplace equation with deal.II (simplified)
#include <deal.II/grid/tria.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/fe/fe_q.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/vector.h>
#include <deal.II/numerics/matrix_tools.h>
#include <deal.II/numerics/vector_tools.h>

using namespace dealii;

template <int dim>
class LaplaceProblem {
  Triangulation<dim> triangulation;
  FE_Q<dim>          fe;
  DoFHandler<dim>    dof_handler;
  SparsityPattern    sparsity_pattern;
  SparseMatrix<double> system_matrix;
  Vector<double>     solution;
  Vector<double>     system_rhs;

public:
  LaplaceProblem() : fe(2), dof_handler(triangulation) {}

  void run() {
    GridGenerator::hyper_cube(triangulation, -1, 1);
    triangulation.refine_global(5);
    dof_handler.distribute_dofs(fe);
    // ... assemble system and solve
  }
};

PETSc

Documented

Portable, Extensible Toolkit for Scientific Computation. Provides scalable solvers for PDEs — linear/nonlinear solvers, time steppers, and optimisation on distributed systems.

solve.c
c
// PETSc: Solve Ax = b with CG + Jacobi preconditioner
#include <petsc.h>

int main(int argc, char **argv) {
  PetscInitialize(&argc, &argv, NULL, NULL);

  Mat A; Vec x, b;
  KSP ksp; PC pc;
  PetscInt n = 1000;

  // Create matrix and vectors
  MatCreate(PETSC_COMM_WORLD, &A);
  MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, n, n);
  MatSetFromOptions(A);
  MatSetUp(A);

  // ... assemble tridiagonal system ...

  VecCreate(PETSC_COMM_WORLD, &b);
  VecSetSizes(b, PETSC_DECIDE, n);
  VecSetFromOptions(b);
  VecDuplicate(b, &x);

  // Create solver
  KSPCreate(PETSC_COMM_WORLD, &ksp);
  KSPSetOperators(ksp, A, A);
  KSPSetType(ksp, KSPCG);

  // Set preconditioner
  KSPGetPC(ksp, &pc);
  PCSetType(pc, PCJACOBI);

  // Solve
  KSPSolve(ksp, b, x);

  // Clean up
  KSPDestroy(&ksp);
  MatDestroy(&A); VecDestroy(&x); VecDestroy(&b);
  PetscFinalize();
  return 0;
}

Numerical Modelling

Finite Element Methods (FEM)

Discretise the domain into elements (triangles, tetrahedra, hexahedra) and approximate the solution using piecewise polynomial basis functions. Weak formulation transforms the PDE into a system of algebraic equations.

Weak form of Poisson's equation: find u such that the above holds for all test functions v.

Monte Carlo Methods

Stochastic simulation techniques using random sampling to estimate quantities. Applications include thermodynamic equilibrium (Metropolis algorithm), particle transport, uncertainty quantification, and stochastic optimisation.

Monte Carlo estimator: average of observable A over N samples drawn from distribution p(x).

Optimisation

Gradient-based (L-BFGS, conjugate gradient) and derivative-free (Nelder-Mead, genetic algorithms) methods for minimising objective functions. Applied to material design, parameter identification, and inverse problems.

General constrained optimisation problem formulation.

Simulation Resources

Tutorials

Step-by-step guides for setting up and running micromagnetic simulations with MuMax3, OOMMF, and FEniCS.

Under Development

Benchmarks

Standardised micromagnetic benchmark problems (µMAG Standard Problems #1–#5) with reference solutions.

Under Development

Reference Models

Pre-built simulation configurations for common geometries: thin films, nanodots, nanowires, and skyrmion lattices.

Under Development