@@ -12,3 +12,67 @@ GPUArrays.gpu_call(x, (x,)) do state, l
12
12
l[1 ] = 1f0 ^ 1.0
13
13
return
14
14
end
15
+
16
+
17
+ using ArrayFire
18
+
19
+ ArrayFire. set_backend (AF_BACKEND_OPENCL)
20
+
21
+ using CLArrays
22
+ TY= Float32
23
+ N = 2 ^ 9
24
+ h = TY (2 * π/ N)
25
+ epsn = TY (h * .5 )
26
+ C = TY (2 / epsn)
27
+ tau = TY (epsn * h)
28
+ Tfinal = 50.
29
+
30
+ S (x,y) = exp (- x^ 2 / 0.1f0 )* exp (- y^ 2 / 0.1f0 )
31
+
32
+ # real-space and reciprocal-space grids
33
+ # the real-space grid is just used for plotting!
34
+ X_cpu = convert .(TY,collect (linspace (- pi + h, pi , N)) .* ones (1 ,N))
35
+ X = CLArray (X_cpu);
36
+ k = collect ([0 : N/ 2 ; - N/ 2 + 1 : - 1 ]);
37
+ Â = CLArray (convert .(TY,kron (k.^ 2 , ones (1 ,N)) + kron (ones (N), k' .^ 2 )));
38
+
39
+ # initial condition
40
+ uc = TY (2.0 )* (CLArray {TY} (rand (TY, (N, N)))- TY (0.5 ));
41
+
42
+ # ################################################################
43
+ # ################################################################
44
+ function take_step! (u, t_plot)
45
+ uff = fft (u)
46
+ uff1 = fft (u.^ 3f0 - u)
47
+ @. tmp1 = ((1f0 + C* tau* Â) .* uff .- tau/ epsn * (Â .* uff1)) ./ (1f0 + (epsn* tau)* Â.^ 2f0 + C* tau* Â)
48
+ u .= real .(ifft (tmp1))
49
+ nothing
50
+ end
51
+ function normalise_af! (u,out)
52
+ out .= u- minimum (u)
53
+ out .= out / maximum (out)
54
+ nothing
55
+ end
56
+ # ################################################################
57
+ # ################################################################
58
+
59
+ T_plot = 0.01 ; t_plot = 0.0
60
+
61
+
62
+ up = copy (uc)
63
+ @time for n = 1 : ceil (Tfinal / tau)
64
+ @show n
65
+ take_step! (uc, t_plot)
66
+ t_plot += tau
67
+ # f t_plot >= T_plot
68
+ # # @show n
69
+ # normalise_af!(uc,up)
70
+ # draw_image(window_, up, Ref(ArrayFire.af_cell(0, 0, pointer(""), ArrayFire.AF_COLORMAP_HEAT)))
71
+ # set_title(window_,"N = $N, n = $n, t = $(round(n*tau,4)), max = $(maximum(uc)) - min = $(minimum(uc))")
72
+ # # set_axes_limits_3d(window_,-3.2f0,3.2f0,-3.2f0,-3.2f0,-2.3f0,2.0f0,true,Ref(ArrayFire.af_cell(0, 0, pointer(""), ArrayFire.AF_COLORMAP_HEAT)))
73
+ # show(window_)
74
+ # t_plot = 0.0
75
+ # end
76
+ end
77
+
78
+ print_mem_info (" GPU-Mem apres loop" , 0 )
0 commit comments