# MIF 2.1
# MIF Example File: sample-vecreflect.mif
# Description: Example use of the Oxs_ScriptOrientVectorField
#   and Oxs_ScriptVectorField classes.

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

RandomSeed 1

Specify Oxs_BoxAtlas:atlas {
  xrange {-80e-9 80e-9}
  yrange {-80e-9 80e-9}
  zrange {0  40e-9}
}

Specify Oxs_RectangularMesh:mesh {
  cellsize {10e-9 10e-9 10e-9}
  atlas :atlas
}

Specify Oxs_UniformExchange:NiFe {
  A  13e-12
}

Specify Oxs_UZeeman [subst {
  multiplier [expr {0.001/$mu0}]
  Hrange {
     {    0  0  0   1  10  0   10 }
  }
}]

Specify Oxs_Demag {}

Specify Oxs_RungeKuttaEvolve:evolve {}

proc Trap { x y z } {
     if {$y<=$x && $y<=0.5} {return [list 0 1 0]}
     return [list 0 0 0]
}

Specify Oxs_ScriptVectorField:trap {
   script Trap
   atlas :atlas
}

# Reflect about the y-axis
proc Reflect { x y z } {
   return [list $x [expr {-1*$y}] $z]
}

# Reflect :trap field about the y-axis.  Since the atlas is
# xy-symmetric about the coordinate origin, we don't need a
# supplemental translation.  Note the use of "script_args
# rawpt"; the default is relpt which is [0,1] based, which
# does not preserve the symmetry with respect to the origin,
# and would therefore require a slightly more complicated
# Reflect proc.
# NB: This transformation only effects the position of the
# vectors, not their direction.
Specify Oxs_ScriptOrientVectorField:orient {
   field :trap
   script Reflect
   script_args rawpt
}

# Flip the direction of the vector elements.
Specify Oxs_ScriptVectorField:flip {
   vector_fields :orient
   script Reflect
   script_args vectors
}

# Select one of :trap, :orient, or :flip to see the effect
# of the various transformations.
set use_field :flip

# Create scalar Ms field off of magnitude of vector field
# selected by $use_field.
Specify Oxs_VecMagScalarField:Ms [subst {
   field $use_field
   multiplier 8e5
}]

Specify Oxs_TimeDriver [subst {
 basename sample-vecreflect
 evolver :evolve
 stopping_dm_dt 0.01
 mesh :mesh
 m0 $use_field
 Ms :Ms
}]
