Skip to content

Commit 1330422

Browse files
authored
Update docs and add descriptive error message (#128)
1 parent edf29bb commit 1330422

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/cell_lists/full_grid.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
2-
FullGridCellList(; min_corner, max_corner, search_radius = 0.0,
3-
periodicity = false, backend = DynamicVectorOfVectors{Int32},
2+
FullGridCellList(; min_corner, max_corner,
3+
search_radius = zero(eltype(min_corner)),
4+
backend = DynamicVectorOfVectors{Int32},
45
max_points_per_cell = 100)
56
67
A simple cell list implementation where each (empty or non-empty) cell of a rectangular
@@ -15,12 +16,8 @@ See [`copy_neighborhood_search`](@ref) for more details.
1516
# Keywords
1617
- `min_corner`: Coordinates of the domain corner in negative coordinate directions.
1718
- `max_corner`: Coordinates of the domain corner in positive coordinate directions.
18-
- `search_radius = 0.0`: Search radius of the neighborhood search, which will determine the
19-
cell size. Use the default of `0.0` to create a template (see above).
20-
- `periodicity = false`: Set to `true` when using a [`PeriodicBox`](@ref) with the
21-
neighborhood search. When using [`copy_neighborhood_search`](@ref),
22-
this option can be ignored an will be set automatically depending
23-
on the periodicity of the neighborhood search.
19+
- `search_radius`: Search radius of the neighborhood search, which will determine the
20+
cell size. Use the default of zero to create a template (see above).
2421
- `backend = DynamicVectorOfVectors{Int32}`: Type of the data structure to store the actual
2522
cell lists. Can be
2623
- `Vector{Vector{Int32}}`: Scattered memory, but very memory-efficient.

src/neighborhood_search.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ struct PeriodicBox{NDIMS, ELTYPE}
131131
end
132132
end
133133

134+
@inline Base.eltype(::PeriodicBox{<:Any, ELTYPE}) where {ELTYPE} = ELTYPE
135+
134136
"""
135137
foreach_point_neighbor(f, system_coords, neighbor_coords, neighborhood_search;
136138
parallelization_backend = default_backend(system_coords),

src/nhs_grid.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ since not sorting makes our implementation a lot faster (although less paralleli
5353
"A Parallel SPH Implementation on Multi-Core CPUs".
5454
In: Computer Graphics Forum 30.1 (2011), pages 99–112.
5555
[doi: 10.1111/J.1467-8659.2010.01832.X](https://doi.org/10.1111/J.1467-8659.2010.01832.X)
56+
57+
!!! note "Note"
58+
The type of `search_radius` determines the type used for the internals of the
59+
neighborhood search.
60+
When working with single precision, the `search_radius` must be `Float32` in order
61+
to avoid the use of double precision values (for example when working with GPUs).
62+
When using a `periodic_box`, its type must match the type of the `search_radius`.
5663
"""
5764
struct GridNeighborhoodSearch{NDIMS, US, CL, ELTYPE, PB, UB} <: AbstractNeighborhoodSearch
5865
cell_list :: CL
@@ -84,6 +91,11 @@ function GridNeighborhoodSearch{NDIMS}(; search_radius = 0.0, n_points = 0,
8491
n_cells = ntuple(_ -> -1, Val(NDIMS))
8592
cell_size = ntuple(_ -> search_radius, Val(NDIMS))
8693
else
94+
if typeof(search_radius) != eltype(periodic_box)
95+
throw(ArgumentError("the `search_radius` and the `PeriodicBox` must have " *
96+
"the same element type"))
97+
end
98+
8799
# Round up search radius so that the grid fits exactly into the domain without
88100
# splitting any cells. This might impact performance slightly, since larger
89101
# cells mean that more potential neighbors are considered than necessary.

0 commit comments

Comments
 (0)