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
2 changes: 2 additions & 0 deletions src/cell_lists/dictionary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct DictionaryCellList{NDIMS} <: AbstractCellList
end
end

@inline Base.ndims(::DictionaryCellList{NDIMS}) where {NDIMS} = NDIMS

function supported_update_strategies(::DictionaryCellList)
return (SemiParallelUpdate, SerialIncrementalUpdate, SerialUpdate)
end
Expand Down
11 changes: 11 additions & 0 deletions src/cell_lists/full_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct FullGridCellList{C, LI, MINC, MAXC} <: AbstractCellList
max_corner :: MAXC
end

@inline Base.ndims(cell_list::FullGridCellList) = ndims(cell_list.linear_indices)

function supported_update_strategies(::FullGridCellList{<:DynamicVectorOfVectors})
return (ParallelIncrementalUpdate, ParallelUpdate, SemiParallelUpdate,
SerialIncrementalUpdate, SerialUpdate)
Expand All @@ -47,6 +49,15 @@ function FullGridCellList(; min_corner, max_corner,
search_radius = zero(eltype(min_corner)),
backend = DynamicVectorOfVectors{Int32},
max_points_per_cell = 100)
if length(min_corner) != length(max_corner)
throw(ArgumentError("min_corner and max_corner must have the same length"))
end

if length(min_corner) > 100
throw(ArgumentError("FullGridCellList only supports up to 100 dimensions, " *
"check your `min_corner` and `max_corner`"))
end
Comment thread
efaulhaber marked this conversation as resolved.
Comment thread
svchb marked this conversation as resolved.

# Add one layer in each direction to make sure neighbor cells exist.
# Also pad domain a little more to avoid 0 in cell indices due to rounding errors.
# We can't just use `eps()`, as one might use lower precision types.
Expand Down
5 changes: 5 additions & 0 deletions src/nhs_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ function GridNeighborhoodSearch{NDIMS}(; search_radius = 0.0, n_points = 0,
periodic_box = nothing,
cell_list = DictionaryCellList{NDIMS}(),
update_strategy = nothing) where {NDIMS}
if ndims(cell_list) != NDIMS
throw(ArgumentError("a $(NDIMS)D cell list is required for " *
"a GridNeighborhoodSearch{$(NDIMS)}"))
end

if isnothing(update_strategy)
# Automatically choose best available update option for this cell list
update_strategy = first(supported_update_strategies(cell_list))()
Expand Down
16 changes: 16 additions & 0 deletions test/cell_lists/full_grid.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
@testset "`FullGridCellList`" verbose=true begin
# Test that an error is thrown when too many dimensions are used
@testset "constructor" begin
min_corner = zeros(101)
max_corner = ones(101)
search_radius = 1.0

error_string = "FullGridCellList only supports up to 100 dimensions"
@test_throws error_string FullGridCellList(; min_corner, max_corner)
@test_throws error_string FullGridCellList(; min_corner, max_corner, search_radius)

min_corner = zeros(3)
max_corner = ones(2)
error_string = "min_corner and max_corner must have the same length"
@test_throws error_string FullGridCellList(; min_corner, max_corner)
end

# Test that `update!` throws an error when a particle is outside the bounding box
@testset "`update!` bounds check" begin
@testset "$(N)D" for N in 1:3
Expand Down
3 changes: 3 additions & 0 deletions test/nhs_grid.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@testset verbose=true "GridNeighborhoodSearch" begin
@testset "Constructor" begin
error_str = "a 2D cell list is required for a GridNeighborhoodSearch{2}"
@test_throws error_str GridNeighborhoodSearch{2}(cell_list = DictionaryCellList{3}())

error_str = "is not a valid update strategy"
@test_throws "test $error_str" GridNeighborhoodSearch{2}(update_strategy = :test)

Expand Down