mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-21 00:51:21 +00:00
JSON3
This commit is contained in:
parent
4c4c9b5993
commit
7a1268a4ea
5 changed files with 35 additions and 12 deletions
|
@ -2,10 +2,11 @@ using Pkg
|
|||
Pkg.activate(".")
|
||||
|
||||
using Random, Distributions
|
||||
using JLD2
|
||||
using ProgressMeter
|
||||
using GLMakie, ColorSchemes, LaTeXStrings
|
||||
using StaticArrays
|
||||
using JLD2: JLD2
|
||||
using JSON3: JSON3
|
||||
|
||||
import Dates: now, CompoundPeriod, canonicalize
|
||||
import Base: push!, run, iterate
|
||||
|
|
|
@ -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...")
|
||||
|
||||
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}")
|
||||
|
||||
animation_path = "exports/$name_part.mkv"
|
||||
animation_path = "exports/$filename.mkv"
|
||||
|
||||
record(fig, animation_path; framerate=framerate) do io
|
||||
circles = Observable(Vector{Circle}(undef, args.N))
|
||||
|
|
20
src/data.jl
20
src/data.jl
|
@ -30,13 +30,25 @@ function save_frame!(sol, frame, t, particles)
|
|||
return frame
|
||||
end
|
||||
|
||||
function save_data_jld(sol, args, name_part)
|
||||
function save_data_jld(sol, args, filename)
|
||||
println("Saving data...")
|
||||
|
||||
data_path = "exports/$name_part.jld2"
|
||||
jldsave(data_path; sol, args, name_part)
|
||||
path = "exports/$filename.jld2"
|
||||
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
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function pair_correlation(frame=0, dr=0.1)
|
||||
sol, args, name_part = run(;
|
||||
sol, args, filename = run(;
|
||||
N=1000,
|
||||
T=1.0,
|
||||
v=20.0,
|
||||
|
|
18
src/run.jl
18
src/run.jl
|
@ -56,15 +56,25 @@ function run(;
|
|||
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
|
||||
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
|
||||
|
||||
if framerate > 0
|
||||
animate(sol, args, name_part; framerate=framerate)
|
||||
animate(sol, args, filename; framerate=framerate)
|
||||
|
||||
save_variables_to_JSON = true
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue