-
Notifications
You must be signed in to change notification settings - Fork 0
/
energy.go
41 lines (35 loc) · 773 Bytes
/
energy.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
package engine
import "github.com/mumax/3/cuda"
var (
energyTerms []func() float64 // registers total energy terms
E_total = NewGetScalar("E_total", "J", "Total energy", GetTotalEnergy)
)
// add energy term to global energy
func registerEnergy(term func() float64) {
energyTerms = append(energyTerms, term)
}
// Returns the total energy in J.
func GetTotalEnergy() float64 {
E := 0.
for _, f := range energyTerms {
E += f()
}
return E
}
// vector dot product
func dot(a, b Getter) float64 {
A, recyA := a.Get()
if recyA {
defer cuda.Recycle(A)
}
B, recyB := b.Get()
if recyB {
defer cuda.Recycle(B)
}
return float64(cuda.Dot(A, B))
}
// volume of one cell in m3
func cellVolume() float64 {
c := Mesh().CellSize()
return c[0] * c[1] * c[2]
}