forked from JLeliaert/vinamax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjumpnoise.go
executable file
·120 lines (92 loc) · 3.06 KB
/
jumpnoise.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
//This file contains functions used for the jumpnoise
package vinamax
import (
"math"
// "fmt"
)
//calculates the attempt frequency of a particle
func attemptf1(p *particle) float64 {
volume := cube(p.r) * 4. / 3. * math.Pi
hk := 2. * Ku1 / (p.msat * mu0)
gprime := Alpha * gamma0 * mu0 / (1. + (Alpha * Alpha))
delta := Ku1 * volume / (kb * Temp)
bx, by, bz := B_ext(T)
bextvector := vector{bx / mu0, by / mu0, bz / mu0}
hoverhk := math.Abs(bextvector.dot(p.u_anis)) / (hk)
if math.Signbit(bextvector.dot(p.m)) == false {
hoverhk *= -1.
}
//works only with aligned particles with B_ext at the moment
fieldfactor := (1. - 1*hoverhk)
//fmt.Println(gprime*hk*math.Sqrt(delta/math.Pi)*math.Exp(-delta*fieldfactor))
return gprime * hk * math.Sqrt(delta/math.Pi) * math.Exp(-delta*fieldfactor)
}
//calculates the attempt frequency of a particle
func attemptf2(p *particle) float64 {
volume := cube(p.r) * 4 / 3. * math.Pi
hk := 2. * Ku1 / (p.msat * mu0)
gprime := Alpha * gamma0 * mu0 / (1. + (Alpha * Alpha))
delta := Ku1 * volume / (kb * Temp)
bx, by, bz := B_ext(T)
bextvector := vector{bx / mu0, by / mu0, bz / mu0}
hoverhk := math.Abs(bextvector.dot(p.u_anis)) / hk
if math.Signbit(bextvector.dot(p.m)) {
hoverhk *= -1.
}
postpostfactor := 1. / (math.Erf(math.Sqrt(delta) * (1 - hoverhk)))
return gprime * hk / math.Sqrt(delta*math.Pi) * postpostfactor * math.Exp(-delta)
}
//calculates the attempt frequency of a particle
func attemptf3(p *particle) float64 {
volume := cube(p.r) * 4 / 3. * math.Pi
hk := 2. * Ku1 / (p.msat * mu0)
gprime := Alpha * gamma0 * mu0 / (1. + (Alpha * Alpha))
delta := Ku1 * volume / (kb * Temp)
bx, by, bz := B_ext(T)
bextvector := vector{bx / mu0, by / mu0, bz / mu0}
hoverhk := math.Abs(bextvector.dot(p.u_anis)) / hk
if math.Signbit(bextvector.dot(p.m)) {
hoverhk *= -1.
}
postpostfactor := 1. / (math.Log(2. / (1 + hoverhk)))
return gprime * hk / (4 * delta) * postpostfactor
}
//calculates the attempt frequency of a particle
func attemptf0(p *particle) float64 {
volume := cube(p.r) * 4. / 3. * math.Pi
delta := Ku1 * volume / (kb * Temp)
return 1. / Tau0 * math.Exp(-delta)
}
//calculates the next switching time
func setswitchtime(p *particle) {
prob := rng.Float64()
//TODO choose based on the barrier??? see which one corresponds when with brownian noise
nextflip := (-1. / attemptf0(p)) * math.Log((1. - prob))
//nextflip := (-1. / attemptf1(p)) * math.Log((1. - prob))
//nextflip := (-1. / attemptf2(p)) * math.Log(1.-prob)
//nextflip := (-1. / attemptf3(p)) * math.Log(1.-prob)
p.flip = nextflip + T
}
//checks if it's time to switch and if so, switch and calculate next switchtime
func checkswitch(p *particle) {
if T > p.flip {
switchp(p)
setswitchtime(p)
}
}
//switches the magnetisation of a particle
func switchp(p *particle) {
p.m = p.m.times(-1.)
}
//resets all switchtimes
func resetswitchtimes(Lijst []*particle) {
for _, p := range Lijst {
setswitchtime(p)
}
}
//checks switch for all particles
func checkallswitch(Lijst []*particle) {
for _, p := range Lijst {
checkswitch(p)
}
}