Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make max_points_per_cell work with templates #76

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 14 additions & 4 deletions src/cell_lists/full_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ function FullGridCellList(; min_corner, max_corner, search_radius = 0.0,
# Pad domain to avoid 0 in cell indices due to rounding errors.
# We can't just use `eps()`, as one might use lower precision types.
# This padding is safe, and will give us one more layer of cells in the worst case.
min_corner = SVector(Tuple(min_corner .- 1e-3 * search_radius))
max_corner = SVector(Tuple(max_corner .+ 1e-3 * search_radius))
min_corner = SVector(Tuple(min_corner .- 1.0f-3 * search_radius))
max_corner = SVector(Tuple(max_corner .+ 1.0f-3 * search_radius))
efaulhaber marked this conversation as resolved.
Show resolved Hide resolved

if search_radius < eps()
# Create an empty "template" cell list to be used with `copy_cell_list`
cells = construct_backend(backend, 0, 0)
cells = construct_backend(backend, 0, max_points_per_cell)
linear_indices = nothing
else
# Note that we don't shift everything so that the first cell starts at `min_corner`.
Expand Down Expand Up @@ -180,5 +180,15 @@ function copy_cell_list(cell_list::FullGridCellList, search_radius, periodic_box
(; min_corner, max_corner) = cell_list

return FullGridCellList(; min_corner, max_corner, search_radius,
backend = typeof(cell_list.cells))
backend = typeof(cell_list.cells),
max_points_per_cell = max_points_per_cell(cell_list.cells))
end

function max_points_per_cell(cells::DynamicVectorOfVectors)
return size(cells.backend, 1)
end

# Fallback when backend is a `Vector{Vector{T}}`
function max_points_per_cell(cells)
return 100
end
6 changes: 6 additions & 0 deletions src/nhs_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ function initialize_grid!(neighborhood_search::GridNeighborhoodSearch, y::Abstra

empty!(cell_list)

if neighborhood_search.search_radius < eps()
# Cannot initialize with zero search radius.
# This is used in TrixiParticles when a neighborhood search is not used.
return neighborhood_search
end

for point in axes(y, 2)
# Get cell index of the point's cell
point_coords = extract_svector(y, Val(ndims(neighborhood_search)), point)
Expand Down
4 changes: 3 additions & 1 deletion test/nhs_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@

# Check that the update strategy is preserved
nhs = GridNeighborhoodSearch{2}(cell_list = FullGridCellList(; min_corner,
max_corner),
max_corner,
max_points_per_cell = 101),
update_strategy = SerialUpdate())
copy = copy_neighborhood_search(nhs, 1.0, 10)

@test copy.update_strategy == SerialUpdate()
@test size(copy.cell_list.cells.backend, 1) == 101
end

@testset "Cells at Coordinate Limits" begin
Expand Down