Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/moves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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₂
Expand All @@ -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

"""
Expand Down
22 changes: 14 additions & 8 deletions src/neighbours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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



Expand Down Expand Up @@ -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)
Expand Down