mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-21 00:51:21 +00:00
Added periodic boundary conditions graphics
This commit is contained in:
parent
bfcc1fee3f
commit
acebf489b7
2 changed files with 116 additions and 3 deletions
115
graphics/periodic_boundary_conditions.jl
Normal file
115
graphics/periodic_boundary_conditions.jl
Normal file
|
@ -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
|
|
@ -93,6 +93,4 @@ function gen_verlet_and_cell_lists_graphics()
|
|||
finish()
|
||||
|
||||
return nothing
|
||||
end
|
||||
|
||||
# TODO: Deduplicate with radial_distribution.jl
|
||||
end
|
Loading…
Reference in a new issue