Cleanup code slightly and implement tests for CellList
Some checks failed
Build and Test / build-and-test (push) Failing after 5m4s

This commit is contained in:
Alex Selimov 2025-09-19 23:46:21 -04:00
parent f3e701236e
commit d957a90573
Signed by: aselimov
GPG key ID: 3DDB9C3E023F1F31
4 changed files with 55 additions and 7 deletions

View file

@ -25,14 +25,16 @@ struct CellList {
size_t total_cells;
size_t n_particles;
CellList(size_t n_particles, Box &box, float cutoff)
CellList(size_t n_particles, Box &box, float r_cutoff)
: n_particles(n_particles) {
box_min.x = box.xlo;
box_min.y = box.ylo;
box_min.z = box.zlo;
auto [grid_size, cell_size] = calc_grid_and_cell_size(box, cutoff);
auto [grid_size, cell_size] = calc_grid_and_cell_size(box, r_cutoff);
this->grid_size = grid_size;
this->cell_size = cell_size;
total_cells = grid_size.x * grid_size.y * grid_size.z;
@ -50,14 +52,18 @@ struct CellList {
}
// Get cell index from 3D coordinates
__device__ int get_cell_index(int x, int y, int z) const {
// 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;
}
std::pair<int3, float3> calc_grid_and_cell_size(Box &box, float cutoff) {
int3 grid_size = {utils::max((int)(box.xhi - box.xlo) / cutoff, 1),
utils::max((int)(box.yhi - box.ylo) / cutoff, 1),
utils::max((int)(box.zhi - box.zlo) / cutoff, 1)};
std::pair<int3, float3> calc_grid_and_cell_size(Box &box,
float r_cutoff) const {
int3 grid_size = {utils::max((int)(box.xhi - box.xlo) / r_cutoff, 1),
utils::max((int)(box.yhi - box.ylo) / r_cutoff, 1),
utils::max((int)(box.zhi - box.zlo) / r_cutoff, 1)};
float3 cell_size = {
(box.xhi - box.xlo) / grid_size.x,