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,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
n_steps_before_verlet_list_update::Int64=1000,
|
2021-11-23 00:35:36 +00:00
|
|
|
|
seed::Int64=42,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_bundle_snapshots::Int64=100,
|
2021-11-16 21:26:08 +00:00
|
|
|
|
)
|
2021-11-26 05:55:27 +00:00
|
|
|
|
@assert length(dir) > 0
|
|
|
|
|
@assert duration > 0
|
|
|
|
|
@assert snapshot_at in 0.01:0.01:duration
|
2021-11-23 00:35:36 +00:00
|
|
|
|
@assert n_steps_before_verlet_list_update >= 0
|
|
|
|
|
@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
|
|
|
|
skin_r =
|
|
|
|
|
1.1 * (
|
|
|
|
|
2 * sim_consts.v * n_steps_before_verlet_list_update * sim_consts.δt +
|
|
|
|
|
2 * sim_consts.interaction_r
|
|
|
|
|
)
|
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
|
|
|
|
|
n_steps_before_snapshot = round(Int64, snapshot_at / sim_consts.δt)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
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-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-11-10 14:41:04 +00:00
|
|
|
|
args = (
|
2021-11-26 05:55:27 +00:00
|
|
|
|
v=sim_consts.v,
|
2021-11-16 21:26:08 +00:00
|
|
|
|
skin_r=skin_r,
|
|
|
|
|
skin_r²=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),
|
|
|
|
|
vδt=sim_consts.v * sim_consts.δt,
|
|
|
|
|
μ=sim_consts.μ,
|
|
|
|
|
interaction_r=sim_consts.interaction_r,
|
|
|
|
|
interaction_r²=sim_consts.interaction_r^2,
|
|
|
|
|
N=sim_consts.N,
|
|
|
|
|
l=sim_consts.l,
|
|
|
|
|
particle_diameter=sim_consts.particle_diameter,
|
|
|
|
|
particles=generate_particles(
|
|
|
|
|
sim_consts.grid_n, sim_consts.grid_box_width, sim_consts.l
|
|
|
|
|
),
|
|
|
|
|
verlet_list=[PreVector{Int64}(sim_consts.N - 1) for i in 1:(sim_consts.N - 1)],
|
|
|
|
|
n_bundle_snapshots=n_bundle_snapshots,
|
|
|
|
|
bundle=Bundle(sim_consts.N, n_bundle_snapshots),
|
2021-11-10 14:41:04 +00:00
|
|
|
|
)
|
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
status = JSON3.read(read("$dir/status.json", String))
|
|
|
|
|
T0::Float64 = status.T
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
T = T0 + duration
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
start_datetime = now()
|
|
|
|
|
|
|
|
|
|
run_vars = (;
|
2021-11-18 18:42:11 +00:00
|
|
|
|
# Input
|
2021-11-26 05:55:27 +00:00
|
|
|
|
duration,
|
2021-11-23 00:35:36 +00:00
|
|
|
|
snapshot_at,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
n_steps_before_verlet_list_update,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
seed,
|
|
|
|
|
n_bundle_snapshots,
|
2021-11-18 18:42:11 +00:00
|
|
|
|
# Calculated
|
2021-11-17 19:43:20 +00:00
|
|
|
|
skin_r,
|
|
|
|
|
integration_steps,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_steps_before_snapshot,
|
|
|
|
|
n_snapshots,
|
|
|
|
|
T,
|
|
|
|
|
# Read
|
|
|
|
|
T0,
|
|
|
|
|
start_datetime,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
)
|
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
n_bundles::Int64 = status.n_bundles
|
|
|
|
|
next_bundle = n_bundles + 1
|
2021-11-26 14:00:19 +00:00
|
|
|
|
bundles_dir = "$dir/bundles"
|
|
|
|
|
mkpath(bundles_dir)
|
2021-11-26 05:55:27 +00:00
|
|
|
|
|
|
|
|
|
if n_bundle_snapshots > 0
|
|
|
|
|
save_data = true
|
|
|
|
|
|
2021-11-26 13:50:47 +00:00
|
|
|
|
open("$bundles_dir/run_vars_$next_bundle.json", "w") do f
|
2021-11-26 05:55:27 +00:00
|
|
|
|
JSON3.pretty(f, run_vars)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
save_data = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
simulate(
|
|
|
|
|
args,
|
|
|
|
|
sim_consts.δt,
|
|
|
|
|
T0,
|
|
|
|
|
T,
|
|
|
|
|
n_steps_before_verlet_list_update,
|
|
|
|
|
n_steps_before_snapshot,
|
|
|
|
|
n_bundles,
|
|
|
|
|
dir,
|
|
|
|
|
save_data,
|
|
|
|
|
)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
return dir
|
|
|
|
|
end
|