11@doc raw """
2- GridNeighborhoodSearch{NDIMS}(search_radius, n_points;
3- periodic_box = nothing, threaded_nhs_update = true)
2+ GridNeighborhoodSearch{NDIMS}(; search_radius = 0.0 , n_points = 0,
3+ periodic_box = nothing, threaded_update = true)
44
55Simple grid-based neighborhood search with uniform search radius.
66The domain is divided into a regular grid.
@@ -23,17 +23,19 @@ As opposed to (Ihmsen et al. 2011), we do not sort the points in any way,
2323since not sorting makes our implementation a lot faster (although less parallelizable).
2424
2525# Arguments
26- - `NDIMS`: Number of dimensions.
27- - `search_radius`: The uniform search radius.
28- - `n_points`: Total number of points.
26+ - `NDIMS`: Number of dimensions.
2927
3028# Keywords
29+ - `search_radius = 0.0`: The fixed search radius. The default of `0.0` is useful together
30+ with [`copy_neighborhood_search`](@ref).
31+ - `n_points = 0`: Total number of points. The default of `0` is useful together
32+ with [`copy_neighborhood_search`](@ref).
3133- `periodic_box = nothing`: In order to use a (rectangular) periodic domain, pass a
3234 [`PeriodicBox`](@ref).
33- - `threaded_nhs_update = true`: Can be used to deactivate thread parallelization in the
34- neighborhood search update. This can be one of the largest
35- sources of variations between simulations with different
36- thread numbers due to neighbor ordering changes.
35+ - `threaded_update = true`: Can be used to deactivate thread parallelization in the
36+ neighborhood search update. This can be one of the largest
37+ sources of variations between simulations with different
38+ thread numbers due to neighbor ordering changes.
3739
3840## References
3941- M. Chalela, E. Sillero, L. Pereyra, M.A. Garcia, J.B. Cabral, M. Lares, M. Merchán.
@@ -53,11 +55,11 @@ struct GridNeighborhoodSearch{NDIMS, ELTYPE, CL, PB} <: AbstractNeighborhoodSear
5355 cell_size :: NTuple{NDIMS, ELTYPE} # Required to calculate cell index
5456 cell_buffer :: Array{NTuple{NDIMS, Int}, 2} # Multithreaded buffer for `update!`
5557 cell_buffer_indices :: Vector{Int} # Store which entries of `cell_buffer` are initialized
56- threaded_nhs_update :: Bool
58+ threaded_update :: Bool
5759
58- function GridNeighborhoodSearch {NDIMS} (search_radius, n_points;
60+ function GridNeighborhoodSearch {NDIMS} (; search_radius = 0.0 , n_points = 0 ,
5961 periodic_box = nothing ,
60- threaded_nhs_update = true ) where {NDIMS}
62+ threaded_update = true ) where {NDIMS}
6163 ELTYPE = typeof (search_radius)
6264 cell_list = DictionaryCellList {NDIMS} ()
6365
@@ -87,7 +89,7 @@ struct GridNeighborhoodSearch{NDIMS, ELTYPE, CL, PB} <: AbstractNeighborhoodSear
8789 new{NDIMS, ELTYPE, typeof (cell_list),
8890 typeof (periodic_box)}(cell_list, search_radius, periodic_box, n_cells,
8991 cell_size, cell_buffer, cell_buffer_indices,
90- threaded_nhs_update )
92+ threaded_update )
9193 end
9294end
9395
@@ -141,14 +143,14 @@ end
141143
142144# Modify the existing hash table by moving points into their new cells
143145function update_grid! (neighborhood_search:: GridNeighborhoodSearch , coords_fun)
144- (; cell_list, cell_buffer, cell_buffer_indices, threaded_nhs_update ) = neighborhood_search
146+ (; cell_list, cell_buffer, cell_buffer_indices, threaded_update ) = neighborhood_search
145147
146148 # Reset `cell_buffer` by moving all pointers to the beginning
147149 cell_buffer_indices .= 0
148150
149151 # Find all cells containing points that now belong to another cell
150152 mark_changed_cell! (neighborhood_search, cell_list, coords_fun,
151- Val (threaded_nhs_update ))
153+ Val (threaded_update ))
152154
153155 # Iterate over all marked cells and move the points into their new cells.
154156 for thread in 1 : Threads. nthreads ()
@@ -180,15 +182,15 @@ function update_grid!(neighborhood_search::GridNeighborhoodSearch, coords_fun)
180182end
181183
182184@inline function mark_changed_cell! (neighborhood_search, cell_list, coords_fun,
183- threaded_nhs_update :: Val{true} )
185+ threaded_update :: Val{true} )
184186 # `collect` the keyset to be able to loop over it with `@threaded`
185187 @threaded for cell in collect (eachcell (cell_list))
186188 mark_changed_cell! (neighborhood_search, cell, coords_fun)
187189 end
188190end
189191
190192@inline function mark_changed_cell! (neighborhood_search, cell_list, coords_fun,
191- threaded_nhs_update :: Val{false} )
193+ threaded_update :: Val{false} )
192194 for cell in eachcell (cell_list)
193195 mark_changed_cell! (neighborhood_search, cell, coords_fun)
194196 end
307309 return floor (Int, i)
308310end
309311
310- # Create a copy of a neighborhood search but with a different search radius
311- function copy_neighborhood_search (nhs:: GridNeighborhoodSearch , search_radius, x, y)
312- search = GridNeighborhoodSearch {ndims(nhs)} (search_radius, npoints (nhs),
313- periodic_box = nhs. periodic_box)
314-
315- # Initialize neighborhood search
316- initialize! (search, x, y)
317-
318- return search
312+ function copy_neighborhood_search (nhs:: GridNeighborhoodSearch , search_radius, n_points;
313+ eachpoint = 1 : n_points)
314+ return GridNeighborhoodSearch {ndims(nhs)} (; search_radius, n_points,
315+ periodic_box = nhs. periodic_box,
316+ threaded_update = nhs. threaded_update)
319317end
0 commit comments