muMAG Standard Problem #4

The standard problem #4 defined by the muMAG group is a famous micromagnetic problem for the validation of a micromagnetic simulator. A rectangular sample with the material parameters of permalloy is prepared in an S-state. Then the time evolution of the system under the influence of an external field is computed.

Code

from magnum import *
from math import pi, cos, sin

# Define the world, a rectangular mesh made of permalloy
world = World(
  RectangularMesh((100, 25, 1), (5e-9, 5e-9, 3.0e-9)),
  Body("all", Material.Py(alpha=0.02)))

# Relax an s-state as the initial magnetization of the SP4.
# Therefore define the following function
def sp4_make_s_state():

  # Specify s-state-like starting state
  def state0(field, pos): 
    u = abs(pi*(pos[0]/field.mesh.size[0]-0.5)) / 2.0
    return 8e5 * cos(u), 8e5 * sin(u), 0

  # Create solver, set parameters and relax 
  # to get initial state for SP4
  solver = create_solver(
    world, [StrayField, ExchangeField], log=True, do_precess=False, 
    evolver="rkf45", eps_abs=1e-4, eps_rel=1e-2)
  solver.state.M = state0
  solver.state.alpha = 0.5
  solver.relax()
  return solver.state.M


# Define a function that sets the magnetization "M0", applies the external
# field "H_ext" and saves the results to the directory "file_dir"
def sp4_apply_field(M0, H_ext, file_dir):
  solver = create_solver(
    world, [StrayField, ExchangeField, ExternalField], log=True, 
    evolver="rkf45", eps_abs=1e-4, eps_rel=1e-4)
  solver.state.M = M0
  solver.state.H_ext_offs = H_ext

  # Add the step handlers which save the simulation data
  solver.addStepHandler(
    VTKStorage(file_dir, "M"), condition.EveryNthStep(100))
  solver.addStepHandler(
    DataTableLog(file_dir + ".odt"), condition.EveryNthStep(10))

  # Simulate for 2 ns
  solver.solve(condition.Time(2.0e-9))


# Perform the simulation
mag0 = sp4_make_s_state()
sp4_apply_field(mag0, (-24.6e-3/MU0, +4.3e-3/MU0, 0.0), "sp4-1")
sp4_apply_field(mag0, (-35.5e-3/MU0, -6.3e-3/MU0, 0.0), "sp4-2")

Results

The time evolution of the magnetization rendered with ParaView

Time Evolution The contents of the odt file plotted with gnuplot