# MIF 2.1
# MIF Test File: randomshape.mif
# Description: Random shape example

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

Parameter seed 1   ;# Set to an empty string to draw seed from system clock
RandomSeed $seed

Parameter xcount 8
Parameter ycount 7
Parameter zcount 6

set xcellsize 3e-9
set ycellsize 5e-9
set zcellsize 7e-9

Specify Oxs_BoxAtlas:atlas [subst {
   xrange {0 [expr {$xcount*$xcellsize}]}
   yrange {0 [expr {$ycount*$ycellsize}]}
   zrange {0 [expr {$zcount*$zcellsize}]}
}]

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

Specify Oxs_RandomScalarField:Shape {
   range_min 0
   range_max 1
   cache_grid :mesh
}

Specify Oxs_RandomVectorField:Orientation {
   min_norm 1
   max_norm 1
   cache_grid :mesh
}


proc Msval { val } {
   if {$val<0.5} {
      return 0.0
   }
   if {$val<0.75} {
      return 4e5
   }
   return 8e5
}

proc Kval { val } {
   return [expr {-500e3*$val}]
}

Specify Oxs_UniaxialAnisotropy {
   K1 { Oxs_ScriptScalarField {
      script Kval
      script_args scalars
      scalar_fields :Shape
      atlas :atlas
   }}
   axis :Orientation
}

Specify Oxs_UniformExchange {
   A 13e-12
}

Specify Oxs_CGEvolve:evolve {}

Specify Oxs_MinDriver [subst {
 evolver :evolve
 stopping_mxHxm 0.1
 mesh :mesh
 Ms { Oxs_ScriptScalarField {
    atlas :atlas
    script Msval
    script_args scalars
    scalar_fields :Shape
 }}
 m0 :Orientation
}]
