Skip to content

Commit c5292dd

Browse files
authored
Add docs for initialize! and update! (#22)
* Add docs for `initialize!` and `update!` * Implement suggestions
1 parent c705ca5 commit c5292dd

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/neighborhood_search.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
abstract type AbstractNeighborhoodSearch end
2+
3+
"""
4+
initialize!(search::AbstractNeighborhoodSearch, x, y)
5+
6+
Initialize a neighborhood search with the two coordinate arrays `x` and `y`.
7+
8+
In general, the purpose of a neighborhood search is to find for one point in `x`
9+
all points in `y` whose distances to that point are smaller than the search radius.
10+
`x` and `y` are expected to be matrices, where the `i`-th column contains the coordinates
11+
of point `i`. Note that `x` and `y` can be identical.
12+
13+
See also [`update!`](@ref).
14+
"""
15+
@inline initialize!(search::AbstractNeighborhoodSearch, x, y) = search
16+
17+
"""
18+
update!(search::AbstractNeighborhoodSearch, x, y; particles_moving = (true, true))
19+
20+
Update an already initialized neighborhood search with the two coordinate arrays `x` and `y`.
21+
22+
Like [`initialize!`](@ref), but reusing the existing data structures of the already
23+
initialized neighborhood search.
24+
When the points only moved a small distance since the last `update!` or `initialize!`,
25+
this is significantly faster than `initialize!`.
26+
27+
Not all implementations support incremental updates.
28+
If incremental updates are not possible for an implementation, `update!` will fall back
29+
to a regular `initialize!`.
30+
31+
Some neighborhood searches might not need to update when only `x` changed since the last
32+
`update!` or `initialize!` and `y` did not change. Pass `particles_moving = (true, false)`
33+
in this case to avoid unnecessary updates.
34+
The first flag in `particles_moving` indicates if points in `x` are moving.
35+
The second flag indicates if points in `y` are moving.
36+
37+
See also [`initialize!`](@ref).
38+
"""
39+
@inline function update!(search::AbstractNeighborhoodSearch, x, y;
40+
particles_moving = (true, true))
41+
return search
42+
end
43+
144
struct PeriodicBox{NDIMS, ELTYPE}
245
min_corner :: SVector{NDIMS, ELTYPE}
346
max_corner :: SVector{NDIMS, ELTYPE}

src/nhs_grid.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ since not sorting makes our implementation a lot faster (although less paralleli
4848
In: Computer Graphics Forum 30.1 (2011), pages 99–112.
4949
[doi: 10.1111/J.1467-8659.2010.01832.X](https://doi.org/10.1111/J.1467-8659.2010.01832.X)
5050
"""
51-
struct GridNeighborhoodSearch{NDIMS, ELTYPE, PB}
51+
struct GridNeighborhoodSearch{NDIMS, ELTYPE, PB} <: AbstractNeighborhoodSearch
5252
hashtable :: Dict{NTuple{NDIMS, Int}, Vector{Int}}
5353
search_radius :: ELTYPE
5454
empty_vector :: Vector{Int} # Just an empty vector (used in `eachneighbor`)

src/nhs_trivial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal function `eachneighbor`.
1919
coordinates of the domain corner in positive coordinate
2020
directions.
2121
"""
22-
struct TrivialNeighborhoodSearch{NDIMS, ELTYPE, EP, PB}
22+
struct TrivialNeighborhoodSearch{NDIMS, ELTYPE, EP, PB} <: AbstractNeighborhoodSearch
2323
search_radius :: ELTYPE
2424
eachparticle :: EP
2525
periodic_box :: PB

0 commit comments

Comments
 (0)