-
Notifications
You must be signed in to change notification settings - Fork 0
/
temperature.go
79 lines (69 loc) · 2.24 KB
/
temperature.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/barnex/cuda5/curand"
"github.com/mumax/3/cuda"
"github.com/mumax/3/data"
"github.com/mumax/3/mag"
"github.com/mumax/3/util"
)
var (
Temp ScalarParam
temp_red derivedParam
B_therm vAdder
E_therm *GetScalar
Edens_therm sAdder
generator curand.Generator
thermSeed int64 = 0
)
func init() {
Temp.init("Temp", "K", "Temperature", []derived{&temp_red})
DeclFunc("ThermSeed", ThermSeed, "Set a random seed for thermal noise")
B_therm.init("B_therm", "T", "Thermal field", AddThermalField)
E_therm = NewGetScalar("E_therm", "J", "Thermal energy", GetThermalEnergy)
Edens_therm.init("Edens_therm", "J/m3", "Thermal energy density", addEdens(&B_therm, -1))
registerEnergy(GetThermalEnergy, Edens_therm.AddTo)
// reduced temperature = (alpha * T) / (mu0 * Msat)
temp_red.init(1, []updater{&Alpha, &Temp, &Msat}, func(p *derivedParam) {
dst := temp_red.cpu_buf
alpha := Alpha.cpuLUT()
T := Temp.cpuLUT()
Ms := Msat.cpuLUT()
for i := 0; i < NREGION; i++ { // not regions.MaxReg!
dst[0][i] = safediv(alpha[0][i]*T[0][i], mag.Mu0*Ms[0][i])
}
})
}
func AddThermalField(dst *data.Slice) {
if Temp.isZero() {
return
}
/* With higher-order solvers, the thermal field should remain constant during the step,
requiring us to save it. While possible, it hardly is worth the effort given the fact
that the time step will be extremely small anyway.
*/
util.AssertMsg(solvertype == 1, "Temperature can only be used with Euler solver (solvertype 1)")
if generator == 0 {
generator = curand.CreateGenerator(curand.PSEUDO_DEFAULT)
generator.SetSeed(thermSeed)
}
N := Mesh().NCell()
kmu0_VgammaDt := mag.Mu0 * mag.Kb / (mag.Gamma0 * cellVolume() * Solver.Dt_si)
noise := cuda.Buffer(1, Mesh().Size())
defer cuda.Recycle(noise)
const mean = 0
const stddev = 1
for i := 0; i < 3; i++ {
generator.GenerateNormal(uintptr(noise.DevPtr(0)), int64(N), mean, stddev)
cuda.AddTemperature(dst.Comp(i), noise, temp_red.gpuLUT1(), kmu0_VgammaDt, regions.Gpu())
}
}
func GetThermalEnergy() float64 {
return -cellVolume() * dot(&M_full, &B_therm)
}
// Seeds the thermal noise generator
func ThermSeed(seed int) {
thermSeed = int64(seed)
if generator != 0 {
generator.SetSeed(thermSeed)
}
}