From acebf489b7a24781402728da85437b3de6c9cd4d Mon Sep 17 00:00:00 2001 From: Mo8it Date: Thu, 27 Jan 2022 17:07:24 +0100 Subject: [PATCH] Added periodic boundary conditions graphics --- graphics/periodic_boundary_conditions.jl | 115 +++++++++++++++++++++++ graphics/verlet_and_cell_lists.jl | 4 +- 2 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 graphics/periodic_boundary_conditions.jl diff --git a/graphics/periodic_boundary_conditions.jl b/graphics/periodic_boundary_conditions.jl new file mode 100644 index 0000000..bf65a57 --- /dev/null +++ b/graphics/periodic_boundary_conditions.jl @@ -0,0 +1,115 @@ +using Luxor +using Random: Random +using StaticArrays: SVector + +using ReCo: ReCo + +function gen_periodic_boundary_conditions_graphics() + Random.seed!(23) + + drwaing_box_length = 300 + + graphics_export_dir = "exports/graphics" + mkpath(graphics_export_dir) + + Drawing( + drwaing_box_length, + drwaing_box_length, + "$graphics_export_dir/periodic_boundary_conditions.pdf", + ) + origin() + + particle_radius = 10 + box_len = drwaing_box_length / 3 + half_box_len = box_len / 2 + + N_in_one_box = 5 + + colors = ["red", "blue", "orange", "green", "cyan"] + + distance_limit = 0.99 * 2 * particle_radius + + particles = Vector{ReCo.Particle}(undef, 9 * N_in_one_box) + translation_vecs = [ + SVector(0.0, 0.0), + SVector(box_len, 0.0), + SVector(box_len, box_len), + SVector(0.0, box_len), + SVector(-box_len, box_len), + SVector(-box_len, 0.0), + SVector(-box_len, -box_len), + SVector(0.0, -box_len), + SVector(box_len, -box_len), + ] + + p1_c = SVector(0.0, 0.0) + + for p1_ind in 1:N_in_one_box + while true + x = (rand() - 0.5) * (box_len - 2 * particle_radius) + y = (rand() - 0.5) * (box_len - 2 * particle_radius) + + p1_c = SVector(x, y) + + no_collision = true + + for p2_ind in 1:(p1_ind - 1) + if ReCo.norm2d(p1_c - particles[p2_ind].c) < distance_limit + no_collision = false + + break + end + end + + if no_collision + break + end + end + + setcolor(colors[p1_ind]) + for box_ind in 1:9 + c = p1_c + translation_vecs[box_ind] + particle = ReCo.Particle(0, c, 0.0) + particles[p1_ind * box_ind] = particle + circle(c[1], c[2], particle_radius, :fill) + end + end + + setcolor("black") + setline(1.0) + for sign in (1, -1) + line( + Point(sign * drwaing_box_length / 6, drwaing_box_length / 2), + Point(sign * drwaing_box_length / 6, -drwaing_box_length / 2), + :stroke, + ) + line( + Point(drwaing_box_length / 2, sign * drwaing_box_length / 6), + Point(-drwaing_box_length / 2, sign * drwaing_box_length / 6), + :stroke, + ) + end + + p1_ind = 3 + p2_ind = 5 + + p1_c = particles[p1_ind].c + p2_c = particles[p2_ind].c + normal_vec_form_p1_to_p2 = p2_c - p1_c + min_image_vec = ReCo.minimum_image(normal_vec_form_p1_to_p2, half_box_len) + min_image_vec_from_p1 = p1_c + min_image_vec + + setcolor("black") + arrow(Point(p1_c[1], p1_c[2]), Point(p2_c[1], p2_c[2]); linewidth=2.0) + + setcolor("red") + arrow( + Point(p1_c[1], p1_c[2]), + Point(min_image_vec_from_p1[1], min_image_vec_from_p1[2]); + linewidth=2.0, + ) + + finish() + + return nothing +end diff --git a/graphics/verlet_and_cell_lists.jl b/graphics/verlet_and_cell_lists.jl index 61d80df..8ed2f8a 100644 --- a/graphics/verlet_and_cell_lists.jl +++ b/graphics/verlet_and_cell_lists.jl @@ -93,6 +93,4 @@ function gen_verlet_and_cell_lists_graphics() finish() return nothing -end - -# TODO: Deduplicate with radial_distribution.jl \ No newline at end of file +end \ No newline at end of file