# MIF 2.1
# MIF Example File: varalpha.mif
# Description: Example with time varying applied field and
#              spatially varying damping parameter alpha.

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

RandomSeed 1

# Solver should be one of the following:
#   rk2, rk2heun, rk4, rkf54, rkf54m, rkf54s
Parameter solver rkf54

Parameter cellsize 5e-9

Parameter alphamin 0.01
Parameter alphamax 1.0

Parameter H_amp    10 ;# Applied field amplitude in mT
Parameter H_freq    1 ;# Applied field frequency in GHz

Specify Oxs_BoxAtlas:atlas {
  xrange {0 1000e-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 {1 0 0}
}

Specify Oxs_UniformExchange {
   A  13e-12
}

# For simplicity, no demag
Ignore Specify Oxs_Demag {}

# Time varying applied field
set Hw [expr {2*$pi*$H_freq*1e9}]  ;# Convert freq from GHz to radians/sec
proc Happ { t } {
   # Import time is in seconds.
   # Return value is field in mT.
   global H_amp Hw
   set Hy [expr {$H_amp*sin($Hw*$t)}]
   set dHy_dt [expr {$Hw*$H_amp*cos($Hw*$t)}]
   return [list 0. $Hy 0. 0. $dHy_dt 0.]
}
Specify Oxs_ScriptUZeeman [subst {
   script_args total_time
   script Happ
   multiplier [expr {1.0/(1000.*$mu0)}]
}]


# Spatially varying damping parameter alpha
proc alphascript { x y z } {
   global alphamin alphamax
   return [expr {$alphamin + ($alphamax-$alphamin)*$x}]
}
Specify Oxs_ScriptScalarField:alpha {
   script alphascript
   atlas :atlas
}

Specify Oxs_RungeKuttaEvolve:evolve [subst {
   alpha :alpha
   method $solver
   start_dt 1e-13
}]

Specify Oxs_TimeDriver [subst {
 basename varalpha
 evolver :evolve
 stopping_time 3e-9
 mesh :mesh
 Ms 800e3
 m0 { 1 0.0 0.0 }
}]
