Context
I am working on an example of a 3-D visualization of a 2-D glacier flow. Until now the visualization is done for a very small problem (256x256 grid points). Later it should also work for much larger problems.
Problem
The animation becomes slow after redrawing surface about 25 times. Here is an outline of the visualization strategy chosen (B_v is the topography, “the mountain”, and H_v the glacier height for visualization. #(…) denotes omitted code):
First I set up a scene and draw an empty glacier on it (all NaNs)
#(...)
B_v .= B
H_v = fill(NaN, nx, ny)
scene = Makie.surface(X, Y, transpose(B_v), colormap = cgrad(:terrain, scale=:exp10))
glacier = Makie.surface!(scene, X, Y, H_v)
Then, I use record
around the time steps of the simulation and do a redraw of the glacier surface at each time step:
record(scene, "glacierflow.mp4"; framerate = 25) do io
for it = 1:nt
H_v .= H
H_v[H_v.<=0.01] .= NaN
HB_v .= transpose(B_v.+H_v)
Makie.surface!(glacier, X, Y, HB_v, colormap=ice_color, shininess=Float32(2^10), transparency=true, shading=true)
recordframe!(io)
#(...)
end
end
The glacier starts beautifully flowing down the mountain, but after about 25 time steps the glacier flow computations become slow - as if it would do constantly some GC invocations or something. Without the visualisation this slow down is of course not observed. All arrays for the computations are preallocated: there is no allocation happening during the simulation.
When I monitored the memory usage, I saw that it started at about 930 MB before the visulalization and then it increased slowly and at about 25 times steps it had reached about 1 GB. There the memory usage started to oscillate between about 980 MB and 1050 MB.
Note that during the simulation there was still about 5 GBs free memory.
Questions
Do you have any advice on how to mitigate this problem? Should I maybe use other Makie functions for this?
Thanks!!