diff --git a/src/moves.jl b/src/moves.jl index f3e25ca..71d35d0 100644 --- a/src/moves.jl +++ b/src/moves.jl @@ -57,11 +57,10 @@ Returns the tuple `(e₁, e₂)` of energies before and after the move. function perform_action!(system::Particles, action::Displacement) neighbour_list = get_neighbour_list(system) e₁ = compute_energy_particle(system, action.i, neighbour_list) + update_position!(system, action) - c, c2 = old_new_cell(system, action.i, neighbour_list) - if c != c2 - update_neighbour_list!(action.i, c, c2, neighbour_list) - end + update_neighbour_list!(system, action.i, neighbour_list) + e₂ = compute_energy_particle(system, action.i, neighbour_list) action.δe = e₂ - e₁ return e₁, e₂ @@ -78,10 +77,7 @@ function Arianna.revert_action!(system::Particles, action::Displacement) update_position!(system, action) neighbour_list = get_neighbour_list(system) system.energy[1] -= action.δe - c, c2 = old_new_cell(system, action.i, neighbour_list) - if c != c2 - update_neighbour_list!(action.i, c, c2, neighbour_list) - end + update_neighbour_list!(system, action.i, neighbour_list) end """ diff --git a/src/neighbours.jl b/src/neighbours.jl index 0d8e498..c737ba1 100644 --- a/src/neighbours.jl +++ b/src/neighbours.jl @@ -30,17 +30,10 @@ end """No-op update for `EmptyList`. """ -function update_neighbour_list!(i, c, c2, ::EmptyList) +function update_neighbour_list!(system::Particles, ::Int, ::EmptyList) return nothing end -"""Return placeholder old and new cell indices for `EmptyList`. - -Always returns (1,1) as no cells are tracked. -""" -function old_new_cell(::Particles, i, ::EmptyList) - return 1, 1 -end """Calling an EmptyList objects return an object which can be iterated upon. @@ -169,6 +162,12 @@ function update_neighbour_list!(i, c, c2, neighbour_list::CellList) return nothing end +function update_neighbour_list!(system::Particles, i::Int, neighbour_list::CellList) + c, c2 = old_new_cell(system, i, neighbour_list) + if c != c2 + update_neighbour_list!(i, c, c2, neighbour_list) + end +end @@ -295,6 +294,13 @@ function update_neighbour_list!(i::Int, c::Int, c2::Int, neighbour_list::LinkedL return nothing end +function update_neighbour_list!(system::Particles, i::Int, neighbour_list::LinkedList) + c, c2 = old_new_cell(system, i, neighbour_list) + if c != c2 + update_neighbour_list!(i, c, c2, neighbour_list) + end +end + """Return old and new cell indices for particle `i` using a `LinkedList` neighbour list. """ function old_new_cell(system::Particles, i, neighbour_list::LinkedList)