# MIF 2.1
# MIF Example File: sample-vecrotate.mif
# Description: Example use of the Oxs_AffineOrientVectorField
#   and Oxs_AffineTransformVectorField classes

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

RandomSeed 0

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
}

# Rotate position of :trap 90 degrees counterclockwise,
# and include a translation of -20 nm in the x direction
# to add a rectangular base to the quadrilateral.  Note
# that the Trap proc is defined for all (x,y,z).  We use
# the "inverse" option here.  Otherwise, "M" would have
# to encode a 90 degree cw rotation, and offset would
# be set to a -20 nm translation in the y direction.
# NB: Since the volume specified by :atlas places the
# coordinate origin in the xy-center, a translation
# is not needed to slide the result back into the
# :atlas volume.
# NB: This transformation only effects the position of
# the vectors, not their direction!
Specify Oxs_AffineOrientVectorField:orient {
   field :trap
   M { 0 -1 0
       1  0 0
       0  0 1 }
   offset { -20e-9 0 0 }
   inverse 1
}

# Rotate the direction of the vectors 90 degrees
# counterclockwise.
Specify Oxs_AffineTransformVectorField:rot {
   field :orient
   M { 0 -1 0
       1  0 0
       0  0 1 }
}

# Select field to use.  Should be one of :trap, :orient, or
# :rot.  Set to :trap to use the original (untransformed)
# field.  Set to :orient to see the effect of the :orient
# without :rot.  Or use :rot to see the combined effects.
set use_field :rot

# 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-vecrotate
 m0 $use_field
 Ms :Ms
 stopping_dm_dt 0.01
 evolver :evolve
 mesh :mesh
}]
