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

RandomSeed 1

Parameter Ms 8e5 ;# A/m

Parameter period        20e-9  ;# All distances in meters
Parameter amplitude      1e-9
Parameter layerA_height 15e-9
Parameter spacer_height  1e-9
Parameter layerB_height  5e-9

Parameter xcellsize 2e-9
Parameter ycellsize 5e-9
Parameter zcellsize 1e-9

Parameter xsize 150e-9
Parameter ysize 100e-9
set zsize [expr {$layerA_height + $spacer_height + $layerB_height}]
set zsize [expr {$zsize + 2*$amplitude}]
set zsize [expr {$zcellsize*round($zsize/$zcellsize)}] ;# Needs
## to be an exact multiple of zcellsize

SetOptions {
 basename modulation
}

### Support procs ##############################################
proc SinusoidalLayers { x y z } {
    global pi Ms
    global period amplitude
    global layerA_height spacer_height layerB_height
    set zcheck [expr {$amplitude*sin(2*$pi*$x/$period)}]
    if {$z<$amplitude+$zcheck} {
	return 0.0  ;# below layerA
    }
    if {$z<$amplitude+$layerA_height+$zcheck} {
        return $Ms  ;# layerA
    }
    if {$z<$amplitude+$layerA_height+$spacer_height+$zcheck} {
	return 0.0  ;# spacer
    }
    if {$z<$amplitude+$layerA_height+$spacer_height+$layerB_height+$zcheck} {
        return $Ms  ;# layerB
    }
    return 0.0      ;# above layerB
}

### Specify blocks #############################################
Specify Oxs_BoxAtlas:atlas [subst {
  xrange {0 $xsize}
  yrange {0 $ysize}
  zrange {0 $zsize}
}]

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

Specify Oxs_UniformExchange:NiFe {
  A  13e-12
}

Specify Oxs_UZeeman [subst {
  multiplier [expr {0.001/$mu0}]
  Hrange {
     {   0   0   0   100   0   0   1}
  }
}]

Specify Oxs_Demag {}

Specify Oxs_EulerEvolve:evolve {}

Specify Oxs_TimeDriver {
 evolver :evolve
 stopping_time {0.25e-9 1.75e-9}
 mesh :mesh
 Ms {Oxs_ScriptScalarField {
    atlas :atlas
    script SinusoidalLayers
    script_args rawpt
 }}
 m0 { 1 0 0 }
}
