2022-01-21 22:17:15 +00:00
|
|
|
|
struct SimConsts
|
|
|
|
|
n_particles::Int64
|
|
|
|
|
v₀::Float64
|
|
|
|
|
δt::Float64
|
|
|
|
|
packing_ratio::Float64
|
2022-01-23 15:14:37 +00:00
|
|
|
|
μₜ::Float64
|
2022-01-21 22:17:15 +00:00
|
|
|
|
Dₜ::Float64
|
|
|
|
|
particle_radius::Float64
|
|
|
|
|
Dᵣ::Float64
|
|
|
|
|
σ::Float64
|
|
|
|
|
ϵ::Float64
|
|
|
|
|
interaction_r::Float64
|
|
|
|
|
skin_r::Float64
|
|
|
|
|
n_steps_before_verlet_list_update::Int64
|
|
|
|
|
grid_n::Int64
|
|
|
|
|
half_box_len::Float64
|
|
|
|
|
grid_box_width::Float64
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
struct RunParams
|
|
|
|
|
duration::Float64
|
|
|
|
|
snapshot_at::Float64
|
|
|
|
|
seed::Int64
|
|
|
|
|
n_bundle_snapshots::Int64
|
|
|
|
|
integration_steps::Int64
|
|
|
|
|
n_steps_before_snapshot::Int64
|
|
|
|
|
n_snapshots::Int64
|
|
|
|
|
T::Float64
|
|
|
|
|
T0::Float64
|
|
|
|
|
start_datetime::Dates.DateTime
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
struct SimState
|
|
|
|
|
n_bundles::Int64
|
|
|
|
|
T::Float64
|
|
|
|
|
end
|
|
|
|
|
|
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
|
|
|
|
|
|
2022-01-21 22:17:15 +00:00
|
|
|
|
function save_bundle(dir::String, bundle::Bundle, n_bundle::Int64, T::Float64)
|
2021-12-12 14:29:08 +00:00
|
|
|
|
bundles_dir = "$dir/bundles"
|
|
|
|
|
mkpath(bundles_dir)
|
|
|
|
|
|
2022-01-21 22:17:15 +00:00
|
|
|
|
JLD2.save_object("$bundles_dir/bundle_$n_bundle.jld2", bundle)
|
2021-12-12 14:29:08 +00:00
|
|
|
|
|
2022-01-21 22:17:15 +00:00
|
|
|
|
JLD2.save_object("$dir/sim_state.jld2", SimState(n_bundle, round(T; digits=3)))
|
2021-11-17 19:03:07 +00:00
|
|
|
|
|
|
|
|
|
return nothing
|
2022-01-23 02:04:10 +00:00
|
|
|
|
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]
|
2021-11-17 19:03:07 +00:00
|
|
|
|
end
|