# MIF 2.1
# MIF Example File: cube.mif
# Description: Demag accuracy test.

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

RandomSeed 1

Parameter cell_edge_count 2

set cube_edge 10e-9

set cellsize [expr {$cube_edge/double($cell_edge_count)}]

set Ms 8e5

Specify Oxs_BoxAtlas:atlas [subst {
  xrange {0 $cube_edge}
  yrange {0 $cube_edge}
  zrange {0 $cube_edge}
}]

set octant_size [expr {$cellsize*(($cell_edge_count+1)/2)}]
Specify Oxs_BoxAtlas:octant [subst {
  xrange {0 $octant_size}
  yrange {0 $octant_size}
  zrange {0 $octant_size}
}]

Specify Oxs_AtlasVectorField:octant_field_x [subst {
   atlas :octant
   multiplier [expr {-8/$Ms}]
   default_value {0 0 0}
   values {
      octant {1 0 0}
   }
}]

Specify Oxs_AtlasVectorField:octant_field_y [subst {
   atlas :octant
   multiplier [expr {-8/$Ms}]
   default_value {0 0 0}
   values {
      octant {0 1 0}
   }
}]

Specify Oxs_AtlasVectorField:octant_select_x [subst {
   atlas :octant
   default_value {0 0 0}
   values {
      octant {1 0 0}
   }
}]

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

Specify Oxs_Demag [subst {
  user_output {
     name "Nxx"
     source_field Field
     select_field {[expr {-1./$Ms}] 0 0}
     normalize 0
  }
  user_output {
     name "octant Nxx"
     source_field Field
     select_field :octant_field_x
     normalize 0
  }
  user_output {
     name "Nxy"
     source_field Field
     select_field {0 [expr {-1./$Ms}] 0}
     normalize 0
  }
  user_output {
     name "octant Nxy"
     source_field Field
     select_field :octant_field_y
     normalize 0
  }
  comment {Correct octant Nxy value: -0.06162 6950 4494 2262 4}
  comment {   Nxy value at  6 cells: -0.06162 6950 4494 2299 2}
  comment {   Nxy value at 20 cells: -0.06162 6950 4494 2315 1}
  comment {   Nxy value at 50 cells: -0.06162 6950 4494 3782 0}
}]

Specify Oxs_CGEvolve {}

Specify Oxs_MinDriver [subst {
 basename [format "cubetest_%03d" $cell_edge_count]
 evolver Oxs_CGEvolve
 stopping_mxHxm 0.1
 stage_iteration_limit 1
 total_iteration_limit 1
 checkpoint_interval 0
 mesh :mesh
 Ms $Ms
 m0 {1 0 0}
 report_max_spin_angle 1
 user_output {
    name "octant Mx"
    source_field Magnetization
    select_field :octant_select_x
    normalize 1
 }
}]

Destination archive mmArchive
Schedule DataTable archive Step 1
