# MIF 2.1
# MIF Example File: rotate.mif
# Description: Uniform rotating applied field.  Dynamic simulation;
#     applied field rotation frequency is 1 GHz.  Compare also
#     rotatecenter.mif.

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

RandomSeed 1

Parameter cellsize 5e-9

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

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

Specify Oxs_CubicAnisotropy {
     K1  48e3
  axis1 {1 0 0}
  axis2 {0 1 0}
}

Specify Oxs_UniformExchange {
  A  21e-12
}

# Apply a 75 mT, 1 GHz rotating field
Specify Oxs_ScriptUZeeman:rotating [subst {
  script {Rotate 1e9}
  script_args total_time
  multiplier [expr {75*(0.001/$mu0)}]
}]

Specify Oxs_Demag {}

Specify Oxs_RungeKuttaEvolve:evolve {
 alpha 0.1
}

Specify Oxs_TimeDriver {
 basename rotate
 evolver :evolve
 stopping_time 1e-9
 stage_count 10
 mesh :mesh
 Ms 1700e3
 m0 {1 0 0}
}

set TWOPI [expr {8*atan(1.)}]

proc Rotate { freq totaltime } {
   global TWOPI
   set w [expr {$freq*$TWOPI}]
   set ct [expr {cos($w*$totaltime)}]
   set st [expr {sin($w*$totaltime)}]
   set mct [expr {-1*$ct}]
   set mst [expr {-1*$st}]
   return [list  $ct $st 0  [expr {-$w*$st}] [expr {$w*$ct}] 0]
}
