2021-12-02 22:13:54 +00:00
|
|
|
using StaticArrays: SVector
|
|
|
|
using LoopVectorization: @turbo
|
|
|
|
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-11-26 05:55:27 +00:00
|
|
|
c::Matrix{Vector{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-11-26 05:55:27 +00:00
|
|
|
function Bundle(N::Int64, n_snapshots::Int64)
|
|
|
|
return Bundle(
|
|
|
|
zeros(n_snapshots),
|
|
|
|
[zeros(2) for i in 1:N, j in 1:n_snapshots],
|
|
|
|
zeros(N, n_snapshots),
|
|
|
|
)
|
|
|
|
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
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
bundle_c = bundle.c
|
|
|
|
bundle_φ = bundle.φ
|
2021-11-10 23:24:07 +00:00
|
|
|
|
|
|
|
@simd for p in particles
|
|
|
|
p_id = p.id
|
2021-11-26 05:55:27 +00:00
|
|
|
p_c = p.c
|
2021-11-10 23:24:07 +00:00
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
bundle_c_id = bundle_c[p_id, n_snapshot]
|
2021-11-17 18:47:05 +00:00
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
@turbo for j in 1:2
|
|
|
|
bundle_c_id[j] = p_c[j]
|
2021-11-10 23:24:07 +00:00
|
|
|
end
|
|
|
|
|
2021-11-26 05:55:27 +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-11-26 05:55:27 +00:00
|
|
|
function set_status(dir::String, n_bundles::Int64, T::Float64)
|
|
|
|
open("$dir/status.json", "w") do f
|
|
|
|
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-11-26 05:55:27 +00:00
|
|
|
set_status(dir, n, T)
|
2021-11-17 19:03:07 +00:00
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|