mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-11-08 22:21:08 +00:00
small changes
This commit is contained in:
parent
f4734064c5
commit
4c4c9b5993
9 changed files with 30 additions and 24 deletions
|
@ -4,6 +4,8 @@ ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
|
||||||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
|
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
|
||||||
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
|
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
|
||||||
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
|
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
|
||||||
|
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
|
||||||
|
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
|
||||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||||
ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7"
|
ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7"
|
||||||
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
|
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
|
||||||
|
|
|
@ -39,17 +39,19 @@ function minimum_image_coordinate(value::Float64; l::Float64)
|
||||||
end
|
end
|
||||||
|
|
||||||
function minimum_image(v::SVector{2,Float64}; l::Float64)
|
function minimum_image(v::SVector{2,Float64}; l::Float64)
|
||||||
return minimum_image_coordinate.(v; l=l)
|
return SVector(minimum_image_coordinate(v[1]; l=l), minimum_image_coordinate(v[2]; l=l))
|
||||||
end
|
end
|
||||||
|
|
||||||
function are_overlapping(p1::Particle, p2::Particle, overlapping_r²::Float64, l::Float64)
|
function are_overlapping(p1::Particle, p2::Particle, overlapping_r²::Float64, l::Float64)
|
||||||
r⃗₁₂ = SVector{2}(p2.c) - SVector{2}(p1.c) # 1 -> 2
|
r⃗₁₂ = SVector(p2.c[1] - p1.c[1], p2.c[2] - p1.c[2]) # 1 -> 2
|
||||||
|
|
||||||
r⃗₁₂ = minimum_image(r⃗₁₂; l=l)
|
r⃗₁₂ = minimum_image(r⃗₁₂; l=l)
|
||||||
|
|
||||||
distance² = r⃗₁₂[1]^2 + r⃗₁₂[2]^2
|
distance² = r⃗₁₂[1]^2 + r⃗₁₂[2]^2
|
||||||
|
|
||||||
return (distance² < overlapping_r², r⃗₁₂, distance²)
|
overlapping = distance² < overlapping_r²
|
||||||
|
|
||||||
|
return (; overlapping, r⃗₁₂, distance²)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update!(p::Particle)
|
function update!(p::Particle)
|
||||||
|
|
|
@ -33,7 +33,7 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
||||||
skin_colors = Observable(Vector{RGBAf}(undef, args.N))
|
skin_colors = Observable(Vector{RGBAf}(undef, args.N))
|
||||||
end
|
end
|
||||||
|
|
||||||
@showprogress 0.5 for frame in 1:(args.n_frames)
|
@showprogress 0.6 for frame in 1:(args.n_frames)
|
||||||
@simd for i in 1:(args.N)
|
@simd for i in 1:(args.N)
|
||||||
circles[][i] = Circle(
|
circles[][i] = Circle(
|
||||||
Point2(sol.center[i, frame]), args.particle_diameter / 2
|
Point2(sol.center[i, frame]), args.particle_diameter / 2
|
||||||
|
|
|
@ -4,7 +4,9 @@ struct Solution
|
||||||
φ::Matrix{Float64}
|
φ::Matrix{Float64}
|
||||||
|
|
||||||
function Solution(N::Int64, n_frames::Int64)
|
function Solution(N::Int64, n_frames::Int64)
|
||||||
return new(zeros(n_frames), [zeros(2) for i in 1:N, j in 1:n_frames], zeros((N, n_frames)))
|
return new(
|
||||||
|
zeros(n_frames), [zeros(2) for i in 1:N, j in 1:n_frames], zeros((N, n_frames))
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ function pair_correlation(frame=0, dr=0.1)
|
||||||
)
|
)
|
||||||
|
|
||||||
n_r = 100
|
n_r = 100
|
||||||
rs = range(0, args.l; length=n_r)
|
radius = range(0, args.l; length=n_r)
|
||||||
N_g = zeros((args.N, n_r))
|
N_g = zeros((args.N, n_r))
|
||||||
|
|
||||||
if frame == 0
|
if frame == 0
|
||||||
|
@ -18,7 +18,7 @@ function pair_correlation(frame=0, dr=0.1)
|
||||||
end
|
end
|
||||||
|
|
||||||
for r_ind in 1:n_r
|
for r_ind in 1:n_r
|
||||||
r = rs[r_ind]
|
r = radius[r_ind]
|
||||||
|
|
||||||
for i in 1:(args.N)
|
for i in 1:(args.N)
|
||||||
for j in 1:(args.N)
|
for j in 1:(args.N)
|
||||||
|
@ -43,7 +43,7 @@ function pair_correlation(frame=0, dr=0.1)
|
||||||
g = zeros(n_r)
|
g = zeros(n_r)
|
||||||
|
|
||||||
for r_ind in 1:n_r
|
for r_ind in 1:n_r
|
||||||
r = rs[r_ind]
|
r = radius[r_ind]
|
||||||
tmp_g = 0.0
|
tmp_g = 0.0
|
||||||
|
|
||||||
for i in 1:(args.N)
|
for i in 1:(args.N)
|
||||||
|
@ -54,14 +54,14 @@ function pair_correlation(frame=0, dr=0.1)
|
||||||
g[r_ind] = tmp_g
|
g[r_ind] = tmp_g
|
||||||
end
|
end
|
||||||
|
|
||||||
return plot_g(rs, g)
|
return plot_g(radius, g)
|
||||||
end
|
end
|
||||||
|
|
||||||
function plot_g(rs, g)
|
function plot_g(radius, g)
|
||||||
fig = Figure(; resolution=(1080, 1080))
|
fig = Figure(; resolution=(1080, 1080))
|
||||||
ax = Axis(fig[1, 1]; xlabel=L"r", ylabel=L"g(r)")
|
ax = Axis(fig[1, 1]; xlabel=L"r", ylabel=L"g(r)")
|
||||||
|
|
||||||
scatterlines!(ax, rs, g)
|
scatterlines!(ax, radius, g)
|
||||||
|
|
||||||
return (fig, rs, g)
|
return (; fig, radius, g)
|
||||||
end
|
end
|
|
@ -5,7 +5,7 @@ function run(;
|
||||||
δt::Float64=2e-5,
|
δt::Float64=2e-5,
|
||||||
save_at::Float64=0.1,
|
save_at::Float64=0.1,
|
||||||
framerate::Int64=0,
|
framerate::Int64=0,
|
||||||
save_data::Bool=false,
|
save_data::Bool=true,
|
||||||
n_steps_before_verlet_list_update::Int64=100,
|
n_steps_before_verlet_list_update::Int64=100,
|
||||||
debug::Bool=false,
|
debug::Bool=false,
|
||||||
)
|
)
|
||||||
|
@ -56,15 +56,15 @@ function run(;
|
||||||
args, δt, T, n_steps_before_verlet_list_update, n_steps_before_save
|
args, δt, T, n_steps_before_verlet_list_update, n_steps_before_save
|
||||||
)
|
)
|
||||||
|
|
||||||
name_part = "$(end_time)_T=$(T)_N=$(N)_v=$(v)_dt=$(δt)"
|
name_part = "$(end_time)_T=$(T)_N=$(N)_v=$(v)"
|
||||||
|
|
||||||
if save_data
|
if save_data
|
||||||
save_data_jld(sol, args, name_part)
|
save_data_jld(name_part, sol, args, n_steps_before_verlet_list_update)
|
||||||
end
|
end
|
||||||
|
|
||||||
if framerate > 0
|
if framerate > 0
|
||||||
animate(sol, args, name_part; framerate=framerate)
|
animate(sol, args, name_part; framerate=framerate)
|
||||||
end
|
end
|
||||||
|
|
||||||
return (sol=sol, args=args, name_part=name_part)
|
return (; sol, args, name_part)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ function update_verlet_list!(args)
|
||||||
p1 = args.particles[i]
|
p1 = args.particles[i]
|
||||||
p2 = args.particles[j]
|
p2 = args.particles[j]
|
||||||
|
|
||||||
overlapping, r⃗₁₂, distance² = are_overlapping(p1, p2, args.skin_r², args.l)
|
overlapping = are_overlapping(p1, p2, args.skin_r², args.l).overlapping
|
||||||
|
|
||||||
if overlapping
|
if overlapping
|
||||||
push!(args.verlet_list[i], j)
|
push!(args.verlet_list[i], j)
|
||||||
|
@ -79,7 +79,7 @@ function simulate(
|
||||||
start_time = now()
|
start_time = now()
|
||||||
println("Started simulation at $start_time.")
|
println("Started simulation at $start_time.")
|
||||||
|
|
||||||
@showprogress 0.2 for (integration_step, t) in enumerate(0:δt:T)
|
@showprogress 0.6 for (integration_step, t) in enumerate(0:δt:T)
|
||||||
if integration_step % n_steps_before_save == 0
|
if integration_step % n_steps_before_save == 0
|
||||||
frame = save_frame!(sol, frame, t, args.particles)
|
frame = save_frame!(sol, frame, t, args.particles)
|
||||||
end
|
end
|
||||||
|
@ -95,5 +95,5 @@ function simulate(
|
||||||
elapsed_time = canonicalize(CompoundPeriod(end_time - start_time))
|
elapsed_time = canonicalize(CompoundPeriod(end_time - start_time))
|
||||||
println("Done simulation at $end_time and took $elapsed_time.")
|
println("Done simulation at $end_time and took $elapsed_time.")
|
||||||
|
|
||||||
return (sol, end_time)
|
return (; sol, end_time)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue