1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-11-08 22:21:08 +00:00
This commit is contained in:
MoBit 2021-11-17 20:03:07 +01:00
parent 4c4c9b5993
commit 7a1268a4ea
5 changed files with 35 additions and 12 deletions

View file

@ -2,10 +2,11 @@ using Pkg
Pkg.activate(".") Pkg.activate(".")
using Random, Distributions using Random, Distributions
using JLD2
using ProgressMeter using ProgressMeter
using GLMakie, ColorSchemes, LaTeXStrings using GLMakie, ColorSchemes, LaTeXStrings
using StaticArrays using StaticArrays
using JLD2: JLD2
using JSON3: JSON3
import Dates: now, CompoundPeriod, canonicalize import Dates: now, CompoundPeriod, canonicalize
import Base: push!, run, iterate import Base: push!, run, iterate

View file

@ -1,4 +1,4 @@
function animate(sol::Solution, args, name_part::String; framerate::Int64=10) function animate(sol::Solution, args, filename::String; framerate::Int64=10)
println("Generating animation...") println("Generating animation...")
set_theme!(theme_black()) set_theme!(theme_black())
@ -16,7 +16,7 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
Colorbar(fig[1, 2]; limits=(0, 2), colormap=color_scheme, label=L"\frac{\varphi}{\pi}") Colorbar(fig[1, 2]; limits=(0, 2), colormap=color_scheme, label=L"\frac{\varphi}{\pi}")
animation_path = "exports/$name_part.mkv" animation_path = "exports/$filename.mkv"
record(fig, animation_path; framerate=framerate) do io record(fig, animation_path; framerate=framerate) do io
circles = Observable(Vector{Circle}(undef, args.N)) circles = Observable(Vector{Circle}(undef, args.N))

View file

@ -30,13 +30,25 @@ function save_frame!(sol, frame, t, particles)
return frame return frame
end end
function save_data_jld(sol, args, name_part) function save_data_jld(sol, args, filename)
println("Saving data...") println("Saving data...")
data_path = "exports/$name_part.jld2" path = "exports/$filename.jld2"
jldsave(data_path; sol, args, name_part) JLD2.jldsave(path; sol, args, filename)
println("Data saved to $data_path.") println("Data saved to $path.")
return nothing
end
function save_JSON(filename::String, kwargs...)
path = "exports/$filename.json"
open(path, "w") do io
JSON3.pretty(io, kwargs)
end
println("Variables saved to $path.")
return nothing return nothing
end end

View file

@ -1,5 +1,5 @@
function pair_correlation(frame=0, dr=0.1) function pair_correlation(frame=0, dr=0.1)
sol, args, name_part = run(; sol, args, filename = run(;
N=1000, N=1000,
T=1.0, T=1.0,
v=20.0, v=20.0,

View file

@ -56,15 +56,25 @@ function run(;
args, δt, T, n_steps_before_verlet_list_update, n_steps_before_save args, δt, T, n_steps_before_verlet_list_update, n_steps_before_save
) )
name_part = "$(end_time)_T=$(T)_N=$(N)_v=$(v)" filename = "$(end_time)_T=$(T)_N=$(N)_v=$(v)"
save_variables_to_JSON = false
if save_data if save_data
save_data_jld(name_part, sol, args, n_steps_before_verlet_list_update) save_data_jld(filename, sol, args, n_steps_before_verlet_list_update)
save_variables_to_JSON = true
end end
if framerate > 0 if framerate > 0
animate(sol, args, name_part; framerate=framerate) animate(sol, args, filename; framerate=framerate)
save_variables_to_JSON = true
end end
return (; sol, args, name_part) if save_variables_to_JSON
save_JSON(filename, args, n_steps_before_save)
end
return (; sol, args, filename)
end end