mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-21 00:51:21 +00:00
Bundles animation
This commit is contained in:
parent
8e1d274473
commit
59323d49cd
5 changed files with 159 additions and 93 deletions
|
@ -1,5 +1,4 @@
|
|||
using Luxor
|
||||
using StaticArrays
|
||||
|
||||
using ReCo: restrict_coordinate
|
||||
|
||||
|
@ -59,7 +58,7 @@ line(Point(-L, 0), Point(L, 0), :stroke)
|
|||
|
||||
setcolor("red")
|
||||
setline(0.5)
|
||||
for x in SVector(-L, L)
|
||||
for x in (-L, L)
|
||||
line(Point(x, 0.05 * L), Point(x, -0.05 * L), :stroke)
|
||||
end
|
||||
|
||||
|
@ -67,7 +66,7 @@ setcolor("cyan3")
|
|||
line(Point(0, 0.05 * L), Point(0, -0.05 * L), :stroke)
|
||||
|
||||
setcolor("blue")
|
||||
for p in SVector(A, B)
|
||||
for p in (A, B)
|
||||
circle(Point(p, 0), pr, :fill)
|
||||
end
|
||||
|
||||
|
@ -111,7 +110,7 @@ setcolor("cyan3")
|
|||
line(Point(-1.05 * R, 0), Point(-0.95 * R, 0), :stroke)
|
||||
|
||||
setcolor("blue")
|
||||
for pp in SVector(Ap, Bp)
|
||||
for pp in (Ap, Bp)
|
||||
circle(R * pp, pr, :fill)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,10 +4,9 @@ export init_sim, run_sim
|
|||
|
||||
include("PreVector.jl")
|
||||
include("Particle.jl")
|
||||
include("data.jl")
|
||||
include("setup.jl")
|
||||
include("simulation.jl")
|
||||
include("data.jl")
|
||||
# includet("animation.jl")
|
||||
include("run.jl")
|
||||
|
||||
end # module
|
236
src/animation.jl
236
src/animation.jl
|
@ -1,121 +1,187 @@
|
|||
using GLMakie, ColorSchemes
|
||||
module ReCoAnimation
|
||||
|
||||
export animate
|
||||
|
||||
using GLMakie
|
||||
using ColorSchemes: cyclic_mrybm_35_75_c68_n256_s25
|
||||
using LaTeXStrings: @L_str
|
||||
using JSON3: JSON3
|
||||
using JLD2: JLD2
|
||||
using ProgressMeter: @showprogress
|
||||
|
||||
function animate(dir::String; framerate=0)
|
||||
println("Generating animation...")
|
||||
using ReCo: Bundle
|
||||
|
||||
function animate_bundle!(args)
|
||||
bundle_t = args.bundle.t
|
||||
bundle_c = args.bundle.c
|
||||
bundle_φ = args.bundle.φ
|
||||
|
||||
π2 = 2 * π
|
||||
|
||||
for frame in 1:length(bundle_t)
|
||||
@simd for i in 1:(args.N)
|
||||
args.circles[][i] = Circle(Point2(bundle_c[i, frame]), args.particle_radius)
|
||||
|
||||
color = get(args.color_scheme, rem2pi(bundle_φ[i, frame], RoundDown) / π2)
|
||||
args.colors[][i] = RGBAf(color)
|
||||
|
||||
if args.debug
|
||||
args.interaction_circles[][i] = Circle(
|
||||
Point2(bundle_c[i, frame]), args.interaction_r
|
||||
)
|
||||
args.skin_circles[][i] = Circle(Point2(bundle_c[i, frame]), args.skin_r)
|
||||
|
||||
args.interaction_colors[][i] = RGBAf(color, 0.08)
|
||||
args.skin_colors[][i] = RGBAf(color, 0.04)
|
||||
end
|
||||
end
|
||||
|
||||
if args.n_bundle == 1
|
||||
poly!(args.ax, args.circles; color=args.colors)
|
||||
|
||||
if args.debug
|
||||
poly!(args.ax, args.interaction_circles; color=args.interaction_colors)
|
||||
poly!(args.ax, args.skin_circles; color=args.skin_colors)
|
||||
end
|
||||
|
||||
println("Recording started!")
|
||||
else
|
||||
if args.debug
|
||||
@simd for i in 1:(args.N)
|
||||
first_ind = 2 * i - 1
|
||||
second_ind = 2 * i
|
||||
frame_min_1 = frame - 1
|
||||
|
||||
args.segments_x[][first_ind] = bundle_c[i, frame_min_1][1]
|
||||
args.segments_x[][second_ind] = bundle_c[i, frame][1]
|
||||
|
||||
args.segments_y[][first_ind] = bundle_c[i, frame_min_1][2]
|
||||
args.segments_y[][second_ind] = bundle_c[i, frame][2]
|
||||
end
|
||||
|
||||
if frame == 2
|
||||
linesegments!(
|
||||
args.ax, args.segments_x, args.segments_y; color=args.colors
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
notify(args.circles)
|
||||
notify(args.colors)
|
||||
|
||||
if args.debug
|
||||
notify(args.interaction_circles)
|
||||
notify(args.interaction_colors)
|
||||
|
||||
notify(args.skin_circles)
|
||||
notify(args.skin_colors)
|
||||
|
||||
notify(args.segments_x)
|
||||
notify(args.segments_y)
|
||||
end
|
||||
end
|
||||
|
||||
args.ax.title = "t = $(round(bundle_t[frame], digits=3))"
|
||||
|
||||
recordframe!(args.io)
|
||||
end
|
||||
|
||||
return nothing
|
||||
end
|
||||
|
||||
function animate_after_loading(dir, animation_path, sim_consts, framerate, debug)
|
||||
set_theme!(theme_black())
|
||||
|
||||
fig = Figure(; resolution=(1080, 1080))
|
||||
ax = Axis(
|
||||
fig[1, 1];
|
||||
limits=(-variables.l, variables.l, -variables.l, variables.l),
|
||||
limits=(-sim_consts.l, sim_consts.l, -sim_consts.l, sim_consts.l),
|
||||
aspect=AxisAspect(1),
|
||||
xlabel=L"x",
|
||||
ylabel=L"y",
|
||||
)
|
||||
|
||||
color_scheme = ColorSchemes.cyclic_mrybm_35_75_c68_n256_s25
|
||||
color_scheme = cyclic_mrybm_35_75_c68_n256_s25
|
||||
|
||||
Colorbar(fig[1, 2]; limits=(0, 2), colormap=color_scheme, label=L"\frac{\varphi}{\pi}")
|
||||
|
||||
animation_path = "$directory/animation.mkv"
|
||||
N = sim_consts.N
|
||||
|
||||
record_framerate = 0
|
||||
if framerate > 0
|
||||
record_framerate = framerate
|
||||
else
|
||||
record_framerate = variables.framerate
|
||||
end
|
||||
record(fig, animation_path; framerate=framerate) do io
|
||||
circles = Observable(Vector{Circle}(undef, N))
|
||||
colors = Observable(Vector{RGBAf}(undef, N))
|
||||
|
||||
record(fig, animation_path; framerate=record_framerate) do io
|
||||
circles = Observable(Vector{Circle}(undef, variables.N))
|
||||
colors = Observable(Vector{RGBAf}(undef, variables.N))
|
||||
segments_x =
|
||||
segments_y =
|
||||
interaction_circles =
|
||||
skin_circles = interaction_colors = skin_colors = nothing
|
||||
|
||||
if variables.debug
|
||||
segments_x = Observable(zeros(2 * variables.N))
|
||||
segments_y = Observable(zeros(2 * variables.N))
|
||||
if debug
|
||||
segments_x = Observable(zeros(2 * N))
|
||||
segments_y = Observable(zeros(2 * N))
|
||||
|
||||
interaction_circles = Observable(Vector{Circle}(undef, variables.N))
|
||||
skin_circles = Observable(Vector{Circle}(undef, variables.N))
|
||||
interaction_circles = Observable(Vector{Circle}(undef, N))
|
||||
skin_circles = Observable(Vector{Circle}(undef, N))
|
||||
|
||||
interaction_colors = Observable(Vector{RGBAf}(undef, variables.N))
|
||||
skin_colors = Observable(Vector{RGBAf}(undef, variables.N))
|
||||
interaction_colors = Observable(Vector{RGBAf}(undef, N))
|
||||
skin_colors = Observable(Vector{RGBAf}(undef, N))
|
||||
end
|
||||
|
||||
π2 = 2 * π
|
||||
particle_radius = variables.particle_diameter / 2
|
||||
particle_radius = sim_consts.particle_diameter / 2
|
||||
interaction_r = sim_consts.interaction_r
|
||||
|
||||
@showprogress 0.6 for frame in 1:(variables.n_snapshots)
|
||||
@simd for i in 1:(variables.N)
|
||||
circles[][i] = Circle(Point2(sol.center[i, frame]), particle_radius)
|
||||
bundle_paths = readdir("$dir/bundles"; join=true)
|
||||
skin_r = 0.0
|
||||
|
||||
color = get(color_scheme, rem2pi(sol.φ[i, frame], RoundDown) / π2)
|
||||
colors[][i] = RGBAf(color)
|
||||
@showprogress 1 for (n_bundle, bundle_path) in enumerate(bundle_paths)
|
||||
bundle::Bundle = JLD2.load_object(bundle_path)
|
||||
|
||||
if variables.debug
|
||||
interaction_circles[][i] = Circle(
|
||||
Point2(sol.center[i, frame]), variables.interaction_r
|
||||
)
|
||||
skin_circles[][i] = Circle(
|
||||
Point2(sol.center[i, frame]), variables.skin_r
|
||||
)
|
||||
|
||||
interaction_colors[][i] = RGBAf(color, 0.08)
|
||||
skin_colors[][i] = RGBAf(color, 0.04)
|
||||
end
|
||||
run_vars_file = "$dir/runs/run_vars_$n_bundle.json"
|
||||
if debug && isfile(run_vars_file)
|
||||
skin_r::Float64 = JSON3.read(read(run_vars_file, String)).skin_r
|
||||
end
|
||||
|
||||
if frame > 1
|
||||
if variables.debug
|
||||
@simd for i in 1:(variables.N)
|
||||
first_ind = 2 * i - 1
|
||||
second_ind = 2 * i
|
||||
frame_min_1 = frame - 1
|
||||
args = (;
|
||||
io,
|
||||
ax,
|
||||
bundle,
|
||||
sim_consts,
|
||||
debug,
|
||||
circles,
|
||||
colors,
|
||||
segments_x,
|
||||
segments_y,
|
||||
interaction_circles,
|
||||
skin_circles,
|
||||
interaction_colors,
|
||||
skin_colors,
|
||||
particle_radius,
|
||||
skin_r,
|
||||
N,
|
||||
interaction_r,
|
||||
color_scheme,
|
||||
n_bundle,
|
||||
)
|
||||
|
||||
segments_x[][first_ind] = sol.center[i, frame_min_1][1]
|
||||
segments_x[][second_ind] = sol.center[i, frame][1]
|
||||
|
||||
segments_y[][first_ind] = sol.center[i, frame_min_1][2]
|
||||
segments_y[][second_ind] = sol.center[i, frame][2]
|
||||
end
|
||||
|
||||
if frame == 2
|
||||
linesegments!(ax, segments_x, segments_y; color=colors)
|
||||
end
|
||||
end
|
||||
else # First frame
|
||||
poly!(ax, circles; color=colors)
|
||||
|
||||
if variables.debug
|
||||
poly!(ax, interaction_circles; color=interaction_colors)
|
||||
poly!(ax, skin_circles; color=skin_colors)
|
||||
end
|
||||
|
||||
println("Recording started!")
|
||||
end
|
||||
|
||||
notify(circles)
|
||||
notify(colors)
|
||||
|
||||
if variables.debug
|
||||
notify(interaction_circles)
|
||||
notify(interaction_colors)
|
||||
|
||||
notify(skin_circles)
|
||||
notify(skin_colors)
|
||||
|
||||
notify(segments_x)
|
||||
notify(segments_y)
|
||||
end
|
||||
|
||||
ax.title = "t = $(round(sol.t[frame], digits=3))"
|
||||
|
||||
recordframe!(io)
|
||||
animate_bundle!(args)
|
||||
end
|
||||
end
|
||||
|
||||
return nothing
|
||||
end
|
||||
|
||||
function animate(dir::String; framerate::Int64=1, debug::Bool=false)
|
||||
println("Generating animation...")
|
||||
|
||||
sim_consts = JSON3.read(read("$dir/sim_consts.json", String))
|
||||
|
||||
animation_path = "$dir/animation.mkv"
|
||||
|
||||
animate_after_loading(dir, animation_path, sim_consts, framerate, debug)
|
||||
|
||||
println("Animation done and saved to $animation_path.")
|
||||
|
||||
return nothing
|
||||
end
|
||||
|
||||
end # module
|
|
@ -87,10 +87,13 @@ function run_sim(
|
|||
|
||||
next_bundle = n_bundles + 1
|
||||
|
||||
runs_dir = "$dir/runs"
|
||||
mkpath(runs_dir)
|
||||
|
||||
if n_bundle_snapshots > 0
|
||||
save_data = true
|
||||
|
||||
open("$bundles_dir/run_vars_$next_bundle.json", "w") do f
|
||||
open("$runs_dir/run_vars_$next_bundle.json", "w") do f
|
||||
JSON3.pretty(f, run_vars)
|
||||
end
|
||||
else
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using Distributions: Uniform
|
||||
using Dates: now
|
||||
using JSON3: JSON3
|
||||
using ReCo: Bundle, Particle
|
||||
|
||||
function initial_particle_grid_pos(i, j; grid_box_width, l)
|
||||
term = -0.5 * grid_box_width - l
|
||||
|
|
Loading…
Reference in a new issue