# MIF 2.1
# MIF Example File: slidingproc.mif
# Description: A Tcl proc is used to define a stage varying applied
#     field.  This is problem is identical to the sliding.mif example,
#     except a Tcl procedure is used instead of a sequence of OVF files.

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

RandomSeed 1

Parameter Happ 100  ;# Applied field strength, in mT
Parameter cellsize 5e-9

# Convert Happ from mT to A/m
set Happ [expr {$Happ*0.001/$mu0}]

Specify Oxs_BoxAtlas:atlas {
  xrange {0 200e-9}
  yrange {0 100e-9}
  zrange {0  20e-9}
}

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

Specify Oxs_UniaxialAnisotropy {
  K1  5e3
  axis {0 1 0}
}

Specify Oxs_UniformExchange {
  A  12e-12
}

proc SlidingField { stage xr yr zr } {
   if {$stage*0.25<$xr && $xr<($stage+1)*0.25} {
      return [list 0.0 1.0 0.0]
   }
   return [list 0.0 0.0 0.0]
}

proc SlidingFieldSpec { stage } {
   set spec [subst {Oxs_ScriptVectorField {
      atlas :atlas
      script {SlidingField $stage}
   }}]
   return $spec
}

Specify Oxs_StageZeeman [subst {
 script SlidingFieldSpec
 multiplier $Happ
 stage_count 4
}]

Specify Oxs_Demag {}

Specify Oxs_CGEvolve:evolve {}

Specify Oxs_MinDriver [subst {
 basename slidingproc
 evolver :evolve
 stopping_mxHxm 0.1
 mesh :mesh
 Ms 800e3
 m0 { 1 0.02 0.01 }
}]
