2021-12-02 22:13:54 +00:00
|
|
|
using StaticArrays: SVector
|
|
|
|
using JLD2: JLD2
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
struct Bundle
|
2021-11-10 14:41:04 +00:00
|
|
|
t::Vector{Float64}
|
2021-12-07 04:52:10 +00:00
|
|
|
c::Matrix{SVector{2,Float64}}
|
2021-11-10 14:41:04 +00:00
|
|
|
φ::Matrix{Float64}
|
2021-11-26 05:55:27 +00:00
|
|
|
end
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
function Bundle(n_particles::Int64, n_snapshots::Int64)
|
2021-11-26 05:55:27 +00:00
|
|
|
return Bundle(
|
2021-12-07 04:52:10 +00:00
|
|
|
Vector{Float64}(undef, n_snapshots),
|
2021-12-10 02:16:18 +00:00
|
|
|
Matrix{SVector{2,Float64}}(undef, (n_particles, n_snapshots)),
|
|
|
|
Matrix{Float64}(undef, (n_particles, n_snapshots)),
|
2021-11-26 05:55:27 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
function first_n_snapshots(bundle::Bundle, n::Int64)
|
|
|
|
return Bundle(bundle.t[1:n], bundle.c[:, 1:n], bundle.φ[:, 1:n])
|
2021-11-10 14:41:04 +00:00
|
|
|
end
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
function save_snapshot!(
|
|
|
|
bundle::Bundle, n_snapshot::Int64, t::Float64, particles::Vector{Particle}
|
|
|
|
)
|
|
|
|
bundle.t[n_snapshot] = t
|
2021-11-10 23:24:07 +00:00
|
|
|
|
|
|
|
@simd for p in particles
|
2021-12-07 04:52:10 +00:00
|
|
|
bundle.c[p.id, n_snapshot] = p.c
|
2021-11-10 23:24:07 +00:00
|
|
|
|
2021-12-07 04:52:10 +00:00
|
|
|
bundle.φ[p.id, n_snapshot] = p.φ
|
2021-11-10 23:24:07 +00:00
|
|
|
end
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
return nothing
|
2021-11-10 23:24:07 +00:00
|
|
|
end
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
function set_sim_state(dir::String, n_bundles::Int64, T::Float64)
|
|
|
|
open("$dir/sim_state.json", "w") do f
|
2021-11-26 05:55:27 +00:00
|
|
|
JSON3.write(f, Dict("n_bundles" => n_bundles, "T" => round(T; digits=3)))
|
|
|
|
end
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
2021-11-17 19:03:07 +00:00
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
function save_bundle(dir::String, bundle::Bundle, n::Int64, T::Float64)
|
2021-11-26 13:50:47 +00:00
|
|
|
bundles_dir = "$dir/bundles"
|
|
|
|
mkpath(bundles_dir)
|
2021-11-17 19:03:07 +00:00
|
|
|
|
2021-11-26 13:50:47 +00:00
|
|
|
JLD2.save_object("$bundles_dir/bundle_$n.jld2", bundle)
|
2021-11-17 19:03:07 +00:00
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
set_sim_state(dir, n, T)
|
2021-11-17 19:03:07 +00:00
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|