# MIF 2.1
# MIF Example File: cgtest.mif
# Description: Hysteresis loop using conjugate gradient evolver
#     and energy minimization driver.

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 200e-9}
  yrange {0 100e-9}
  zrange {0  20e-9}
}

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

Specify Oxs_CubicAnisotropy {
  K1  -4.5e3
  axis1 {1 0 0}
  axis2 {0 1 0}
}

# NOTE: In the preceding Oxs_CubicAnisotropy Specify block, K1, axis1
# and axis2 are all described above via implicit Oxs_UniformScalarField
# and Oxs_UniformVectorField objects.  That block is *exactly*
# equivalent to
#
#   Specify Oxs_CubicAnisotropy {
#     K1  { Oxs_UniformScalarField {
#              value -4.5e3
#     }}
#     axis1 { Oxs_UniformVectorField {
#              vector {1 0 0}
#     }}
#     axis2 { Oxs_UniformVectorField {
#              vector {0 1 0}
#     }}
#   }
#
# Any of the other Scalar/Vector field objects may be used to initialize
# K1, axis1 and axis2 in place of the Uniform variety.
#
# IN CONTRAST, in the following Specify block, for Oxs_UniformExchange,
# A is an actual scalar, not a scalar field, so it can only be
# initialized via an actual constant.

Specify Oxs_UniformExchange {
  A  9e-12
}

Specify Oxs_UZeeman [subst {
  multiplier [expr {0.001/$mu0}]
  Hrange {
     {   0   0   0   100   1   0   2 }
     { 100   1   0  -100   0   0   2 }
     {   0   0   0     0 100   0   4 }
     {  10  10  10    50  50  50   0 }
  }
}]

Specify Oxs_Demag {}

Specify Oxs_CGEvolve {}

Specify Oxs_MinDriver {
 basename cgtest
 evolver Oxs_CGEvolve
 stopping_mxHxm 0.1
 checkpoint_interval 5
 mesh :mesh
 Ms 8e5
 m0 { Oxs_ScriptVectorField {
   atlas :atlas
   script UpDownSpin
   norm  1
 }}
}

# Ms and m0 above may be initialized using any Scalar/Vector field
# objects.  Ms is implicitly initialized via an implicit
# Oxs_UniformScalarField object, whereas m0 is initialized via an
# explicit embedded Oxs_ScriptVectorField object.  See also the comment
# following the Oxs_CubicAnisotropy Specify block above.

proc UpDownSpin { x y z } {
    if { $x < 0.45 } {
        return "0 1 0"
    } elseif { $x > 0.55 } {
        return "0 -1 0"
    } else {
        return "0 0 1"
    }
}
