# MIF 2.1
# MIF Example File: rotatecenter.mif
# Description: Rotating applied field, restricted to central area
#     of the simulation.  Dynamic simulation; applied field
#     rotation frequency is 1 GHz.  Compare to rotate.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
}

# Specify a vector field that is (1,0,0) in the center,
# and dies off to (0,0,0) halfway to the edge.
Specify Oxs_ScriptVectorField:CenterBump {
    atlas :atlas
    script CenterBump
}
proc CenterBump {x y z} {
   global pi
   set x [expr {2*($x-0.5)}]
   set y [expr {2*($y-0.5)}]
   set radsq [expr {$x*$x+$y*$y}]
   if {$radsq>0.5*0.5} { return [list 0. 0. 0.] }
   #return [list [expr {0.5*(1+cos(sqrt($radsq)/$pi))}] 0. 0.]
   return [list [expr {0.5*(1+cos($pi*sqrt($radsq)))}] 0. 0.]
}


# Apply a 75 mT, 1 GHz rotating field, with profile
# as specified by CenterBump.
proc Rotate { freq totaltime } {
   global pi
   set w [expr {2*$pi*$freq}]
   set ct [expr {cos($w*$totaltime)}]
   set mct [expr {-1*$ct}]
   set st [expr {sin($w*$totaltime)}]
   set mst [expr {-1*$st}]
   return [list  $ct $mst  0 \
                 $st $ct   0 \
                  0   0    1 \
                 [expr {$w*$mst}] [expr {$w*$mct}] 0 \
                 [expr {$w*$ct}]  [expr {$w*$mst}] 0 \
                        0                0         0]
}
Specify Oxs_TransformZeeman:Rotating  [subst {
  multiplier [expr {75*(0.001/$mu0)}]
  type general
  script {Rotate 1e9}
  script_args total_time
  field Oxs_ScriptVectorField:CenterBump
}]

Specify Oxs_Demag {}

Specify Oxs_RungeKuttaEvolve:evolve {
 alpha 0.1
}

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