# MIF 2.1
# MIF Example File: bench1.mif
# Description: Used for benchmarking OOMMF performance.
#              Based on muMAG Problem 1.

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

Parameter sil 10   ;# Stage iteration limit
# After a 3 step warm-up, two stages of length $sil are run
# and reported as DataTable output to mmArchive.

Parameter number_of_stages 2 ;# Number of stages after the
# first, initialization stage.

Parameter evolver cg
switch -exact $evolver {
   cg -
   rk -
   rk2 -
   rk2heun -
   rk4 -
   rkf54 -
   rkf54m -
   rkf54s -
   euler {}
   default {
      error "Invalid evolver request: \"$evolver\".\
             Should be one of cg, rk, rk2, rk4, rkf54,\
             rkf54m, rkf54s or euler."
   }
}

set RandomAnisotropy 0.0 ;# Scaling for random anisotropy
## term.  If set to 0, then uniform 0.5 kJ/m anisotropy as
## specified in muMAG Standard Problem #1 is applied.

Parameter cellsize 8 ;# Cell size in nm

Parameter basename {}

Parameter archive_nickname {}
if {![string match {} $archive_nickname] \
       && ![string match {:*} $archive_nickname]} {
   set archive_nickname ":$archive_nickname"
}

if {[string match {} $basename]} {
   if {[regexp {^[0-9]$} $cellsize]} {
      # Integer value
      set basename [format "bench1-cs%02d" $cellsize]
   } else {
      # Float?
      set basename [format "bench1-cs%g" $cellsize]
   }
}

set cellsize [expr {$cellsize*1e-9}] ;# Convert to meters

Specify Oxs_BoxAtlas:atlas {
  xrange {0 2048e-9}
  yrange {0 1024e-9}
  zrange {0   32e-9}
}

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

Specify Oxs_UniformExchange {
  A  13e-12
}

if {$RandomAnisotropy>0.0} {
  Specify Oxs_UniaxialAnisotropy [subst {
    K1 { Oxs_RandomScalarField {
        range_min [expr {$RandomAnisotropy*0.5e3}]
        range_max [expr {$RandomAnisotropy*5.0e3}]
    }}
    axis { Oxs_RandomVectorField {
        min_norm 1.0
        max_norm 1.0
    }}
  }]
} else {
  Specify Oxs_UniaxialAnisotropy {
    K1 0.5e3
    axis {1 0 0}
  }
}

Specify Oxs_Demag {}

Specify Oxs_UZeeman [subst {
  multiplier [expr {0.001/$mu0}]
  Hrange {
     { 50  0.87275325  0  50 0.87275325 0  $number_of_stages }
  }
}]

if {[string match cg $evolver]} {
   set driver Oxs_MinDriver
   Specify Oxs_CGEvolve:evolve {}
} else {
   set driver Oxs_TimeDriver
   if {[string match euler $evolver]} {
      Specify Oxs_EulerEvolve:evolve {}
   } else {
      if {[string match rk $evolver]} {
         Specify Oxs_RungeKuttaEvolve:evolve {}
      } else {
         Specify Oxs_RungeKuttaEvolve:evolve [subst {
            method $evolver
         }]
      }
   }
}

Specify $driver [subst {
   basename [list $basename]
   evolver :evolve
   stage_iteration_limit {3 {$sil $number_of_stages} :expand:}
   mesh :mesh
   Ms 8.6e5
   m0 {10 1 0}
   report_wall_time 1
   checkpoint_interval -1
}]

Destination archive mmArchive${archive_nickname}
Schedule DataTable archive Stage 1
