forked from JLeliaert/vinamax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_eff.go
137 lines (115 loc) · 3.28 KB
/
B_eff.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
package vinamax
import (
"math"
"math/rand"
)
var rng = rand.New(rand.NewSource(0))
//Sums the individual fields to the effective field working on the particle
func (p *particle) b_eff(temp vector) vector {
return p.demagnetising_field.add(p.anis().add(p.zeeman().add(temp)))
}
//Set the randomseed for the temperature
func Setrandomseed(a int64) {
randomseedcalled = true
rng = rand.New(rand.NewSource(a))
}
// factor 4/3pi in "number" because they are spherical
func (p *particle) calculatetemp_prefactor() {
p.temp_prefactor = math.Sqrt((2. * kb * Alpha * Temp) / (gamma0 * p.msat * 4. / 3. * math.Pi * cube(p.r)))
}
func calculatetemp_prefactors(lijst []*particle) {
for i := range lijst {
lijst[i].calculatetemp_prefactor()
}
}
//Calculates the the thermal field B_therm working on a particle
func (p *particle) temp() vector {
B_therm := vector{0., 0., 0.}
if Brown {
if Temp != 0. {
etax := rng.NormFloat64()
etay := rng.NormFloat64()
etaz := rng.NormFloat64()
B_therm = vector{etax, etay, etaz}
B_therm = B_therm.times(p.temp_prefactor / math.Sqrt(Dt))
}
}
return B_therm
}
//Calculates the Zeeman field working on a particle
func (p *particle) zeeman() vector {
x, y, z := B_ext(T)
x2, y2, z2 := B_ext_space(T, p.x, p.y, p.z)
return vector{x + x2, y + y2, z + z2}.add(p.biasfield)
}
//calculates the zeeman energy in a particle
func (p *particle) e_zeeman() float64 {
return -1 * p.msat * p.Volume() * p.m.dot(p.zeeman())
}
//Calculates the anisotropy field working on a particle
func (p *particle) anis() vector {
//2*Ku1*(m.u)*u/p.msat
mdotu := p.m.dot(p.u_anis)
uniax := p.u_anis.times(2. * Ku1 * mdotu / p.msat)
mdotu2 := p.m.dot(p.u2_anis)
uniax2 := p.u2_anis.times(2. * Ku2 * mdotu2 / p.msat)
cubic := vector{0., 0., 0.}
if Kc1 != 0 {
c1m := p.m.dot(p.c1_anis)
c2m := p.m.dot(p.c2_anis)
c3m := p.m.dot(p.c3_anis)
firstterm := p.c1_anis.times(c1m * (c3m*c3m + c2m*c2m))
secondterm := p.c2_anis.times(c2m * (c3m*c3m + c1m*c1m))
thirdterm := p.c3_anis.times(c3m * (c2m*c2m + c1m*c1m))
cubic = firstterm.add(secondterm.add(thirdterm)).times(-2. * Kc1 / p.msat)
}
return uniax.add(cubic).add(uniax2)
}
//calculates the anisotropy energy in a particle
func (p *particle) e_anis() float64 {
return -0.5 * p.msat * p.Volume() * p.m.dot(p.anis())
}
//calculates the thermal energy in a particle
func (p *particle) e_therm() float64 {
return -1 * p.msat * p.Volume() * p.m.dot(p.tempfield)
}
//calculates the demag energy in a particle
func (p *particle) e_demag() float64 {
return -0.5 * p.msat * p.Volume() * p.m.dot(p.demag())
}
//returns total zeeman energy
func E_zeeman() float64 {
sum := 0.
for i := range Universe.lijst {
sum += Universe.lijst[i].e_zeeman()
}
return sum
}
//returns total anisotropy energy
func E_anis() float64 {
sum := 0.
for i := range Universe.lijst {
sum += Universe.lijst[i].e_anis()
}
return sum
}
//returns total demag energy
func E_demag() float64 {
sum := 0.
for i := range Universe.lijst {
sum += Universe.lijst[i].e_demag()
}
return sum
}
//returns total thermal energy
func E_therm() float64 {
sum := 0.
for i := range Universe.lijst {
sum += Universe.lijst[i].e_therm()
}
return sum
}
//returns total energy in the simulation
func E_total() float64 {
return E_demag() + E_zeeman() + E_anis() + E_therm()
}