Skip to content

novaphy.SpatialHashGrid

Uniform spatial hash grid used by SPH-style neighbor queries. Maps particle positions to a sparse cell grid keyed by integer hash; cell size should match the SPH kernel support radius for best performance.

Constructor

SpatialHashGrid(cell_size: float = 0.1)
Parameter Description
cell_size Grid cell size [m]. Set this to the SPH kernel radius.

Methods

Method Description
build(positions) Rebuild the grid from a list of particle positions.
query_neighbors(point, radius) Return indices of particles within radius of point.
clear() Drop all grid data.

Properties

Property Description
cell_size Grid cell size [m] (read / write). Mutating this invalidates the build — call build again afterwards.

Example

import numpy as np
import novaphy

grid = novaphy.SpatialHashGrid(cell_size=0.1)
positions = [np.array([i * 0.05, 0, 0], dtype=np.float32) for i in range(64)]
grid.build(positions)

neighbors = grid.query_neighbors(positions[0], radius=0.1)
print(len(neighbors), "neighbors within 10 cm")

Notes

  • query_neighbors searches the 3x3x3 cell neighborhood around point. The radius argument is accepted for API shape but does not perform exact-distance filtering today. Apply distance checks downstream if you need exact-radius semantics.

See Also