1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-11-08 22:21:08 +00:00

Fixed animation memory leak

This commit is contained in:
MoBit 2021-11-15 15:17:47 +01:00
parent 5b016f7b68
commit 7bade826e0
3 changed files with 37 additions and 22 deletions

1
.JuliaFormatter.toml Normal file
View file

@ -0,0 +1 @@
style = "blue"

View file

@ -8,7 +8,7 @@ using GLMakie, ColorSchemes, LaTeXStrings
using StaticArrays using StaticArrays
import Dates: now, CompoundPeriod, canonicalize import Dates: now, CompoundPeriod, canonicalize
import Base.push! import Base: push!, run
# Development deps # Development deps
using Revise using Revise

View file

@ -3,7 +3,7 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
set_theme!(theme_black()) set_theme!(theme_black())
fig = Figure(resolution=(1080, 1080)) fig = Figure(; resolution=(1080, 1080))
ax = Axis( ax = Axis(
fig[1, 1]; fig[1, 1];
limits=(-args.l, args.l, -args.l, args.l), limits=(-args.l, args.l, -args.l, args.l),
@ -12,13 +12,18 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
ylabel=L"y", ylabel=L"y",
) )
Colorbar(fig[1, 2]; limits=(0, 2), colormap=ColorSchemes.rainbow, label=L"\frac{\varphi}{\pi}") Colorbar(
fig[1, 2];
limits=(0, 2),
colormap=ColorSchemes.rainbow,
label=L"\frac{\varphi}{\pi}",
)
animation_path = "exports/$name_part.mkv" animation_path = "exports/$name_part.mkv"
record(fig, animation_path; framerate=framerate) do io record(fig, animation_path; framerate=framerate) do io
circles = Vector{Circle}(undef, args.N) circles = Observable(Vector{Circle}(undef, args.N))
colors = Vector{RGBAf}(undef, args.N) colors = Observable(Vector{RGBAf}(undef, args.N))
if args.debug if args.debug
segments_x = zeros(2 * args.N) segments_x = zeros(2 * args.N)
@ -31,15 +36,21 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
skin_colors = Vector{RGBAf}(undef, args.N) skin_colors = Vector{RGBAf}(undef, args.N)
end end
@showprogress 0.5 for frame in 1:args.n_frames @showprogress 0.5 for frame in 1:(args.n_frames)
@simd for i in 1:args.N @simd for i in 1:(args.N)
circles[i] = Circle(Point2(sol.center[i, frame]), args.particle_diameter / 2) circles[][i] = Circle(
Point2(sol.center[i, frame]), args.particle_diameter / 2
)
color = get(ColorSchemes.rainbow, rem2pi(sol.φ[i, frame] / (2 * π), RoundDown)) color = get(
colors[i] = RGBAf(color) ColorSchemes.rainbow, rem2pi(sol.φ[i, frame] / (2 * π), RoundDown)
)
colors[][i] = RGBAf(color)
if args.debug if args.debug
interaction_circles[i] = Circle(Point2(sol.center[i, frame]), args.interaction_r) interaction_circles[i] = Circle(
Point2(sol.center[i, frame]), args.interaction_r
)
skin_circles[i] = Circle(Point2(sol.center[i, frame]), args.skin_r) skin_circles[i] = Circle(Point2(sol.center[i, frame]), args.skin_r)
interaction_colors[i] = RGBAf(color, 0.12) interaction_colors[i] = RGBAf(color, 0.12)
@ -48,8 +59,6 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
end end
if frame > 1 if frame > 1
empty!(ax)
if args.debug if args.debug
@simd for i in 1:(args.N) @simd for i in 1:(args.N)
segments_x[2 * i - 1] = sol.center[i, frame - 1][1] segments_x[2 * i - 1] = sol.center[i, frame - 1][1]
@ -59,18 +68,23 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
segments_y[2 * i] = sol.center[i, frame][2] segments_y[2 * i] = sol.center[i, frame][2]
end end
linesegments!(ax, segments_x, segments_y; color=colors) if frame == 2
linesegments!(ax, segments_x, segments_y; color=colors)
end
end end
else else # First frame
poly!(ax, circles; color=colors)
if args.debug
poly!(ax, interaction_circles; color=interaction_colors)
poly!(ax, skin_circles; color=skin_colors)
end
println("Started recording!") println("Started recording!")
end end
poly!(ax, circles; color=colors) notify(circles)
notify(colors)
if args.debug
poly!(ax, interaction_circles; color=interaction_colors)
poly!(ax, skin_circles; color=skin_colors)
end
ax.title = "t = $(round(sol.t[frame], digits=3))" ax.title = "t = $(round(sol.t[frame], digits=3))"