-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
181 lines (163 loc) · 5.67 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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 circulation and core polarization")
DeclFunc("Antivortex", AntiVortex, "Antivortex magnetization with given circulation and core polarization")
DeclFunc("Skyrmion", Skyrmion, "Skyrmion magnetization with given charge and core polarization")
DeclFunc("Antiskyrmion", Antiskyrmion, "Antiskyrmion magnetization with given charge and core 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("RandomMag", RandomMag, "Random magnetization")
}
// Magnetic configuration returns m vector for position (x,y,z)
type Config func(x, y, z float64) data.Vector
func RandomMag() Config {
return func(x, y, z float64) data.Vector {
return randomDir()
}
}
func randomDir() data.Vector {
phi := rand.Float64() * (2 * math.Pi)
theta := rand.Float64() * math.Pi
x1 := math.Sin(theta) * math.Cos(phi)
y1 := math.Sin(theta) * math.Sin(phi)
z1 := math.Cos(theta)
return data.Vector{x1, y1, z1}
}
// 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}
}
}
func Skyrmion(charge, pol int) Config {
w := 8 * Mesh().CellSize()[X]
w2 := w * w
return func(x, y, z float64) data.Vector {
r2 := x*x + y*y
r := math.Sqrt(r2)
mz := 2*float64(pol)*math.Exp(-r2/w2) - 1
mx := (x * float64(charge) / r) * (1 - math.Abs(mz))
my := (y * float64(charge) / r) * (1 - math.Abs(mz))
return data.Vector{mx, my, mz}
}
}
func Antiskyrmion(charge, pol int) Config {
w := 8 * Mesh().CellSize()[X]
w2 := w * w
return func(x, y, z float64) data.Vector {
r2 := x*x + y*y
r := math.Sqrt(r2)
mz := 2*float64(pol)*math.Exp(-r2/w2) - 1
mx := (-x * float64(charge) / r) * (1 - math.Abs(mz))
my := (y * float64(charge) / r) * (1 - math.Abs(mz))
return data.Vector{mx, my, mz}
}
}
func AntiVortex(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 := -x * float64(circ) / r
my := y * 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[X] = (1-gauss)*m[X] + gauss*mxwall
m[Y] = (1-gauss)*m[Y] + gauss*mywall
m[Z] = (1-gauss)*m[Z] + 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[X]*cos - m[Y]*sin
my_ := m[X]*sin + m[Y]*cos
return data.Vector{mx_, my_, m[Z]}
}
}
func (c Config) Add(weight float64, other Config) Config {
return func(x, y, z float64) data.Vector {
return c(x, y, z).MAdd(weight, other(x, y, z))
}
}
// 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))
// }
//}