@@ -9,7 +9,7 @@ struct Atoms{D, Q, V<:AbstractVector, C<:NeighbourList, H, T<:AbstractFloat, SM<
99 d:: Int
1010 box:: SVector{D,T}
1111 local_energy:: MVector{Q, T}
12- cell_list :: C
12+ neighbour_list :: C
1313 species_list:: H
1414end
1515
@@ -23,11 +23,11 @@ function System(position, species, density::T, temperature::T, model_matrix; lis
2323 local_energy = MVector {N, T} (zeros (T, N))
2424 indices = MVector {N, Bool} (falses (N))
2525 maxcut = maximum ([model. rcut for model in model_matrix])
26- cell_list = list_type (box, maxcut, N)
26+ neighbour_list = list_type (box, maxcut, N)
2727 species_list = isa (species[1 ], Integer) ? SpeciesList (species) : nothing
28- system = Atoms (position, species, density, energy, temperature, model_matrix, N, d, box, local_energy, cell_list , species_list)
29- build_cell_list ! (system)
30- system. local_energy .= [compute_local_energy (system, i) for i in eachindex (system)]
28+ system = Atoms (position, species, density, energy, temperature, model_matrix, N, d, box, local_energy, neighbour_list , species_list)
29+ build_neighbour_list ! (system)
30+ system. local_energy .= [compute_energy_particle (system, i) for i in eachindex (system)]
3131 system. energy[1 ] = sum (system. local_energy) / 2
3232 return system
3333end
@@ -47,11 +47,11 @@ function compute_energy_ij(system::Atoms, position_i, position_j, model_ij::Mode
4747 return potential (r2, model_ij)
4848end
4949
50- function compute_local_energy (system:: Atoms , i)
51- return compute_local_energy (system, i, system. cell_list )
50+ function compute_energy_particle (system:: Atoms , i)
51+ return compute_energy_particle (system, i, system. neighbour_list )
5252end
5353
54- function compute_local_energy (system:: Atoms , i, :: EmptyList )
54+ function compute_energy_particle (system:: Atoms , i, :: EmptyList )
5555 energy_i = zero (typeof (system. density))
5656 position_i = get_position (system, i)
5757 for (j, _) in enumerate (system)
@@ -61,140 +61,37 @@ function compute_local_energy(system::Atoms, i, ::EmptyList)
6161end
6262
6363
64- function destroy_particle! (system:: Atoms , i, :: EmptyList )
64+ function compute_energy_particle (system:: Atoms , i, neighbour_list :: CellList )
6565 energy_i = zero (typeof (system. density))
6666 position_i = get_position (system, i)
67- # Loop over particles
68- @inbounds for (j, _) in enumerate (system)
69- energy_ij = check_compute_energy_ij (system, i, j, position_i)
70- energy_i += energy_ij
71- end
72- return energy_i
73- end
74-
75- function create_particle! (system:: Atoms , i, :: EmptyList )
76- energy_i = zero (typeof (system. density))
77- position_i = get_position (system, i)
78- # Loop over particles
79- @inbounds for (j, position_j) in enumerate (system)
80- energy_ij = check_compute_energy_ij (system, i, j, position_i)
81- energy_i += energy_ij
82- end
83- return energy_i
84- end
67+ c = get_cell_index (position_i, neighbour_list)
68+ neighbour_cells = neighbour_list. neighbour_cells[c]
8569
86- function compute_local_energy (system:: Atoms , i, cell_list:: CellList )
87- energy_i = zero (typeof (system. density))
88- position_i = get_position (system, i)
89- mc = get_cell (position_i, cell_list)
90- # Scan the neighbourhood of cell mc (including itself)
91- @inbounds for mc2 in Iterators. product (map (x -> x- 1 : x+ 1 , mc)... )
92- # Calculate the scalar cell index of the neighbour cell (with PBC)
93- c2 = cell_index (cell_list, mc2)
94- # Scan atoms in cell c2
95- @inbounds for j in cell_list. cells[c2]
96- energy_i += check_compute_energy_ij (system, i, j, position_i)
97- end
98- end
99- return energy_i
100- end
101-
102- # With linked list
103- function destroy_particle! (system:: Atoms , i, cell_list:: CellList )
104- # Get cell of particle i
105- energy_i = zero (typeof (system. density))
106- position_i = get_position (system, i)
107- mc = get_cell (position_i, cell_list)
108- # Scan the neighbourhood of cell mc (including itself)
109- @inbounds for mc2 in Iterators. product (map (x -> x- 1 : x+ 1 , mc)... )
110- # Calculate the scalar cell index of the neighbour cell (with PBC)
111- c2 = cell_index (cell_list, mc2)
112- # Scan atoms in cell c2
113- neighbours = cell_list. cells[c2]
114- @inbounds for j in neighbours
115- energy_ij = check_compute_energy_ij (system, i, j, position_i)
116- energy_i += energy_ij
117- end
118- end
119- return energy_i
120- end
121-
122- function create_particle! (system:: Atoms , i, cell_list:: CellList )
123- energy_i = zero (typeof (system. density))
124- # Get cell of particle i
125- position_i = get_position (system, i)
126- mc = get_cell (position_i, cell_list)
12770 # Scan the neighbourhood of cell mc (including itself)
128- @inbounds for mc2 in Iterators. product (map (x -> x- 1 : x+ 1 , mc)... )
129- # Calculate the scalar cell index of the neighbour cell (with PBC)
130- c2 = cell_index (cell_list, mc2)
71+ @inbounds for c2 in neighbour_cells
13172 # Scan atoms in cell c2
132- neighbours = cell_list . cells[c2]
73+ neighbours = neighbour_list . cells[c2]
13374 @inbounds for j in neighbours
134- energy_ij = check_compute_energy_ij (system, i, j, position_i)
135- energy_i += energy_ij
136- end
137- end
138- return energy_i
139- end
140-
141-
142- function compute_local_energy (system:: Atoms , i, cell_list:: LinkedList )
143- energy_i = zero (typeof (system. density))
144- # Get cell of particle i
145- position_i = get_position (system, i)
146- mc = get_cell (position_i, cell_list)
147- # Scan the neighbourhood of cell mc (including itself)
148- @inbounds for mc2 in Iterators. product (map (x -> x- 1 : x+ 1 , mc)... )
149- # Calculate the scalar cell index of the neighbour cell (with PBC)
150- c2 = cell_index (cell_list, mc2)
151- # Scan atoms in cell c2
152- j = cell_list. head[c2]
153- while (j != - 1 )
154- energy_ij = check_compute_energy_ij (system, i, j, position_i)
155- energy_i += energy_ij
156- j = cell_list. list[j]
157- end
158- end
159- return energy_i
160- end
161-
162-
163- function destroy_particle! (system:: Atoms , i, cell_list:: LinkedList )
164- energy_i = zero (typeof (system. density))
165- # Get cell of particle i
166- position_i = get_position (system, i)
167- mc = get_cell (position_i, cell_list)
168- # Scan the neighbourhood of cell mc (including itself)
169- @inbounds for mc2 in Iterators. product (map (x -> x- 1 : x+ 1 , mc)... )
170- # Calculate the scalar cell index of the neighbour cell (with PBC)
171- c2 = cell_index (cell_list, mc2)
172- # Scan atoms in cell c2
173- j = cell_list. head[c2]
174- while (j != - 1 )
175- energy_ij = check_compute_energy_ij (system, i, j, position_i)
176- energy_i += energy_ij
177- j = cell_list. list[j]
75+ energy_i += check_compute_energy_ij (system, i, j, position_i)
17876 end
17977 end
18078 return energy_i
18179end
18280
183- function create_particle! (system:: Atoms , i, cell_list :: LinkedList )
81+ function compute_energy_particle (system:: Atoms , i, neighbour_list :: LinkedList )
18482 energy_i = zero (typeof (system. density))
18583 # Get cell of particle i
18684 position_i = get_position (system, i)
187- mc = get_cell (position_i, cell_list)
85+ c = get_cell_index (position_i, neighbour_list)
86+ neighbour_cells = neighbour_list. neighbour_cells[c]
18887 # Scan the neighbourhood of cell mc (including itself)
189- @inbounds for mc2 in Iterators. product (map (x -> x- 1 : x+ 1 , mc)... )
190- # Calculate the scalar cell index of the neighbour cell (with PBC)
191- c2 = cell_index (cell_list, mc2)
88+ @inbounds for c2 in neighbour_cells
19289 # Scan atoms in cell c2
193- j = cell_list . head[c2]
90+ j = neighbour_list . head[c2]
19491 while (j != - 1 )
19592 energy_ij = check_compute_energy_ij (system, i, j, position_i)
19693 energy_i += energy_ij
197- j = cell_list . list[j]
94+ j = neighbour_list . list[j]
19895 end
19996 end
20097 return energy_i
0 commit comments