Skip to content

Commit 5f54430

Browse files
committed
Add perform action wrapper
1 parent 5b16e53 commit 5f54430

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/moves.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
using ComponentArrays
22

3+
function Arianna.perform_action!(system::Particles, action::Action)
4+
e₁, e₂ = perform_action!(system, action)
5+
if isinf(e₁) || isinf(e₂)
6+
action.δe = zero(typeof(system.energy[1]))
7+
else
8+
action.δe = e₂ - e₁
9+
system.energy[1] += action.δe
10+
end
11+
return e₁, e₂
12+
end
13+
314
###############################################################################
415
# SIMPLE DISPLACEMENT
516

@@ -22,7 +33,7 @@ function update_position!(system::Particles, action::Displacement)
2233
@inbounds system.position[action.i] = system.position[action.i] + action.δ
2334
end
2435

25-
function Arianna.perform_action!(system::Particles, action::Displacement)
36+
function perform_action!(system::Particles, action::Displacement)
2637
neighbour_list = get_neighbour_list(system)
2738
e₁ = destroy_particle!(system, action.i, neighbour_list)
2839
update_position!(system, action)
@@ -32,7 +43,6 @@ function Arianna.perform_action!(system::Particles, action::Displacement)
3243
end
3344
e₂ = create_particle!(system, action.i, neighbour_list)
3445
action.δe = e₂ - e₁
35-
system.energy[1] += action.δe
3646
return e₁, e₂
3747
end
3848

@@ -92,12 +102,11 @@ function update_species_list!(species_list, swap_species, i, j)
92102
species_list.sp_heads[i], species_list.sp_heads[j] = species_list.sp_heads[j], species_list.sp_heads[i]
93103
end
94104

95-
function Arianna.perform_action!(system::Particles, action::DiscreteSwap)
105+
function perform_action!(system::Particles, action::DiscreteSwap)
96106
i, j = action.i, action.j
97107
spi, spj = get_species(system, i), get_species(system, j)
98108
e₁, e₂ = swap_particle_species!(system, spi, i, spj, j)
99109
action.δe = e₂ - e₁
100-
system.energy[1] += action.δe
101110
update_species_list!(system.species_list, action.species, i, j)
102111
return e₁, e₂
103112
end
@@ -157,12 +166,11 @@ mutable struct MoleculeFlip{F<:AbstractFloat} <: Action
157166
δe::F
158167
end
159168

160-
function Arianna.perform_action!(system::Particles, action::MoleculeFlip)
169+
function perform_action!(system::Particles, action::MoleculeFlip)
161170
i, j = action.i, action.j
162171
spi, spj = system.species[i], system.species[j]
163172
e₁, e₂ = swap_particle_species!(system, spi, i, spj, j)
164173
action.δe = e₂ - e₁
165-
system.energy[1] += action.δe
166174
return e₁, e₂
167175
end
168176

0 commit comments

Comments
 (0)