Refactor type arguments to compute cell_index

This commit is contained in:
Alex Selimov 2025-09-25 20:06:29 -04:00
parent d957a90573
commit cd4a00ebed
Signed by: aselimov
GPG key ID: 3DDB9C3E023F1F31
2 changed files with 6 additions and 3 deletions

View file

@ -55,8 +55,10 @@ struct CellList {
// TODO; Maybe update this to use Morton Encodings in the future to improve
// locality of particle indices. Unclear how much of a benefit this will add,
// but would be cool to do
__host__ __device__ int get_cell_index(int x, int y, int z) const {
return z * grid_size.x * grid_size.y + y * grid_size.x + x;
__host__ __device__ int
get_cell_index_from_cell_coords(int3 cell_coords) const {
return cell_coords.z * grid_size.x * grid_size.y +
cell_coords.y * grid_size.x + cell_coords.x;
}
std::pair<int3, float3> calc_grid_and_cell_size(Box &box,

View file

@ -27,5 +27,6 @@ TEST(CellListTest, GetCellIndex) {
int expected_index = z * cell_list.grid_size.x * cell_list.grid_size.y +
y * cell_list.grid_size.x + x;
EXPECT_EQ(cell_list.get_cell_index(x, y, z), expected_index);
EXPECT_EQ(cell_list.get_cell_index_from_cell_coords({x, y, z}),
expected_index);
}