1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00
ReCo.jl/src/run.jl
2022-01-23 04:21:06 +01:00

122 lines
No EOL
3.4 KiB
Julia
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function empty_hook(args...)
return nothing
end
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
function run_sim(
dir::String;
duration::Float64,
snapshot_at::Float64=0.1,
seed::Int64=42,
n_bundle_snapshots::Int64=100,
env_helper::Union{RL.EnvHelper,Nothing}=nothing,
show_progress::Bool=true,
)
@assert length(dir) > 0
@assert duration > 0
@assert snapshot_at in 0.001:0.001:duration
@assert seed > 0
@assert n_bundle_snapshots >= 0
Random.seed!(seed)
sim_consts::SimConsts = JLD2.load_object("$dir/sim_consts.jld2")
integration_steps = floor(Int64, duration / sim_consts.δt) + 1
n_steps_before_snapshot = round(Int64, snapshot_at / sim_consts.δt)
n_snapshots = floor(Int64, integration_steps / n_steps_before_snapshot) + 1
@assert (n_snapshots - 1) * snapshot_at == duration
n_bundle_snapshots = min(n_snapshots, n_bundle_snapshots)
sim_state::SimState = JLD2.load_object("$dir/sim_state.jld2")
n_bundles = sim_state.n_bundles
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 = Dates.now()
run_params = RunParams(
# Input
duration,
snapshot_at,
seed,
n_bundle_snapshots,
# Internal
integration_steps,
n_steps_before_snapshot,
n_snapshots,
T,
T0,
start_datetime,
)
next_bundle = n_bundles + 1
runs_dir = "$dir/runs"
if save_data
JLD2.save_object("$runs_dir/run_params_$next_bundle.jld2", run_params)
end
end
bundles_dir = "$dir/bundles"
bundle::Bundle = JLD2.load_object("$bundles_dir/bundle_$n_bundles.jld2")
particles = gen_particles(bundle, sim_consts.n_particles)
args = (
v₀=sim_consts.v₀,
δt=sim_consts.δt,
skin_r=sim_consts.skin_r,
skin_r²=sim_consts.skin_r^2,
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),
v₀δt=sim_consts.v₀ * sim_consts.δt,
μ=sim_consts.μ,
interaction_r=sim_consts.interaction_r,
interaction_r²=sim_consts.interaction_r^2,
n_particles=sim_consts.n_particles,
half_box_len=sim_consts.half_box_len,
particles=particles,
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)
],
n_bundle_snapshots=n_bundle_snapshots,
bundle=Bundle(sim_consts.n_particles, n_bundle_snapshots),
box=gen_cell_list_box(sim_consts.half_box_len, sim_consts.skin_r),
show_progress=show_progress,
)
simulate!(
args,
T0,
T,
sim_consts.n_steps_before_verlet_list_update,
n_steps_before_snapshot,
n_bundles,
dir,
save_data,
env_helper,
)
return nothing
end