# MIF 2.1
#
# Sample MIF file emulating simulations contained in
#
#   "Spin transfer into an inhomogeneous magnetization distribution,"
#   J. Miltat, G. Albuquerque, A. Thiaville, and C. Vouille,
#   Journal of Applied Physics, 89, 6982-6984 (2001).
#

Parameter COMPUTE_INITIAL_M 0

set basename spinxfer-miltat

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

#Parameter current_density 3.75e12 ;# Current density in A/m^2
Parameter current_density 7.5e12 ;# Current density in A/m^2

#Parameter Happ 0.0 ;# Field in kOe
#set Happ [expr {$Happ*1e6/(4*$pi)}]  ;# Convert to A/m

Parameter Ms  860e3
Parameter A    13e-12

Parameter Polarization 0.25
Parameter Lambda 2.0

Parameter mp_theta 45  ;# Direction of mp, in degrees
set mp_theta [expr {$mp_theta*$pi/180.}]

set length 125e-9
set width  125e-9
set thick    5e-9

Specify Oxs_BoxAtlas:atlas [subst {
  xrange {0 $length}
  yrange {0 $width}
  zrange {0 $thick}
}]

Parameter xycellsize   5e-9
Parameter zcellsize    5e-9

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

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

# Demag
Specify Oxs_Demag {}

if {!$COMPUTE_INITIAL_M} {

# Evolver
Specify Oxs_SpinXferEvolve:evolve [subst {
  alpha 0.014
  start_dm 0.01
  mp {[expr {cos($mp_theta)}] [expr {sin($mp_theta)}] 0}
  J $current_density
  J_profile Jprofile
  J_profile_args total_time
  P $Polarization
  Lambda $Lambda
}]

# Driver
Specify Oxs_TimeDriver [subst {
 basename $basename
 evolver :evolve
 stopping_dm_dt 1e-9
 stopping_time 5e-9
 mesh :mesh
 Ms $Ms
 m0 { Oxs_FileVectorField {
    atlas :atlas
    file ${basename}-start.omf
    norm 1.0
 }}
}]

} else {

Specify Oxs_CGEvolve:evolve {}

Specify Oxs_MinDriver [subst {
 basename $basename
 evolver :evolve
 stopping_mxHxm 0.01
 mesh :mesh
 Ms $Ms
 comment {m0 { Oxs_FileVectorField {
    atlas :atlas
    file ${basename}-start.omf
    norm 1.0
 }}}
 m0 { [expr {cos(135*$pi/180.)}] [expr {sin(135*$pi/180.)}] 0.0}
}]

}

proc C_State { x y z } {
    if {$x<0.25} { return [list 0.  1.  0.1] }
    if {$x>0.75} { return [list 0. -1. -0.1] }
    return [list 1. 0. 0.]
}

proc Jprofile { t } {
    set scale 0.0;
    if {$t<0.01e-9} {
        set scale [expr {$t/0.01e-9}]
    } elseif {$t<0.74e-9} {
        set scale 1.0
    } elseif {$t<0.75e-9} {
        set scale [expr {(0.75e-9-$t)/0.01e-9}]
    }
    return $scale
}
