Skip to content

Commit

Permalink
Fix whichcell to handle NaN value
Browse files Browse the repository at this point in the history
  • Loading branch information
KeitaNakamura committed Aug 3, 2024
1 parent c2ff73b commit c160020
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ CartesianIndex(2, 2)
whichcell(ξ, size(mesh))
end

@inline function whichcell::NTuple{dim}, gridsize::Dims{dim}) where {dim}
cell = CartesianIndex(@. unsafe_trunc(Int, floor(ξ)) + 1)
isinside = checkbounds(Bool, CartesianIndices(gridsize.-1), cell)
ifelse(isinside, cell, nothing)
@generated function whichcell::NTuple{dim, T}, gridsize::Dims{dim}) where {dim, T}
quote
@_inline_meta
index = map(floor, ξ)
isinside = @nall $dim d -> T(0) index[d] T(gridsize[d]-2)
ifelse(isinside, CartesianIndex(@. unsafe_trunc(Int, index) + 1), nothing)
end
end

0 comments on commit c160020

Please sign in to comment.