# MIF 2.1
#
# muMAG Standard Problem 4.
#
set pi [expr {4*atan(1.0)}]
set mu0 [expr {4*$pi*1e-7}]

Parameter solver rkf54  ;# One of euler, rk2, rk2heun,
                        ## rk4, rkf54, rkf54m, or rkf54s

Parameter subproblem  2  ;# Should be either 1 or 2

Parameter initproblem 0  ;# Use 1 to generate initial state,
            ## or 0 to run using previously generated state.

Parameter xcellsize 2.5e-9
Parameter ycellsize 2.5e-9
Parameter zcellsize   3e-9

Parameter til {} ;# Total iteration limit

if {1 == $subproblem} {
    set basename stdprob4a
    set Hx  -24.6  ;# Applied field in mT
    set Hy    4.3
} elseif {2 == $subproblem} {
    set basename stdprob4b
    set Hx  -35.5  ;# Applied field in mT
    set Hy   -6.3
} else {
    error "Unrecognized subproblem request: $subproblem\
            (should be 1 or 2)"
}
set Hz 0.0

Specify Oxs_BoxAtlas:atlas {
  xrange {0 500e-9}
  yrange {0 125e-9}
  zrange {0   3e-9}
}

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

Specify Oxs_UniformExchange {
  A  13E-12
}

Specify Oxs_Demag {}

if {$initproblem} {
    Specify Oxs_CGEvolve {}
    Specify Oxs_MinDriver [subst {
	basename stdprob4
	evolver Oxs_CGEvolve
	mesh :mesh
	stopping_mxHxm 1e-6
	Ms 8e5
	m0 { 1 0.25 0.1 }
    }]
} else {
    Specify Oxs_FixedZeeman [subst {
        multiplier [expr {0.001/$mu0}]
        field {$Hx $Hy $Hz}
    }]
    if {[string match euler $solver]} {
       Specify Oxs_EulerEvolve:evolver [subst {
          gamma_G             2.211e5
          alpha               0.02
          start_dm            0.01
          error_rate          1.0
          absolute_step_error 0.2
          relative_step_error 0.01
       }]
    } else {
       Specify Oxs_RungeKuttaEvolve:evolver [subst {
          gamma_G             2.211e5
          alpha               0.02
          start_dm            0.01
          error_rate          1.0
          absolute_step_error 0.2
          relative_step_error 0.01
          energy_precision    -1
          method $solver
       }]
    }
    if {![string match {} $til]} {
       set til "total_iteration_limit $til"
    }
    Specify Oxs_TimeDriver [subst {
	basename $basename
	evolver :evolver
	mesh :mesh
	stopping_dm_dt 0.01
	Ms 8e5
	m0 { Oxs_FileVectorField  {
	    atlas :atlas
	    norm  1.0
	    file  stdprob4-start.omf
	}}
        $til
    }]
}
