-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
129 lines (116 loc) · 4.08 KB
/
config.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package engine
// Utilities for setting magnetic configurations.
import (
"github.com/mumax/3/data"
"math"
"math/rand"
)
func init() {
DeclFunc("uniform", Uniform, "Uniform magnetization in given direction")
DeclFunc("vortex", Vortex, "Vortex magnetization with given core circulation and polarization")
DeclFunc("twodomain", TwoDomain, "Twodomain magnetization with with given magnetization in left domain, wall, and right domain")
DeclFunc("vortexwall", VortexWall, "Vortex wall magnetization with given mx in left and right domain and core circulation and polarization")
DeclFunc("addnoise", AddNoise, "Add noise with given amplitude to configuration")
}
// Magnetic configuration returns m vector for position (x,y,z)
type Config func(x, y, z float64) data.Vector
// Returns a uniform magnetization state. E.g.:
// M = Uniform(1, 0, 0)) // saturated along X
func Uniform(mx, my, mz float64) Config {
return func(x, y, z float64) data.Vector {
return data.Vector{mx, my, mz}
}
}
// Make a vortex magnetization with given circulation and core polarization (+1 or -1).
// The core is smoothed over a few exchange lengths and should easily relax to its ground state.
func Vortex(circ, pol int) Config {
diam2 := 2 * sqr64(Mesh().CellSize()[X])
return func(x, y, z float64) data.Vector {
r2 := x*x + y*y
r := math.Sqrt(r2)
mx := -y * float64(circ) / r
my := x * float64(circ) / r
mz := 1.5 * float64(pol) * math.Exp(-r2/diam2)
return data.Vector{mx, my, mz}
}
}
// Make a vortex wall configuration.
func VortexWall(mleft, mright float64, circ, pol int) Config {
h := Mesh().WorldSize()[Y]
v := Vortex(circ, pol)
return func(x, y, z float64) data.Vector {
if x < -h/2 {
return data.Vector{mleft, 0, 0}
}
if x > h/2 {
return data.Vector{mright, 0, 0}
}
return v(x, y, z)
}
}
// Make a 2-domain configuration with domain wall.
// (mx1, my1, mz1) and (mx2, my2, mz2) are the magnetizations in the left and right domain, respectively.
// (mxwall, mywall, mzwall) is the magnetization in the wall. The wall is smoothed over a few cells so it will
// easily relax to its ground state.
// E.g.:
// TwoDomain(1,0,0, 0,1,0, -1,0,0) // head-to-head domains with transverse (Néel) wall
// TwoDomain(1,0,0, 0,0,1, -1,0,0) // head-to-head domains with perpendicular (Bloch) wall
// TwoDomain(0,0,1, 1,0,0, 0,0,-1)// up-down domains with Bloch wall
func TwoDomain(mx1, my1, mz1, mxwall, mywall, mzwall, mx2, my2, mz2 float64) Config {
ww := 2 * Mesh().CellSize()[X] // wall width in cells
return func(x, y, z float64) data.Vector {
var m data.Vector
if x < 0 {
m = data.Vector{mx1, my1, mz1}
} else {
m = data.Vector{mx2, my2, mz2}
}
gauss := math.Exp(-sqr64(x / ww))
m[0] = (1-gauss)*m[0] + gauss*mxwall
m[1] = (1-gauss)*m[1] + gauss*mywall
m[2] = (1-gauss)*m[2] + gauss*mzwall
return m
}
}
// Transl returns a translated copy of configuration c. E.g.:
// M = Vortex(1, 1).Transl(100e-9, 0, 0) // vortex with center at x=100nm
func (c Config) Transl(dx, dy, dz float64) Config {
return func(x, y, z float64) data.Vector {
return c(x-dx, y-dy, z-dz)
}
}
// Scale returns a scaled copy of configuration c.
func (c Config) Scale(sx, sy, sz float64) Config {
return func(x, y, z float64) data.Vector {
return c(x/sx, y/sy, z/sz)
}
}
// Rotates the configuration around the Z-axis, over θ radians.
func (c Config) RotZ(θ float64) Config {
cos := math.Cos(θ)
sin := math.Sin(θ)
return func(x, y, z float64) data.Vector {
x_ := x*cos + y*sin
y_ := -x*sin + y*cos
m := c(x_, y_, z)
mx_ := m[0]*cos - m[1]*sin
my_ := m[0]*sin + m[1]*cos
return data.Vector{mx_, my_, m[2]}
}
}
func AddNoise(amplitude float64, c Config) Config {
return func(x, y, z float64) data.Vector {
m := c(x, y, z)
for i := range m {
m[i] += (rand.Float64() - 0.5)
}
return m
}
}
// Infinitely repeats the shape with given period in x, y, z.
// A period of 0 or infinity means no repetition.
//func (c Config) Repeat(periodX, periodY, periodZ float64) Config {
// return func(x, y, z float64) data.Vector {
// return c(fmod(x, periodX), fmod(y, periodY), fmod(z, periodZ))
// }
//}