From fded0888cf3cab826b9281426846b248bb8c8403 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sun, 23 Jan 2022 03:04:10 +0100 Subject: [PATCH] activate! GLMakie --- src/Animation.jl | 23 ++--------------------- src/ReCo.jl | 2 +- src/data.jl | 20 ++++++++++++++++++++ src/run.jl | 9 +++++---- src/simulation.jl | 10 +++++++--- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/Animation.jl b/src/Animation.jl index 63764d5..a041ad4 100644 --- a/src/Animation.jl +++ b/src/Animation.jl @@ -115,24 +115,6 @@ function animate_bundle!(args, sim_consts::ReCo.SimConsts) return nothing end -function sort_bundle_paths(bundle_paths::Vector{String}) - n_bundles = length(bundle_paths) - - bundle_nums = Vector{Int64}(undef, n_bundles) - - extension_length = 5 # == length(".jld2") - - for i in 1:n_bundles - bundle_path = bundle_paths[i] - bundle_num_string = bundle_path[(findfirst("bundle_", bundle_path).stop + 1):(end - extension_length)] - bundle_nums[i] = parse(Int64, bundle_num_string) - end - - sort_perm = sortperm(bundle_nums) - - return bundle_paths[sort_perm] -end - function animate_with_sim_consts( dir::String, sim_consts::ReCo.SimConsts, @@ -142,6 +124,7 @@ function animate_with_sim_consts( show_skin_circle::Bool, show_frame_diff::Bool, ) + GLMakie.activate!() set_theme!(theme_black()) fig = Figure(; resolution=(1080, 1080)) @@ -199,9 +182,7 @@ function animate_with_sim_consts( segments_y = Observable(zeros(2 * n_particles)) end - bundle_paths = readdir("$dir/bundles"; join=true, sort=false) - - bundle_paths = sort_bundle_paths(bundle_paths) + bundle_paths = ReCo.sorted_bundle_paths(dir) @showprogress 1 for (n_bundle, bundle_path) in enumerate(bundle_paths) bundle::ReCo.Bundle = JLD2.load_object(bundle_path) diff --git a/src/ReCo.jl b/src/ReCo.jl index 93954a8..78f67c4 100644 --- a/src/ReCo.jl +++ b/src/ReCo.jl @@ -6,7 +6,7 @@ using StaticArrays: SVector using JLD2: JLD2 using Distributions: Uniform, Normal using ProgressMeter: @showprogress -using CellListMap: Box, CellList, map_pairwise!, UpdateCellList! +using CellListMap: CellListMap using Random: Random using Dates: Dates diff --git a/src/data.jl b/src/data.jl index 80af7c2..9295b4b 100644 --- a/src/data.jl +++ b/src/data.jl @@ -76,4 +76,24 @@ function save_bundle(dir::String, bundle::Bundle, n_bundle::Int64, T::Float64) JLD2.save_object("$dir/sim_state.jld2", SimState(n_bundle, round(T; digits=3))) return nothing +end + +function sorted_bundle_paths(dir::String) + bundle_paths = readdir("$dir/bundles"; join=true, sort=false) + + n_bundles = length(bundle_paths) + + bundle_nums = Vector{Int64}(undef, n_bundles) + + extension_length = 5 # == length(".jld2") + + for i in 1:n_bundles + bundle_path = bundle_paths[i] + bundle_num_string = bundle_path[(findfirst("bundle_", bundle_path).stop + 1):(end - extension_length)] + bundle_nums[i] = parse(Int64, bundle_num_string) + end + + sort_perm = sortperm(bundle_nums) + + return bundle_paths[sort_perm] end \ No newline at end of file diff --git a/src/run.jl b/src/run.jl index d349990..541fa1a 100644 --- a/src/run.jl +++ b/src/run.jl @@ -2,6 +2,10 @@ function empty_hook(args...) return nothing end +function gen_cell_list_box(half_box_len::Float64, skin_r::Float64) + return CellListMap.Box(SVector(2 * half_box_len, 2 * half_box_len), skin_r) +end + function run_sim( dir::String; duration::Float64, @@ -97,10 +101,7 @@ function run_sim( ], n_bundle_snapshots=n_bundle_snapshots, bundle=Bundle(sim_consts.n_particles, n_bundle_snapshots), - box=Box( - SVector(2 * sim_consts.half_box_len, 2 * sim_consts.half_box_len), - sim_consts.skin_r, - ), + box=gen_cell_list_box(sim_consts.half_box_len, sim_consts.skin_r), ) simulate!( diff --git a/src/simulation.jl b/src/simulation.jl index 566af66..2b4bb7a 100644 --- a/src/simulation.jl +++ b/src/simulation.jl @@ -21,9 +21,9 @@ function update_verlet_lists!(args, cl) args.particles_c[i] = args.particles[i].c end - cl = UpdateCellList!(args.particles_c, args.box, cl; parallel=false) + cl = CellListMap.UpdateCellList!(args.particles_c, args.box, cl; parallel=false) - map_pairwise!( + CellListMap.map_pairwise!( (x, y, i, j, d2, output) -> push_to_verlet_list!(args.verlet_lists, i, j), nothing, args.box, @@ -102,6 +102,10 @@ function gen_run_additional_hooks(env_helper::RL.EnvHelper, integration_step::In (integration_step == 1) end +function gen_cell_list(particles_c::Vector{SVector{2,Float64}}, box::CellListMap.Box) + return CellListMap.CellList(particles_c, box; parallel=false) +end + function simulate!( args, T0::Float64, @@ -117,7 +121,7 @@ function simulate!( task::Union{Task,Nothing} = nothing - cl = CellList(args.particles_c, args.box; parallel=false) + cl = gen_cell_list(args.particles_c, args.box) cl = update_verlet_lists!(args, cl) first_integration_step = true