2021-12-02 22:13:54 +00:00
|
|
|
|
using Distributions: Uniform
|
|
|
|
|
using Dates: now
|
|
|
|
|
using JSON3: JSON3
|
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
function initial_particle_grid_pos(
|
|
|
|
|
i::Int64, j::Int64, grid_box_width::Float64, half_box_len::Float64
|
|
|
|
|
)
|
|
|
|
|
term = -0.5 * grid_box_width - half_box_len
|
2021-12-08 20:53:15 +00:00
|
|
|
|
return SVector(i * grid_box_width + term, j * grid_box_width + term)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
end
|
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
function generate_particles(grid_n::Int64, grid_box_width::Float64, half_box_len::Float64)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
particles = Vector{Particle}(undef, grid_n^2)
|
|
|
|
|
|
|
|
|
|
id = 1
|
|
|
|
|
|
|
|
|
|
for i in 1:grid_n
|
|
|
|
|
for j in 1:grid_n
|
2021-12-07 00:36:47 +00:00
|
|
|
|
particles[id] = Particle(
|
2021-12-10 02:16:18 +00:00
|
|
|
|
id,
|
|
|
|
|
initial_particle_grid_pos(i, j, grid_box_width, half_box_len),
|
|
|
|
|
rand(Uniform(-π, π)),
|
2021-11-10 14:41:04 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
id += 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return particles
|
|
|
|
|
end
|
2021-11-26 05:55:27 +00:00
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
function generate_particles(bundle::Bundle, n_particles::Int64)
|
|
|
|
|
particles = Vector{Particle}(undef, n_particles)
|
2021-12-02 23:37:43 +00:00
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
@simd for id in 1:n_particles
|
2021-12-07 00:36:47 +00:00
|
|
|
|
particles[id] = Particle(id, bundle.c[id, end], bundle.φ[id, end])
|
2021-12-02 23:37:43 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return particles
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
function init_sim(;
|
2021-12-10 02:16:18 +00:00
|
|
|
|
n_particles::Int64,
|
2021-12-03 12:02:33 +00:00
|
|
|
|
v::Float64,
|
|
|
|
|
δt::Float64=1e-5,
|
|
|
|
|
packing_ratio::Float64=0.5,
|
|
|
|
|
comment::String="",
|
|
|
|
|
parent_dir::String="",
|
2021-11-26 05:55:27 +00:00
|
|
|
|
)
|
2021-12-10 02:16:18 +00:00
|
|
|
|
@assert n_particles > 0
|
2021-11-26 05:55:27 +00:00
|
|
|
|
@assert v >= 0
|
|
|
|
|
@assert δt in 1e-7:1e-7:1e-4
|
|
|
|
|
@assert packing_ratio > 0
|
|
|
|
|
|
|
|
|
|
μ = 1.0
|
|
|
|
|
D₀ = 1.0
|
|
|
|
|
particle_diameter = 1.0
|
|
|
|
|
Dᵣ = 3 * D₀ / (particle_diameter^2)
|
|
|
|
|
σ = 1.0
|
|
|
|
|
ϵ = 100.0
|
|
|
|
|
interaction_r = 2^(1 / 6) * σ
|
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
grid_n = round(Int64, ceil(sqrt(n_particles)))
|
2021-11-26 05:55:27 +00:00
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
n_particles = grid_n^2
|
2021-11-26 05:55:27 +00:00
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
half_box_len = sqrt(n_particles * π / packing_ratio) * σ / 4
|
|
|
|
|
grid_box_width = 2 * half_box_len / grid_n
|
2021-11-26 05:55:27 +00:00
|
|
|
|
|
|
|
|
|
sim_consts = (;
|
|
|
|
|
# Input
|
2021-12-10 02:16:18 +00:00
|
|
|
|
n_particles,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
v,
|
|
|
|
|
δt,
|
|
|
|
|
packing_ratio,
|
|
|
|
|
# Calculated
|
|
|
|
|
μ,
|
|
|
|
|
D₀,
|
|
|
|
|
particle_diameter,
|
|
|
|
|
Dᵣ,
|
|
|
|
|
σ,
|
|
|
|
|
ϵ,
|
|
|
|
|
interaction_r,
|
|
|
|
|
grid_n,
|
2021-12-10 02:16:18 +00:00
|
|
|
|
half_box_len,
|
2021-11-26 05:55:27 +00:00
|
|
|
|
grid_box_width,
|
|
|
|
|
)
|
|
|
|
|
|
2021-12-10 02:16:18 +00:00
|
|
|
|
particles = generate_particles(grid_n, grid_box_width, half_box_len)
|
|
|
|
|
bundle = Bundle(n_particles, 1)
|
2021-11-26 05:55:27 +00:00
|
|
|
|
save_snapshot!(bundle, 1, 0.0, particles)
|
|
|
|
|
|
2021-12-03 12:02:33 +00:00
|
|
|
|
particles = nothing
|
|
|
|
|
|
|
|
|
|
dir = "exports"
|
|
|
|
|
if length(parent_dir) > 0
|
|
|
|
|
dir *= "/$parent_dir"
|
|
|
|
|
end
|
2021-12-10 02:16:18 +00:00
|
|
|
|
dir *= "/$(now())_N=$(n_particles)_v=$(v)_#$(rand(1000:9999))"
|
2021-12-03 12:02:33 +00:00
|
|
|
|
if length(comment) > 0
|
|
|
|
|
dir *= "_$comment"
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-26 05:55:27 +00:00
|
|
|
|
mkpath(dir)
|
|
|
|
|
|
|
|
|
|
open("$dir/sim_consts.json", "w") do f
|
2021-12-03 12:02:33 +00:00
|
|
|
|
JSON3.write(f, sim_consts)
|
2021-11-26 05:55:27 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
save_bundle(dir, bundle, 1, 0.0)
|
|
|
|
|
|
|
|
|
|
return dir
|
|
|
|
|
end
|