forked from mumax/3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext_bubblepos.go
114 lines (92 loc) · 2.11 KB
/
ext_bubblepos.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package engine
import (
"math"
)
var (
BubblePos = NewVectorValue("ext_bubblepos", "m", "Bubble core position", bubblePos)
BubbleDist = NewScalarValue("ext_bubbledist", "m", "Bubble traveled distance", bubbleDist)
BubbleSpeed = NewScalarValue("ext_bubblespeed", "m/s", "Bubble velocity", bubbleSpeed)
BubbleMz = 1.0
)
func init() {
DeclVar("ext_BubbleMz", &BubbleMz, "Center magnetization 1.0 or -1.0 (default = 1.0)")
}
func bubblePos() []float64 {
m := M.Buffer()
n := Mesh().Size()
c := Mesh().CellSize()
mz := m.Comp(Z).HostCopy().Scalars()[0]
posx, posy := 0., 0.
if BubbleMz != -1.0 && BubbleMz != 1.0 {
panic("ext_BubbleMz should be 1.0 or -1.0")
}
{
var magsum float32
var weightedsum float32
for iy := range mz {
for ix := range mz[0] {
magsum += ((mz[iy][ix]*float32(BubbleMz) + 1.) / 2.)
weightedsum += ((mz[iy][ix]*float32(BubbleMz) + 1.) / 2.) * float32(iy)
}
}
posy = float64(weightedsum / magsum)
}
{
var magsum float32
var weightedsum float32
for ix := range mz[0] {
for iy := range mz {
magsum += ((mz[iy][ix]*float32(BubbleMz) + 1.) / 2.)
weightedsum += ((mz[iy][ix]*float32(BubbleMz) + 1.) / 2.) * float32(ix)
}
}
posx = float64(weightedsum / magsum)
}
return []float64{(posx-float64(n[X]/2))*c[X] + GetShiftPos(), (posy-float64(n[Y]/2))*c[Y] + GetShiftYPos(), 0}
}
var (
prevBpos = [2]float64{-1e99, -1e99}
bdist = 0.0
)
func bubbleDist() float64 {
pos := bubblePos()
if prevBpos == [2]float64{-1e99, -1e99} {
prevBpos = [2]float64{pos[X], pos[Y]}
return 0
}
w := Mesh().WorldSize()
dx := pos[X] - prevBpos[X]
dy := pos[Y] - prevBpos[Y]
prevBpos = [2]float64{pos[X], pos[Y]}
// PBC wrap
if dx > w[X]/2 {
dx -= w[X]
}
if dx < -w[X]/2 {
dx += w[X]
}
if dy > w[Y]/2 {
dy -= w[Y]
}
if dy < -w[Y]/2 {
dy += w[Y]
}
bdist += math.Sqrt(dx*dx + dy*dy)
return bdist
}
var (
prevBdist = 0.0
prevBt = -999.0
)
func bubbleSpeed() float64 {
dist := bubbleDist()
if prevBt < 0 {
prevBdist = dist
prevBt = Time
return 0
}
v := (dist - prevBdist) / (Time - prevBt)
prevBt = Time
prevBdist = dist
return v
}