# MIF 2.1
# MIF Example File: ellipsoid.mif
# Description: Hysteresis loop of an ellipsoidal particle.
#   This example uses an Oxs_EllipsoidAtlas to define the
#   ellipsoid volume.  This example is exactly equivalent
#   to ellipsoid-atlasproc.mif and ellipsoid-fieldproc.mif.

set pi [expr {4*atan(1.0)}]
set mu0 [expr {4*$pi*1e-7}]

Specify Oxs_EllipsoidAtlas:atlas {
  xrange {0 320e-9}
  yrange {0 160e-9}
  zrange {0  80e-9}
  name   ellipsoid
}

Specify Oxs_RectangularMesh:mesh {
  cellsize {5e-9 5e-9 5e-9}
  atlas :atlas
}

# Exchange
Specify Oxs_UniformExchange {
  A   1.3e-11
}

# Demag
Specify Oxs_Demag {}

# Applied field
Specify Oxs_UZeeman [subst {
  multiplier [expr {0.001/$mu0}]
  Hrange {
     {     0    0   0   200   20   20   10 }
     {  200    20  20  -200  -20  -20   20 }
     { -200   -20 -20   200   20   20   20 }
  }
}]

Specify Oxs_CGEvolve:evolve {}

Specify Oxs_MinDriver {
 basename ellipsoid
 evolver :evolve
 stopping_mxHxm 0.1
 mesh :mesh
 Ms { Oxs_AtlasScalarField {
    atlas :atlas
    default_value 0.0
    values {
       ellipsoid 8e5
    }
 }}
 m0 { Oxs_ScriptVectorField {
    atlas :atlas
    script Vortex
    norm  1
 }}
}

proc Vortex { x y z } {
    set yrad [expr {$y-0.5}]
    set zrad [expr {$z-0.5}]
    set normsq [expr {$yrad*$yrad+$zrad*$zrad}]
    if {$normsq <= 0.0125} {return "1 0 0"}
    return [list 0 $zrad [expr {-1*$yrad}]]
}
