Open fritzio opened 3 months ago
Hi @mmacklin
In the hash_grid_query
function, the start coordinates for neighboring cells are not correctly converted for cells adjacent to the origin, i.e., if the own cell index is zero, then pos[0]
< radius
(and equivalent for pos[1]
and pos[2]
) and the x_start
coordinates are not correctly converted. For example, query.x_start = int((pos[0]-radius)*query.grid.cell_width_inv);
gives for pos[0] = 0.5
and radius = 1.0
a value of 0, which is the cell itself and not -1.
I propose in hashgrid.h
to change
query.x_start = int((pos[0] - radius) * query.grid.cell_width_inv)
to
query.x_start = int((pos[0] - radius) * query.grid.cell_width_inv + query.grid.dim_x) - query.grid.dim_x
(and equivalent for the other start coordinates), which should produce the correct cell values. I think subtracting the grid dimension again is technically not needed, though.
@fritzio I believe flooring the double values before converting them to integers is the way to go. I have tested it out, and it gives me the correct number of neighbours:
query.x_start = int(floor((pos[0]-radius)*query.grid.cell_width_inv));
query.y_start = int(floor((pos[1]-radius)*query.grid.cell_width_inv));
query.z_start = int(floor((pos[2]-radius)*query.grid.cell_width_inv));
@mmacklin I just have one doubt regarding this, can x_start
have negative integers?
Bug Description
The
HashGrid
does not correctly traverse cells through the periodic boundary condition. It does for particles close to the right edge - but not for particles in the vicinity of the left edge though.Below you find a working example, which allocates particles in the center of the cells and counts the number of neighboring cells using the
HashGrid
. It should produce aneighbor_count
of 27 for every particle. However, particles close to the origin only have 8 neighboring particles. It seems that cells are only visited through the upper boundary - but not through the lower boundary.If something is not correct from our side in the code sample, please let us know.
System Information
Warp version: 1.3.0 CUDA version: 12.5 OS: Ubuntu 22.04 Python version: 3.12.4