Skip to content

Commit 9481a48

Browse files
committed
refactor: move all neighbour list update code to module
1 parent 345ad1a commit 9481a48

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/moves.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ Returns the tuple `(e₁, e₂)` of energies before and after the move.
5757
function perform_action!(system::Particles, action::Displacement)
5858
neighbour_list = get_neighbour_list(system)
5959
e₁ = compute_energy_particle(system, action.i, neighbour_list)
60+
6061
update_position!(system, action)
61-
c, c2 = old_new_cell(system, action.i, neighbour_list)
62-
if c != c2
63-
update_neighbour_list!(action.i, c, c2, neighbour_list)
64-
end
62+
update_neighbour_list!(system, action.i, neighbour_list)
63+
6564
e₂ = compute_energy_particle(system, action.i, neighbour_list)
6665
action.δe = e₂ - e₁
6766
return e₁, e₂
@@ -78,10 +77,7 @@ function Arianna.revert_action!(system::Particles, action::Displacement)
7877
update_position!(system, action)
7978
neighbour_list = get_neighbour_list(system)
8079
system.energy[1] -= action.δe
81-
c, c2 = old_new_cell(system, action.i, neighbour_list)
82-
if c != c2
83-
update_neighbour_list!(action.i, c, c2, neighbour_list)
84-
end
80+
update_neighbour_list!(system, action.i, neighbour_list)
8581
end
8682

8783
"""

src/neighbours.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,10 @@ end
3030

3131
"""No-op update for `EmptyList`.
3232
"""
33-
function update_neighbour_list!(i, c, c2, ::EmptyList)
33+
function update_neighbour_list!(system::Particles, ::Int, ::EmptyList)
3434
return nothing
3535
end
3636

37-
"""Return placeholder old and new cell indices for `EmptyList`.
38-
39-
Always returns (1,1) as no cells are tracked.
40-
"""
41-
function old_new_cell(::Particles, i, ::EmptyList)
42-
return 1, 1
43-
end
4437

4538
"""Calling an EmptyList objects return an object which can be iterated upon.
4639
@@ -169,6 +162,12 @@ function update_neighbour_list!(i, c, c2, neighbour_list::CellList)
169162
return nothing
170163
end
171164

165+
function update_neighbour_list!(system::Particles, i::Int, neighbour_list::CellList)
166+
c, c2 = old_new_cell(system, i, neighbour_list)
167+
if c != c2
168+
update_neighbour_list!(i, c, c2, neighbour_list)
169+
end
170+
end
172171

173172

174173

@@ -295,6 +294,13 @@ function update_neighbour_list!(i::Int, c::Int, c2::Int, neighbour_list::LinkedL
295294
return nothing
296295
end
297296

297+
function update_neighbour_list!(system::Particles, i::Int, neighbour_list::LinkedList)
298+
c, c2 = old_new_cell(system, i, neighbour_list)
299+
if c != c2
300+
update_neighbour_list!(i, c, c2, neighbour_list)
301+
end
302+
end
303+
298304
"""Return old and new cell indices for particle `i` using a `LinkedList` neighbour list.
299305
"""
300306
function old_new_cell(system::Particles, i, neighbour_list::LinkedList)

0 commit comments

Comments
 (0)