@@ -95,13 +95,45 @@ struct PeriodicBox{NDIMS, ELTYPE}
9595 end
9696end
9797
98- # The type annotation is to make Julia specialize on the type of the function.
99- # Otherwise, unspecialized code will cause a lot of allocations
100- # and heavily impact performance.
101- # See https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing
98+ """
99+ foreach_point_neighbor(f, system_coords, neighbor_coords, neighborhood_search;
100+ points = axes(system_coords, 2), parallel = true)
101+
102+ Loop for each point in `system_coords` over all points in `neighbor_coords` whose distances
103+ to that point are smaller than the search radius and execute the function `f(i, j, x, y, d)`,
104+ where
105+ - `i` is the column index of the point in `system_coords`,
106+ - `j` the column index of the neighbor in `neighbor_coords`,
107+ - `x` an `SVector` of the coordinates of the point (`system_coords[:, i]`),
108+ - `y` an `SVector` of the coordinates of the neighbor (`neighbor_coords[:, j]`),
109+ - `d` the distance between `x` and `y`.
110+
111+ The `neighborhood_search` must have been initialized or updated with `system_coords`
112+ as first coordinate array and `neighbor_coords` as second coordinate array.
113+
114+ Note that `system_coords` and `neighbor_coords` can be identical.
115+
116+ # Arguments
117+ - `f`: The function explained above.
118+ - `system_coords`: A matrix where the `i`-th column contains the coordinates of point `i`.
119+ - `neighbor_coords`: A matrix where the `j`-th column contains the coordinates of point `j`.
120+ - `neighborhood_search`: A neighborhood search initialized or updated with `system_coords`
121+ as first coordinate array and `neighbor_coords` as second
122+ coordinate array.
123+
124+ # Keywords
125+ - `points`: Loop over these point indices. By default all columns of `system_coords`.
126+ - `parallel=true`: Run the outer loop over `points` thread-parallel.
127+
128+ See also [`initialize!`](@ref), [`update!`](@ref).
129+ """
102130function foreach_point_neighbor (f:: T , system_coords, neighbor_coords, neighborhood_search;
103131 points = axes (system_coords, 2 ),
104132 parallel = true ) where {T}
133+ # The type annotation above is to make Julia specialize on the type of the function.
134+ # Otherwise, unspecialized code will cause a lot of allocations
135+ # and heavily impact performance.
136+ # See https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing
105137 foreach_point_neighbor (f, system_coords, neighbor_coords, neighborhood_search, points,
106138 Val (parallel))
107139end
0 commit comments