# MIF 2.1

## Universal Constants ##
set pi [expr 4*atan(1.0)]
set mu0 [expr 4*$pi*1e-7]
Parameter kB 1.3806503e-23
Parameter TMR 30 ; # In percentage

## Initial Magnetization ##
Parameter COMPUTE_INITIAL_M 0
Parameter seed 23446
eval RandomSeed $seed
Parameter time_steps 1e-14

## Set Output Format ##
Parameter basename thermSpinXferEvolveExample

## Geometry and Electrical Inputs ##
Parameter total_current 50.0e-6;	# Current in amps
Parameter simTime 1.0e-11

## Material Parameter (Permalloy) ##
Parameter kFac 56;				# Scale energy by this much kT
Parameter Temp 300;                             # Temperature in Kelvin
Parameter Ms 860e3;				# Saturation Magnetization (Amp/Meter) 		
Parameter A    13e-12;				# Exchange Coefficient(Stiffness) (J/Meter)
Parameter Polarization  0.45
Parameter Lambda 2
Parameter sizeLamb 2.5e-9;

set length [expr {11*$sizeLamb}]; 		           # Horizontal direction (X-Direction)
set width  [expr {4*$sizeLamb}]; 		           # Vertical direction (Y-Direction)
set thick  1.0e-9;   				           # Into the plane of monitor (Z-Direction)
set Ku [expr {$kFac*$kB*$Temp/$length/$width/$thick}] ;# one axis anisotropy, J/m^3 (for conventional MTJ satisfying 80kT of activation energy)

Parameter thInitDeg 0.1
Parameter phInitDeg 0.0
set thInit [expr {$thInitDeg*$pi/180}]
set phInit [expr {$phInitDeg*$pi/180}]

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

set current_area [expr {$width*$width}];	# Area of the Rectangle
set Jcurr [expr {$total_current/$current_area}]

Parameter xycellsize [expr {0.5*$sizeLamb}];			# Edge-length of the domain square in the plane
Parameter zcellsize $thick;					# Thickness of the domain normal to the plane


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

# Uniaxial anistropy.  
Specify Oxs_UniaxialAnisotropy [subst {
   K1 $Ku
   axis {0 0 1}
}]

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

# Evolver
Specify Xf_ThermSpinXferEvolve:evolve [subst {
  alpha 0.014
  method rk2heun
  temperature $Temp
  tempscript temperature_profile
  tempscript_args { total_time }
  uniform_seed $seed
  min_timestep [expr {$time_steps}]
  max_timestep [expr {$time_steps}]
  mp {Oxs_ScriptVectorField {
     script dualPinnedLayers
     script_args { relpt }
     atlas :atlas
  } }
  J {Oxs_ScriptScalarField {
    script {Jwrite $Jcurr}
    script_args { relpt }
    atlas :atlas
  } }
  P $Polarization
  Lambda $Lambda
  energy_precision -1
}]

## Driver ##
Specify Oxs_TimeDriver [subst {
 basename [list $basename]
 evolver :evolve
 stopping_time $simTime
 stage_count 1000
 checkpoint_interval 5
 mesh :mesh
 Ms { $Ms }
 m0 { [expr {sin($thInit)}] 0.0 [expr {cos($thInit)}] }
}]

proc dualPinnedLayers { xrel yrel zrel } {
  if {$xrel <= 0.5} { return "0 0 -1" }
  return "0 0 1"
}

proc Jwrite { Jcurr xrel yrel zrel } {
  if {$xrel <= [expr {4.0/11.0}]} { return $Jcurr }
  return 0
}

proc temperature_profile { total_time } {
  if {$total_time <= 1e-9 } { return [expr {0.9+0.1*($total_time/1e-9)}] }
  return 1.0
}

#Destination [subst $basename] mmArchive
#Schedule DataTable [subst $basename] Stage 1
