Skip to content

Commit

Permalink
Add NaN check
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Dec 23, 2024
1 parent a6682d4 commit afd2fba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/cell_lists/full_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ function max_points_per_cell(cells)
end

function check_domain_bounds(cell_list::FullGridCellList, y, search_radius)
if any(isnan, y)
error("particle coordinates contain NaNs")
end

# Require one extra layer in each direction to make sure neighbor cells exist
min_corner = minimum(y, dims = 2) .- search_radius
max_corner = maximum(y, dims = 2) .+ search_radius
Expand Down
17 changes: 13 additions & 4 deletions test/cell_lists/full_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@

nhs = GridNeighborhoodSearch{N}(; cell_list, search_radius)
y = rand(N, 10)
error_nan = ErrorException("particle coordinates contain NaNs")
error_string_bounds = "particle coordinates are outside the domain bounds of the cell list"
error_bounds = ErrorException(error_string_bounds)

y[1, 7] = NaN
@test_throws error_nan initialize!(nhs, y, y)

y[1, 7] = -0.01
@test_throws ErrorException initialize!(nhs, y, y)
@test_throws error_bounds initialize!(nhs, y, y)

y[1, 7] = 10.01
@test_throws ErrorException initialize!(nhs, y, y)
@test_throws error_bounds initialize!(nhs, y, y)

y[1, 7] = 0.0
@test_nowarn_mod initialize!(nhs, y, y)
Expand All @@ -28,11 +34,14 @@
y[1, 7] = 10.0
@test_nowarn_mod update!(nhs, y, y)

y[1, 7] = NaN
@test_throws error_nan update!(nhs, y, y)

y[1, 7] = 10.01
@test_throws ErrorException update!(nhs, y, y)
@test_throws error_bounds update!(nhs, y, y)

y[1, 7] = -0.01
@test_throws ErrorException update!(nhs, y, y)
@test_throws error_bounds update!(nhs, y, y)
end
end
end

0 comments on commit afd2fba

Please sign in to comment.