2021-11-10 14:41:04 +00:00
|
|
|
|
function run(;
|
|
|
|
|
N::Int64,
|
2021-11-23 00:35:36 +00:00
|
|
|
|
T::Int64,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
v::Float64,
|
|
|
|
|
δt::Float64=1e-5,
|
2021-11-23 00:35:36 +00:00
|
|
|
|
snapshot_at::Float64=0.1,
|
2021-11-10 14:41:04 +00:00
|
|
|
|
framerate::Int64=0,
|
2021-11-17 18:47:05 +00:00
|
|
|
|
save_data::Bool=true,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
n_steps_before_verlet_list_update::Int64=1000,
|
|
|
|
|
packing_ratio::Float64=0.5,
|
2021-11-11 00:51:58 +00:00
|
|
|
|
debug::Bool=false,
|
2021-11-23 00:35:36 +00:00
|
|
|
|
seed::Int64=42,
|
2021-11-16 21:26:08 +00:00
|
|
|
|
)
|
2021-11-23 00:35:36 +00:00
|
|
|
|
@assert N > 0
|
|
|
|
|
@assert T > 0
|
|
|
|
|
@assert v >= 0
|
|
|
|
|
@assert δt > 0
|
|
|
|
|
@assert snapshot_at ∉ 0.01:0.01:T
|
|
|
|
|
@assert framerate >= 0
|
|
|
|
|
@assert n_steps_before_verlet_list_update >= 0
|
|
|
|
|
@assert packing_ratio > 0
|
|
|
|
|
@assert seed > 0
|
|
|
|
|
|
|
|
|
|
Random.seed!(seed)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
|
|
|
|
μ = 1.0
|
|
|
|
|
D₀ = 1.0
|
|
|
|
|
particle_diameter = 1.0
|
|
|
|
|
Dᵣ = 3 * D₀ / (particle_diameter^2)
|
|
|
|
|
σ = 1.0
|
|
|
|
|
ϵ = 100.0
|
|
|
|
|
interaction_r = 2^(1 / 6) * σ
|
|
|
|
|
|
|
|
|
|
grid_n = round(Int64, ceil(sqrt(N)))
|
|
|
|
|
|
|
|
|
|
N = grid_n^2
|
|
|
|
|
|
2021-11-17 19:43:20 +00:00
|
|
|
|
l = sqrt(N * π / packing_ratio) * σ / 4
|
2021-11-10 14:41:04 +00:00
|
|
|
|
grid_box_width = 2 * l / grid_n
|
|
|
|
|
|
|
|
|
|
skin_r = 1.1 * (2 * v * n_steps_before_verlet_list_update * δt + 2 * interaction_r)
|
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
|
integration_steps = floor(Int64, T / δt) + 1
|
2021-11-23 00:35:36 +00:00
|
|
|
|
n_steps_before_save = round(Int64, snapshot_at / δt)
|
2021-11-10 23:24:07 +00:00
|
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
|
n_frames = floor(Int64, integration_steps / n_steps_before_save) + 1
|
|
|
|
|
|
2021-11-10 14:41:04 +00:00
|
|
|
|
args = (
|
2021-11-16 21:26:08 +00:00
|
|
|
|
v=v,
|
|
|
|
|
c₁=4 * ϵ * 6 * σ^6 * δt * μ,
|
|
|
|
|
c₂=2 * σ^6,
|
|
|
|
|
c₃=sqrt(2 * D₀ * δt),
|
|
|
|
|
c₄=sqrt(2 * Dᵣ * δt),
|
|
|
|
|
vδt=v * δt,
|
|
|
|
|
μ=μ,
|
|
|
|
|
interaction_r=interaction_r,
|
|
|
|
|
interaction_r²=interaction_r^2,
|
|
|
|
|
N=N,
|
|
|
|
|
l=l,
|
|
|
|
|
particle_diameter=particle_diameter,
|
|
|
|
|
particles=generate_particles(grid_n, grid_box_width, l),
|
|
|
|
|
skin_r=skin_r,
|
|
|
|
|
skin_r²=skin_r^2,
|
|
|
|
|
verlet_list=[PreVector(Int64, N - 1) for i in 1:(N - 1)],
|
2021-11-18 18:42:11 +00:00
|
|
|
|
n_frames=n_frames,
|
2021-11-16 21:26:08 +00:00
|
|
|
|
debug=debug,
|
2021-11-10 14:41:04 +00:00
|
|
|
|
)
|
|
|
|
|
|
2021-11-16 21:26:08 +00:00
|
|
|
|
sol, end_time = simulate(
|
|
|
|
|
args, δt, T, n_steps_before_verlet_list_update, n_steps_before_save
|
|
|
|
|
)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
|
args = nothing
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
|
variables = (;
|
|
|
|
|
# Input
|
|
|
|
|
N,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
T,
|
2021-11-18 18:42:11 +00:00
|
|
|
|
v,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
δt,
|
2021-11-23 00:35:36 +00:00
|
|
|
|
snapshot_at,
|
2021-11-17 19:43:20 +00:00
|
|
|
|
framerate,
|
|
|
|
|
n_steps_before_verlet_list_update,
|
|
|
|
|
packing_ratio,
|
|
|
|
|
debug,
|
2021-11-18 18:42:11 +00:00
|
|
|
|
# Calculated
|
2021-11-17 19:43:20 +00:00
|
|
|
|
μ,
|
|
|
|
|
D₀,
|
|
|
|
|
particle_diameter,
|
|
|
|
|
Dᵣ,
|
|
|
|
|
σ,
|
|
|
|
|
ϵ,
|
|
|
|
|
interaction_r,
|
|
|
|
|
grid_n,
|
|
|
|
|
l,
|
|
|
|
|
grid_box_width,
|
|
|
|
|
skin_r,
|
|
|
|
|
integration_steps,
|
|
|
|
|
n_steps_before_save,
|
2021-11-18 18:42:11 +00:00
|
|
|
|
n_frames,
|
|
|
|
|
# Output
|
2021-11-17 19:43:20 +00:00
|
|
|
|
end_time,
|
|
|
|
|
)
|
|
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
|
postprocess(sol, variables, save_data)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
|
return (; sol, variables)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
end
|