mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-23 01:01:03 +00:00
122 lines
No EOL
3.4 KiB
Julia
122 lines
No EOL
3.4 KiB
Julia
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/$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,
|
||
ϵσ⁶δtμₜ24=24 * sim_consts.ϵ * sim_consts.σ^6 * sim_consts.δt * sim_consts.μₜ,
|
||
σ⁶2=2 * sim_consts.σ^6,
|
||
sqrt_Dₜδt2=sqrt(2 * sim_consts.Dₜ * sim_consts.δt),
|
||
sqrt_Dᵣδt2=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 |