-
Notifications
You must be signed in to change notification settings - Fork 0
/
ext_centerwall.go
72 lines (60 loc) · 1.82 KB
/
ext_centerwall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package engine
import (
"fmt"
"github.com/mumax/3/data"
)
var (
DWPos = NewGetScalar("ext_dwpos", "m", "Position of the simulation window while following a domain wall", GetShiftPos) // TODO: make more accurate
)
func init() {
DeclFunc("ext_centerWall", CenterWall, "centerWall(c) shifts m after each step to keep m_c close to zero")
}
func centerWall(c int) {
M := &M
mc := sAverageUniverse(M.Buffer().Comp(c))[0]
n := Mesh().Size()
tolerance := 4 / float64(n[X]) // x*2 * expected <m> change for 1 cell shift
zero := data.Vector{0, 0, 0}
if ShiftMagL == zero || ShiftMagR == zero {
sign := magsign(M.GetCell(0, n[Y]/2, n[Z]/2)[c])
ShiftMagL[c] = float64(sign)
ShiftMagR[c] = -float64(sign)
}
sign := magsign(ShiftMagL[c])
//log.Println("mc", mc, "tol", tolerance)
if mc < -tolerance {
Shift(sign)
} else if mc > tolerance {
Shift(-sign)
}
}
// This post-step function centers the simulation window on a domain wall
// between up-down (or down-up) domains (like in perpendicular media). E.g.:
// PostStep(CenterPMAWall)
func CenterWall(magComp int) {
PostStep(func() { centerWall(magComp) })
}
func magsign(x float64) int {
if x > 0.1 {
return 1
}
if x < -0.1 {
return -1
}
panic(fmt.Errorf("center wall: unclear in which direction to shift: magnetization at border=%v. Set ShiftMagL, ShiftMagR", x))
}
// used for speed
var (
lastShift float64 // shift the last time we queried speed
lastT float64 // time the last time we queried speed
lastV float64 // speed the last time we queried speed
DWSpeed = NewGetScalar("ext_dwspeed", "m/s", "Speed of the simulation window while following a domain wall", getShiftSpeed)
)
func getShiftSpeed() float64 {
if lastShift != GetShiftPos() {
lastV = (GetShiftPos() - lastShift) / (Time - lastT)
lastShift = GetShiftPos()
lastT = Time
}
return lastV
}