# MIF 2.1
# MIF Example File: block.mif
# Description: Test problem for time-varying uniaxial anisotropy

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

Parameter seed 0
eval RandomSeed $seed  ;# Initialize seed to {} to get a seed
## value from the system clock.


set Ms 800e3
set Km [expr {0.5*$mu0*$Ms*$Ms}]
set A 13e-12
set K1 5e5

set xsize  80e-9
set ysize  16e-9
set zsize   8e-9
Parameter cellsize 2e-9

Specify Oxs_MultiAtlas:atlas [subst {
   atlas {Oxs_BoxAtlas {
      xrange {0 [expr {0.5*$xsize}]}
      yrange {0 $ysize}
      zrange {0 $zsize}
      name left
   }}
   atlas {Oxs_BoxAtlas {
      xrange {[expr {0.5*$xsize}] $xsize}
      yrange {0 [expr {0.25*$ysize}]}
      zrange {0 $zsize}
      name rightbottom
   }}
   atlas {Oxs_BoxAtlas {
      xrange {[expr {0.5*$xsize}] $xsize}
      yrange {[expr {0.25*$ysize}] $ysize}
      zrange {0 $zsize}
      name righttop
   }}
}]

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


# Reversing field
Specify Oxs_FixedZeeman [subst {
   field {[expr {1.1*$Km}] 0.1 0.05}
   multiplier -1
}]

# Uniaxial anistropy.
Specify Oxs_UniaxialAnisotropy:Left [subst {
   K1 {Oxs_AtlasScalarField {
      atlas :atlas
      default_value 0.0
      values {
         left $K1
         rightbottom $K1
      }
   }}
   axis {1 0 0}
}]
proc Kmult { stage stage_time } {
   if {$stage != 1} {
      return [list 1.0 0.0]
   }
   set toff 1e-9
   set tscale [expr {4.0/$toff}]
   set t [expr {($stage_time-$toff)*$tscale}]
   set efact [expr {exp(-1*$t*$t)}]
   set mult [expr {1.0 - $efact}]
   set dmult [expr {2*$tscale*$t*$efact}]
   return [list $mult $dmult]
}
Specify Oxs_UniaxialAnisotropy:Right [subst {
   K1 {Oxs_AtlasScalarField {
      atlas :atlas
      default_value 0.0
      values {
         righttop $K1
      }
   }}
   axis {1 0 0}
   multscript Kmult
   multscript_args {stage stage_time}
   stage_count 3
}]

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

# Demag
Specify Oxs_Demag {}

# Evolver
Specify Oxs_RungeKuttaEvolve:evolver {
   alpha 0.1
}

# Driver
Specify Oxs_TimeDriver [subst {
   evolver :evolver
   stopping_dm_dt {0.1 0 0.1}
   stopping_time {0 2e-9 0}
   mesh :mesh
   Ms $Ms
   m0 {1 0 0}
}]
