# MIF 2.2
# MIF Example File: pbcbrick.mif
# Description: Demag accuracy test for periodic boundaries.

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

RandomSeed 1

Parameter m0 {1 0 0}

Parameter pbcdir x

Parameter Nx 32
Parameter Ny 16
Parameter Nz 16

#Parameter Nx 1
#Parameter Ny 1
#Parameter Nz 1

Parameter arad 32

Parameter itlimit 1

set basename [format "pbcbrick_%03dx%03dx%03d" $Nx $Ny $Nz]

SetOptions [subst {
 basename $basename
 comment {vector_field_output_meshtype irregular}
 comment {vector_field_output_format {text %#g}}
}]

Parameter xrange 100e-9
Parameter yrange  50e-9
Parameter zrange  50e-9

#Parameter xrange 100e-9
#Parameter yrange 100e-9
#Parameter zrange 100e-9

Parameter report_max_spin_angle 1

set xcellsize [expr {$xrange/$Nx}]
set ycellsize [expr {$yrange/$Ny}]
set zcellsize [expr {$zrange/$Nz}]

set Ms 1e6

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

# Specify base octant with a whole number of cells, rounding up.
Specify Oxs_BoxAtlas:octant [subst {
  xrange {0 [expr {ceil($Nx/2.)*$xcellsize}]}
  yrange {0 [expr {ceil($Ny/2.)*$ycellsize}]}
  zrange {0 [expr {ceil($Nz/2.)*$zcellsize}]}
}]

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_field_z [subst {
   atlas :octant
   multiplier [expr {-8/$Ms}]
   default_value {0 0 0}
   values {
      octant {0 0 1}
   }
}]

if {[string match "none" $pbcdir]} {
  Specify Oxs_RectangularMesh:mesh [subst {
   cellsize {$xcellsize $ycellsize $zcellsize}
   atlas :atlas
   }]
} else {
  Specify Oxs_PeriodicRectangularMesh:mesh [subst {
   cellsize {$xcellsize $ycellsize $zcellsize}
   atlas :atlas
   periodic $pbcdir
   }]
}

Specify Oxs_Demag [subst {
  asymptotic_radius $arad
  user_output {
     name "hx"
     source_field Field
     select_field {[expr {-1./$Ms}] 0 0}
     units {}
     normalize 0
  }
  user_output {
     name "octant hx"
     source_field Field
     select_field :octant_field_x
     units {}
     normalize 0
  }
  user_output {
     name "hy"
     source_field Field
     select_field {0 [expr {-1./$Ms}] 0}
     units {}
     normalize 0
  }
  user_output {
     name "octant hy"
     source_field Field
     select_field :octant_field_y
     units {}
     normalize 0
  }
  user_output {
     name "hz"
     source_field Field
     select_field {0 0 [expr {-1./$Ms}]}
     units {}
     normalize 0
  }
  user_output {
     name "octant hz"
     source_field Field
     select_field :octant_field_z
     units {}
     normalize 0
  }
}]

Specify Oxs_CGEvolve {}

Specify Oxs_MinDriver [subst {
 evolver Oxs_CGEvolve
 stopping_mxHxm 0.1
 stage_iteration_limit $itlimit
 total_iteration_limit $itlimit
 checkpoint_interval 0
 mesh :mesh
 Ms $Ms
 m0 [list $m0]
 report_max_spin_angle $report_max_spin_angle
}]

#Destination archive mmArchive
#Schedule DataTable archive Step 1
#Schedule Oxs_Demag::Field archive Step 1
