# MIF 2.1
# MIF Example File: vortex_pinning.mif
# Description: Test showing vortex pinning as a function of cell size.
#
# Running this example produces one-half of a hysteresis loop, with the
# applied field running from (0,0,0) to (Hmax,0,0).  The sample is a
# soft magnetic strip having dimensions 100 nm x 100 nm x 10 nm.
#

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

# Permalloy parameters
set Ms 8e5    ;# A/m
set A 1.3e-11 ;# J/m
# K = 0 J/m^3

########################################################################
# Simulation parameters

Parameter cellsize 10 ;# Cellsize, in nm

Parameter stop 0.01 ;# Torque topping criteria, in A/m

Parameter Hmax 25 ;# Maximum applied field, in mT

Parameter Hsteps 125 ;# Number of field steps

########################################################################
# Auxiliary variables and adjustments

set xsize 500e-9
set ysize 500e-9
set zsize  10e-9

set csize [expr {$cellsize*1e-9}]  ;# Convert to meters
set xcellsize [expr {$xsize/ceil($xsize/$csize)}] ;# Round to nearest
set ycellsize [expr {$ysize/ceil($ysize/$csize)}]
set zcellsize [expr {$zsize/ceil($zsize/$csize)}]

set basename [format "vortex_pinning-cs%05.2f" [expr {$xcellsize*1e9}]]

########################################################################
# Support procs

proc Vortex { x y z } {
    set xrad [expr {2.*$x-1.}]
    set yrad [expr {2.*$y-1.}]
    set normsq [expr {$xrad*$xrad+$yrad*$yrad}]
    if {$normsq <= 0.05} {return "0 0 1"}
    return [list [expr {-1*$yrad}] $xrad 0]
}

########################################################################

Specify Oxs_BoxAtlas:atlas [subst {
  xrange {0 $xsize}
  yrange {0 $ysize}
  zrange {0 $zsize}
}]

Specify Oxs_RectangularMesh:mesh [subst {
  cellsize {$xcellsize $ycellsize $zcellsize}
  atlas :atlas
}]

# Exchange
Specify Oxs_UniformExchange [subst {
  A  $A
}]

# Demag
Specify Oxs_Demag {}

Specify Oxs_UZeeman [subst {
  multiplier [expr {0.001/$mu0}]
  Hrange {
     {   0   0   0   $Hmax 0 0  $Hsteps }
  }
}]


# Evolver
Specify Oxs_CGEvolve {}

# Driver
Specify Oxs_MinDriver [subst {
   basename [list $basename]
   evolver Oxs_CGEvolve
   stopping_mxHxm $stop
   mesh :mesh
   Ms $Ms
   m0 { Oxs_ScriptVectorField {
    atlas :atlas
    script Vortex
    norm  1
   }}
}]

Destination archive mmArchive
Schedule DataTable archive Stage 1
Schedule Oxs_MinDriver::Magnetization archive Stage 1

# Optionally, may want to save some magnetization states
# Schedule Oxs_MinDriver::Magnetization archive Stage 10
