11@doc raw """
2- GridNeighborhoodSearch{NDIMS}(search_radius, n_points; periodic_box_min_corner=nothing,
3- periodic_box_max_corner= nothing, threaded_nhs_update= true)
2+ GridNeighborhoodSearch{NDIMS}(search_radius, n_points;
3+ periodic_box = nothing, threaded_nhs_update = true)
44
55Simple grid-based neighborhood search with uniform search radius.
66The domain is divided into a regular grid.
@@ -28,15 +28,12 @@ since not sorting makes our implementation a lot faster (although less paralleli
2828- `n_points`: Total number of points.
2929
3030# Keywords
31- - `periodic_box_min_corner`: In order to use a (rectangular) periodic domain, pass the
32- coordinates of the domain corner in negative coordinate
33- directions.
34- - `periodic_box_max_corner`: In order to use a (rectangular) periodic domain, pass the
35- coordinates of the domain corner in positive coordinate
36- directions.
37- - `threaded_nhs_update=true`: Can be used to deactivate thread parallelization in the neighborhood search update.
38- This can be one of the largest sources of variations between simulations
39- with different thread numbers due to neighbor ordering changes.
31+ - `periodic_box = nothing`: In order to use a (rectangular) periodic domain, pass a
32+ [`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.
4037
4138## References
4239- M. Chalela, E. Sillero, L. Pereyra, M.A. Garcia, J.B. Cabral, M. Lares, M. Merchán.
@@ -59,25 +56,19 @@ struct GridNeighborhoodSearch{NDIMS, ELTYPE, CL, PB} <: AbstractNeighborhoodSear
5956 threaded_nhs_update :: Bool
6057
6158 function GridNeighborhoodSearch {NDIMS} (search_radius, n_points;
62- periodic_box_min_corner = nothing ,
63- periodic_box_max_corner = nothing ,
59+ periodic_box = nothing ,
6460 threaded_nhs_update = true ) where {NDIMS}
6561 ELTYPE = typeof (search_radius)
6662 cell_list = DictionaryCellList {NDIMS} ()
6763
6864 cell_buffer = Array {NTuple{NDIMS, Int}, 2} (undef, n_points, Threads. nthreads ())
6965 cell_buffer_indices = zeros (Int, Threads. nthreads ())
7066
71- if search_radius < eps () ||
72- (periodic_box_min_corner === nothing && periodic_box_max_corner === nothing )
73-
67+ if search_radius < eps () || isnothing (periodic_box)
7468 # No periodicity
75- periodic_box = nothing
7669 n_cells = ntuple (_ -> - 1 , Val (NDIMS))
7770 cell_size = ntuple (_ -> search_radius, Val (NDIMS))
78- elseif periodic_box_min_corner != = nothing && periodic_box_max_corner != = nothing
79- periodic_box = PeriodicBox (periodic_box_min_corner, periodic_box_max_corner)
80-
71+ else
8172 # Round up search radius so that the grid fits exactly into the domain without
8273 # splitting any cells. This might impact performance slightly, since larger
8374 # cells mean that more potential neighbors are considered than necessary.
@@ -91,9 +82,6 @@ struct GridNeighborhoodSearch{NDIMS, ELTYPE, CL, PB} <: AbstractNeighborhoodSear
9182 " in each dimension when used with periodicity. " *
9283 " Please use no NHS for very small problems." ))
9384 end
94- else
95- throw (ArgumentError (" `periodic_box_min_corner` and `periodic_box_max_corner` " *
96- " must either be both `nothing` or both an array or tuple" ))
9785 end
9886
9987 new{NDIMS, ELTYPE, typeof (cell_list),
@@ -103,7 +91,7 @@ struct GridNeighborhoodSearch{NDIMS, ELTYPE, CL, PB} <: AbstractNeighborhoodSear
10391 end
10492end
10593
106- @inline Base. ndims (neighborhood_search :: GridNeighborhoodSearch{NDIMS} ) where {NDIMS} = NDIMS
94+ @inline Base. ndims (:: GridNeighborhoodSearch{NDIMS} ) where {NDIMS} = NDIMS
10795
10896@inline function npoints (neighborhood_search:: GridNeighborhoodSearch )
10997 return size (neighborhood_search. cell_buffer, 1 )
321309
322310# Create a copy of a neighborhood search but with a different search radius
323311function copy_neighborhood_search (nhs:: GridNeighborhoodSearch , search_radius, x, y)
324- if nhs. periodic_box === nothing
325- search = GridNeighborhoodSearch {ndims(nhs)} (search_radius, npoints (nhs))
326- else
327- search = GridNeighborhoodSearch {ndims(nhs)} (search_radius, npoints (nhs),
328- periodic_box_min_corner = nhs. periodic_box. min_corner,
329- periodic_box_max_corner = nhs. periodic_box. max_corner)
330- end
312+ search = GridNeighborhoodSearch {ndims(nhs)} (search_radius, npoints (nhs),
313+ periodic_box = nhs. periodic_box)
331314
332315 # Initialize neighborhood search
333316 initialize! (search, x, y)
0 commit comments