-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (35 loc) · 958 Bytes
/
main.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
// +build ignore
package main
import (
"math/rand"
"github.com/davidkleiven/gopf/pf"
)
func main() {
nx := 128
ny := 128
dt := 0.1
domainSize := []int{nx, ny}
model := pf.NewModel()
conc := pf.NewField("conc", nx*ny, nil)
// Initialize with random concentration
r := rand.New(rand.NewSource(0))
for i := range conc.Data {
conc.Data[i] = complex(2.0*r.Float64()-1.0, 0.0)
}
// Add constants
gamma := pf.NewScalar("gamma", complex(2.0, 0.0)) // Gradient coefficient
m1 := pf.NewScalar("m1", complex(-1.0, 0.0)) // -1.0
model.AddScalar(gamma)
model.AddScalar(m1)
// Initialize the center
model.AddField(conc)
model.AddEquation("dconc/dt = LAP conc^3 + m1*LAP conc + m1*gamma*LAP^2 conc")
// Initialize solver
solver := pf.NewSolver(&model, domainSize, dt)
model.Summarize()
// Initialize uint8 IO
out := pf.NewUint8IO("cahnHilliard2D")
solver.AddCallback(out.SaveFields)
// Solve the equation
solver.Solve(10, 10)
}