-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagnetization.go
79 lines (70 loc) · 1.89 KB
/
magnetization.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
package engine
import (
"github.com/mumax/3/cuda"
"github.com/mumax/3/data"
"reflect"
)
type magnetization struct {
buffered
}
func (b *magnetization) Set(src *data.Slice) {
if src.Mesh().Size() != b.buffer.Mesh().Size() {
src = data.Resample(src, b.buffer.Mesh().Size())
}
data.Copy(b.buffer, src)
cuda.Normalize(b.buffer, vol())
}
func (b *magnetization) LoadFile(fname string) {
b.Set(LoadFile(fname))
}
// Sets the magnetization inside the shape
// TODO: a bit slowish
func (m *magnetization) SetInShape(region Shape, conf Config) {
if region == nil {
region = universe
}
host := m.buffer.HostCopy()
h := host.Vectors()
n := m.Mesh().Size()
for iz := 0; iz < n[Z]; iz++ {
for iy := 0; iy < n[Y]; iy++ {
for ix := 0; ix < n[X]; ix++ {
r := Index2Coord(ix, iy, iz)
x, y, z := r[X], r[Y], r[Z]
if region(x, y, z) { // inside
m := conf(x, y, z)
h[X][iz][iy][ix] = float32(m[X])
h[Y][iz][iy][ix] = float32(m[Y])
h[Z][iz][iy][ix] = float32(m[Z])
}
}
}
}
m.Set(host)
}
// set m to config in region
func (m *magnetization) SetRegion(region int, conf Config) {
host := m.buffer.HostCopy()
h := host.Vectors()
n := m.Mesh().Size()
r := byte(region)
for iz := 0; iz < n[Z]; iz++ {
for iy := 0; iy < n[Y]; iy++ {
for ix := 0; ix < n[X]; ix++ {
pos := Index2Coord(ix, iy, iz)
x, y, z := pos[X], pos[Y], pos[Z]
if regions.arr[iz][iy][ix] == r {
m := conf(x, y, z)
h[X][iz][iy][ix] = float32(m[X])
h[Y][iz][iy][ix] = float32(m[Y])
h[Z][iz][iy][ix] = float32(m[Z])
}
}
}
}
m.Set(host)
}
func (m *magnetization) SetValue(v interface{}) { m.SetInShape(nil, v.(Config)) }
func (m *magnetization) InputType() reflect.Type { return reflect.TypeOf(Config(nil)) }
func (m *magnetization) Type() reflect.Type { return reflect.TypeOf(new(magnetization)) }
func (m *magnetization) Eval() interface{} { return m }