From 4c4c9b5993ed6fd9663c2cd58d1815e21eabcfd9 Mon Sep 17 00:00:00 2001 From: MoBit Date: Wed, 17 Nov 2021 19:47:05 +0100 Subject: [PATCH] small changes --- Project.toml | 2 ++ src/Particle.jl | 10 ++++++---- src/PreVector.jl | 2 +- src/ReCo.jl | 2 +- src/animation.jl | 2 +- src/data.jl | 6 ++++-- src/pair_correlation_function.jl | 16 ++++++++-------- src/run.jl | 8 ++++---- src/simulation.jl | 6 +++--- 9 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Project.toml b/Project.toml index bd73673..9b4a70d 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,8 @@ ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7" ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" diff --git a/src/Particle.jl b/src/Particle.jl index 79e1e72..0e04dcf 100644 --- a/src/Particle.jl +++ b/src/Particle.jl @@ -39,21 +39,23 @@ function minimum_image_coordinate(value::Float64; l::Float64) end 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 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) distance² = r⃗₁₂[1]^2 + r⃗₁₂[2]^2 - return (distance² < overlapping_r², r⃗₁₂, distance²) + overlapping = distance² < overlapping_r² + + return (; overlapping, r⃗₁₂, distance²) end function update!(p::Particle) @simd for i in 1:2 p.c[i] = p.tmp_c[i] end -end \ No newline at end of file +end diff --git a/src/PreVector.jl b/src/PreVector.jl index a0a94ee..6c3a58c 100644 --- a/src/PreVector.jl +++ b/src/PreVector.jl @@ -24,4 +24,4 @@ function iterate(pv::PreVector{T}, state=1) where {T} else return (pv.v[state], state + 1) end -end \ No newline at end of file +end diff --git a/src/ReCo.jl b/src/ReCo.jl index d83f0ff..41dea08 100644 --- a/src/ReCo.jl +++ b/src/ReCo.jl @@ -20,4 +20,4 @@ includet("setup.jl") includet("simulation.jl") includet("data.jl") includet("animation.jl") -includet("run.jl") \ No newline at end of file +includet("run.jl") diff --git a/src/animation.jl b/src/animation.jl index a1cadbb..98b9b36 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -33,7 +33,7 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10) skin_colors = Observable(Vector{RGBAf}(undef, args.N)) 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) circles[][i] = Circle( Point2(sol.center[i, frame]), args.particle_diameter / 2 diff --git a/src/data.jl b/src/data.jl index b052a5a..bc7e84d 100644 --- a/src/data.jl +++ b/src/data.jl @@ -4,7 +4,9 @@ struct Solution φ::Matrix{Float64} 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 @@ -17,7 +19,7 @@ function save_frame!(sol, frame, t, particles) p_id = p.id pre_pos = sol.center[p_id, frame] - + @simd for i in 1:2 pre_pos[i] = p.c[i] end diff --git a/src/pair_correlation_function.jl b/src/pair_correlation_function.jl index fbb6196..2ae732f 100644 --- a/src/pair_correlation_function.jl +++ b/src/pair_correlation_function.jl @@ -10,7 +10,7 @@ function pair_correlation(frame=0, dr=0.1) ) 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)) if frame == 0 @@ -18,7 +18,7 @@ function pair_correlation(frame=0, dr=0.1) end for r_ind in 1:n_r - r = rs[r_ind] + r = radius[r_ind] for i 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) for r_ind in 1:n_r - r = rs[r_ind] + r = radius[r_ind] tmp_g = 0.0 for i in 1:(args.N) @@ -54,14 +54,14 @@ function pair_correlation(frame=0, dr=0.1) g[r_ind] = tmp_g end - return plot_g(rs, g) + return plot_g(radius, g) end -function plot_g(rs, g) +function plot_g(radius, g) fig = Figure(; resolution=(1080, 1080)) ax = Axis(fig[1, 1]; xlabel=L"r", ylabel=L"g(r)") - scatterlines!(ax, rs, g) + scatterlines!(ax, radius, g) - return (fig, rs, g) -end \ No newline at end of file + return (; fig, radius, g) +end diff --git a/src/run.jl b/src/run.jl index e6ed9be..c6d5cb8 100644 --- a/src/run.jl +++ b/src/run.jl @@ -5,7 +5,7 @@ function run(; δt::Float64=2e-5, save_at::Float64=0.1, framerate::Int64=0, - save_data::Bool=false, + save_data::Bool=true, n_steps_before_verlet_list_update::Int64=100, debug::Bool=false, ) @@ -56,15 +56,15 @@ function run(; 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 - save_data_jld(sol, args, name_part) + save_data_jld(name_part, sol, args, n_steps_before_verlet_list_update) end if framerate > 0 animate(sol, args, name_part; framerate=framerate) end - return (sol=sol, args=args, name_part=name_part) + return (; sol, args, name_part) end diff --git a/src/simulation.jl b/src/simulation.jl index be0599f..bfb5676 100644 --- a/src/simulation.jl +++ b/src/simulation.jl @@ -10,7 +10,7 @@ function update_verlet_list!(args) p1 = args.particles[i] 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 push!(args.verlet_list[i], j) @@ -79,7 +79,7 @@ function simulate( start_time = now() 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 frame = save_frame!(sol, frame, t, args.particles) end @@ -95,5 +95,5 @@ function simulate( elapsed_time = canonicalize(CompoundPeriod(end_time - start_time)) println("Done simulation at $end_time and took $elapsed_time.") - return (sol, end_time) + return (; sol, end_time) end