# MIF 2.1
# MIF Example File: edgecorranisotropy.mif
# Description: Sample use of Oxs_EdgeCorrAnisotropy class

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

RandomSeed 1

Parameter cellsize 5e-9

Parameter DoEdgeCorrection 1

Parameter SupCount 5
Parameter SubCount 5

set Ms 8e5

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

proc Full {Ms x y z} {
   return $Ms
}

proc Ellipse { Ms x y z } {
   # Args: relpt
   set x [expr {2*($x-0.5)}]
   set y [expr {2*($y-0.5)}]
   set radsq [expr {$x*$x+$y*$y}]
   if {$radsq<1.0} { return $Ms }
   return 0.0
}

proc Ellipsoid { Ms x y z } {
   # Args: relpt
   set x [expr {2*($x-0.5)}]
   set y [expr {2*($y-0.5)}]
   set z [expr {2*($z-0.5)}]
   set radsq [expr {$x*$x+$y*$y+$z*$z}]
   if {$radsq<1.0} { return $Ms }
   return 0.0
}

Specify Oxs_ScriptScalarField:fineMs [subst {
   atlas :atlas
   script {Ellipse $Ms}
}]

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

Specify Oxs_UniformExchange {
  comment {A  13e-12}
  lex 5.6858023018340375706248897033035e-9
}

Ignore 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_UZeeman [subst {
  multiplier [expr {0.001/$mu0}]
  Hrange {
      {   0   0   0   [expr {-2./sqrt(2)}] [expr {2./sqrt(2)}]  0   200 }
  }
}]

Specify Oxs_Demag {}

Specify Oxs_CGEvolve:evolve {}

if {$DoEdgeCorrection} {
    Specify Oxs_EdgeCorrAnisotropy [subst {
	supercount {$SupCount $SupCount 1}
	subcount {$SubCount $SubCount 1}
	demag {Oxs_Demag {}}
	mesh :mesh
	Ms :fineMs
	coarsename fatMs
        saveN "edgecorr${SupCount}x${SupCount}x1X${SubCount}x${SubCount}x1"
        readN "edgecorr${SupCount}x${SupCount}x1X${SubCount}x${SubCount}x1"
    }]
    set MsSpec :fatMs
} else {
    set MsSpec :fineMs
}

Specify Oxs_MinDriver [subst {
 evolver :evolve
 basename "ellipsetest-${SupCount}X${SubCount}"
 stopping_mxHxm 1e-4
 mesh :mesh
 Ms $MsSpec
 comment {m0 { 1 0.0 0.0 }}
 m0 { Oxs_ScriptVectorField {
     script {PartRandm0 1 0.5 0.0}
     script_args {}
 }}
 comment {m0 { Oxs_RandomVectorField {
     min_norm 1.0
     max_norm 1.0
 }}}
}]

proc PartRandm0 { x0 y0 z0 } {
    set x [expr {$x0+(2*rand()-1.0)*5}]
    set y [expr {$y0+(2*rand()-1.0)*5}]
    set z [expr {$z0+(2*rand()-1.0)*5}]
    return [list $x $y $z]
}
