2022-01-18 01:17:52 +00:00
|
|
|
|
function empty_hook(args...)
|
|
|
|
|
return nothing
|
|
|
|
|
end
|
2021-12-12 14:29:08 +00:00
|
|
|
|
|
2022-01-23 02:04:10 +00:00
|
|
|
|
function gen_cell_list_box(half_box_len::Float64, skin_r::Float64)
|
|
|
|
|
return CellListMap.Box(SVector(2 * half_box_len, 2 * half_box_len), skin_r)
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
function run_sim(
|
|
|
|
|
dir::String;
|
|
|
|
|
duration::Float64,
|
2021-11-23 00:35:36 +00:00
|
|
|
|
snapshot_at::Float64=0.1,
|
|
|
|
|
seed::Int64=42,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_bundle_snapshots::Int64=100,
|
2022-01-11 00:31:30 +00:00
|
|
|
|
env_helper::Union{RL.EnvHelper,Nothing}=nothing,
|
2022-01-23 03:21:06 +00:00
|
|
|
|
show_progress::Bool=true,
|
2021-11-16 21:26:08 +00:00
|
|
|
|
)
|
2021-11-26 05:55:27 +00:00
|
|
|
|
@assert length(dir) > 0
|
|
|
|
|
@assert duration > 0
|
2021-12-11 18:21:56 +00:00
|
|
|
|
@assert snapshot_at in 0.001:0.001:duration
|
2021-11-23 00:35:36 +00:00
|
|
|
|
@assert seed > 0
|
2021-11-26 05:55:27 +00:00
|
|
|
|
@assert n_bundle_snapshots >= 0
|
2021-11-23 00:35:36 +00:00
|
|
|
|
|
|
|
|
|
Random.seed!(seed)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2022-01-21 22:17:15 +00:00
|
|
|
|
sim_consts::SimConsts = JLD2.load_object("$dir/sim_consts.jld2")
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
integration_steps = floor(Int64, duration / sim_consts.δt) + 1
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-12-12 14:29:08 +00:00
|
|
|
|
n_steps_before_snapshot = round(Int64, snapshot_at / sim_consts.δt)
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_snapshots = floor(Int64, integration_steps / n_steps_before_snapshot) + 1
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-12-12 23:19:18 +00:00
|
|
|
|
@assert (n_snapshots - 1) * snapshot_at == duration
|
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_bundle_snapshots = min(n_snapshots, n_bundle_snapshots)
|
2021-11-18 18:42:11 +00:00
|
|
|
|
|
2022-01-21 22:17:15 +00:00
|
|
|
|
sim_state::SimState = JLD2.load_object("$dir/sim_state.jld2")
|
2021-12-10 02:16:18 +00:00
|
|
|
|
n_bundles = sim_state.n_bundles
|
2021-12-02 23:37:43 +00:00
|
|
|
|
|
2021-12-12 14:29:08 +00:00
|
|
|
|
T0::Float64 = sim_state.T
|
|
|
|
|
T = T0 + duration
|
|
|
|
|
|
|
|
|
|
if n_bundle_snapshots > 0
|
|
|
|
|
save_data = true
|
|
|
|
|
else
|
|
|
|
|
save_data = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@async begin
|
2022-01-21 22:17:15 +00:00
|
|
|
|
start_datetime = Dates.now()
|
2021-12-12 14:29:08 +00:00
|
|
|
|
|
2022-01-21 22:17:15 +00:00
|
|
|
|
run_params = RunParams(
|
2021-12-12 14:29:08 +00:00
|
|
|
|
# Input
|
|
|
|
|
duration,
|
|
|
|
|
snapshot_at,
|
|
|
|
|
seed,
|
|
|
|
|
n_bundle_snapshots,
|
2022-01-17 21:00:59 +00:00
|
|
|
|
# Internal
|
2021-12-12 14:29:08 +00:00
|
|
|
|
integration_steps,
|
|
|
|
|
n_steps_before_snapshot,
|
|
|
|
|
n_snapshots,
|
|
|
|
|
T,
|
|
|
|
|
T0,
|
|
|
|
|
start_datetime,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
next_bundle = n_bundles + 1
|
|
|
|
|
|
|
|
|
|
runs_dir = "$dir/runs"
|
|
|
|
|
|
|
|
|
|
if save_data
|
2022-01-21 22:17:15 +00:00
|
|
|
|
JLD2.save_object("$runs_dir/run_params_$next_bundle.jld2", run_params)
|
2021-12-12 14:29:08 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-02 23:37:43 +00:00
|
|
|
|
bundles_dir = "$dir/bundles"
|
2022-01-24 20:27:43 +00:00
|
|
|
|
bundle::Bundle = JLD2.load_object("$bundles_dir/$n_bundles.jld2")
|
2021-12-02 23:37:43 +00:00
|
|
|
|
|
2021-12-12 14:29:08 +00:00
|
|
|
|
particles = gen_particles(bundle, sim_consts.n_particles)
|
2021-12-07 03:19:35 +00:00
|
|
|
|
|
2021-11-10 14:41:04 +00:00
|
|
|
|
args = (
|
2021-12-12 14:29:08 +00:00
|
|
|
|
v₀=sim_consts.v₀,
|
2021-12-12 17:27:56 +00:00
|
|
|
|
δt=sim_consts.δt,
|
2021-12-12 14:29:08 +00:00
|
|
|
|
skin_r=sim_consts.skin_r,
|
|
|
|
|
skin_r²=sim_consts.skin_r^2,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_snapshots=n_snapshots,
|
2022-01-23 15:14:37 +00:00
|
|
|
|
c₁=4 * sim_consts.ϵ * 6 * sim_consts.σ^6 * sim_consts.δt * sim_consts.μₜ,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
c₂=2 * sim_consts.σ^6,
|
2022-01-20 16:33:17 +00:00
|
|
|
|
c₃=sqrt(2 * sim_consts.Dₜ * sim_consts.δt),
|
2021-11-26 05:55:27 +00:00
|
|
|
|
c₄=sqrt(2 * sim_consts.Dᵣ * sim_consts.δt),
|
2021-12-12 14:29:08 +00:00
|
|
|
|
v₀δt=sim_consts.v₀ * sim_consts.δt,
|
2022-01-23 15:14:37 +00:00
|
|
|
|
μₜ=sim_consts.μₜ,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
interaction_r=sim_consts.interaction_r,
|
|
|
|
|
interaction_r²=sim_consts.interaction_r^2,
|
2021-12-10 02:16:18 +00:00
|
|
|
|
n_particles=sim_consts.n_particles,
|
|
|
|
|
half_box_len=sim_consts.half_box_len,
|
2021-12-07 03:19:35 +00:00
|
|
|
|
particles=particles,
|
2021-12-10 02:16:18 +00:00
|
|
|
|
particles_c=[particles[i].c for i in 1:(sim_consts.n_particles)],
|
|
|
|
|
verlet_lists=[
|
|
|
|
|
PreVector{Int64}(sim_consts.n_particles - i) for
|
|
|
|
|
i in 1:(sim_consts.n_particles - 1)
|
|
|
|
|
],
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_bundle_snapshots=n_bundle_snapshots,
|
2021-12-10 02:16:18 +00:00
|
|
|
|
bundle=Bundle(sim_consts.n_particles, n_bundle_snapshots),
|
2022-01-23 02:04:10 +00:00
|
|
|
|
box=gen_cell_list_box(sim_consts.half_box_len, sim_consts.skin_r),
|
2022-01-23 03:21:06 +00:00
|
|
|
|
show_progress=show_progress,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
)
|
|
|
|
|
|
2022-01-18 01:17:52 +00:00
|
|
|
|
simulate!(
|
2021-11-26 05:55:27 +00:00
|
|
|
|
args,
|
|
|
|
|
T0,
|
|
|
|
|
T,
|
2021-12-12 23:19:18 +00:00
|
|
|
|
sim_consts.n_steps_before_verlet_list_update,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_steps_before_snapshot,
|
|
|
|
|
n_bundles,
|
|
|
|
|
dir,
|
|
|
|
|
save_data,
|
2022-01-11 00:31:30 +00:00
|
|
|
|
env_helper,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-12-12 14:29:08 +00:00
|
|
|
|
return nothing
|
2021-11-26 05:55:27 +00:00
|
|
|
|
end
|