2021-12-12 14:29:08 +00:00
|
|
|
|
empty_hook(args...) = nothing
|
|
|
|
|
|
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,
|
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
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
sim_consts = JSON3.read(read("$dir/sim_consts.json", String))
|
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
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
sim_state = JSON3.read(read("$dir/sim_state.json", String))
|
|
|
|
|
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
|
|
|
|
|
start_datetime = now()
|
|
|
|
|
|
|
|
|
|
run_params = (;
|
|
|
|
|
# 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
|
|
|
|
|
write_struct_to_json(run_params, "$runs_dir/run_params_$next_bundle")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-02 23:37:43 +00:00
|
|
|
|
bundles_dir = "$dir/bundles"
|
|
|
|
|
bundle = JLD2.load_object("$bundles_dir/bundle_$n_bundles.jld2")
|
|
|
|
|
|
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,
|
|
|
|
|
c₁=4 * sim_consts.ϵ * 6 * sim_consts.σ^6 * sim_consts.δt * sim_consts.μ,
|
|
|
|
|
c₂=2 * sim_consts.σ^6,
|
|
|
|
|
c₃=sqrt(2 * sim_consts.D₀ * sim_consts.δt),
|
|
|
|
|
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,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
μ=sim_consts.μ,
|
|
|
|
|
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),
|
2021-12-12 14:29:08 +00:00
|
|
|
|
box=Box(
|
|
|
|
|
SVector(2 * sim_consts.half_box_len, 2 * sim_consts.half_box_len),
|
|
|
|
|
sim_consts.skin_r,
|
|
|
|
|
),
|
2021-11-17 19:43:20 +00:00
|
|
|
|
)
|
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
simulate(
|
|
|
|
|
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
|