Grid SPH

The Grid-SPH method is a hybrid approach between traditional SPH and grid-based density estimation. Instead of performing k-nearest neighbor searches, it computes particle statistics on a grid and uses integral images to efficiently approximate SPH-like smoothing. This approach is significantly faster for large datasets while maintaining reasonable accuracy.

The density and velocity field of a cosmological simulation computed with GridSPH.

_images/gridsph_example.png

gridSPH2D

2D grid-based SPH density or field estimation.

Overview

This method computes density or field estimates by:

  1. Assigning particles to a grid using nearest-grid-point (NGP) assignment

  2. Building an integral image for fast region summation

  3. Estimating SPH-like volumes using enclosed particle counts

  4. Converting volume estimates into density or field values

Example

import fiesta

boxsize = 100
ngrid = 256
rho = fiesta.gridsph.gridSPH2D(x, y, boxsize, ngrid, minpart=5)

temp = fiesta.gridsph.gridSPH2D(x, y, [100, 100], 128, f=temperature, minpart=10)

gridSPH3D

3D extension of the Grid-SPH method.

Overview

This function extends the 2D grid-SPH algorithm into three dimensions, using 3D integral images for fast volume estimation.

Example

import fiesta

boxsize = 100
ngrid = 256
rho = fiesta.gridsph.gridSPH3D(x, y, z, boxsize, ngrid, minpart=10)

temp = fiesta.gridsph.gridSPH3D(x, y, z, [200, 200, 200], 64, f=temperature, minpart=20)

API Reference

fiesta.gridsph.gridSPH2D(x: ndarray, y: ndarray, boxsize: float | List[float], ngrid: int, minpart: int = 1, w: ndarray | None = None, f: ndarray | None = None, periodic: bool | List[bool] = True, dgrid: ndarray | None = None, fgrid: ndarray | None = None) Tuple[ndarray, ndarray]

The grid SPH method. This method is similar to a k-Nearest Neighbour method although performed on a grid for speed.

Parameters:
  • x (array) – X and Y coordinates of the points.

  • y (array) – X and Y coordinates of the points.

  • boxsize (float or list) – Size of the 2D grid.

  • ngrid (int or list) – Grid size.

  • minpart (int, optional) – Minimum number of particles.

  • w (array, optional) – Weights for the points, if None assumed to be unitary for all.

  • f (array, optional) – Field values for the points, if None it is assumed the intention is to compute density.

  • periodic (bool or list, optional) – Periodic boundary condition.

  • dgrid (array, optional) – Precomputed density grid, computed using p2g.part2grid2D.

  • fgrid (array, optional) – Precomputed field grid, computed using p2g.part2grid2D, and unnormalised by density.

Returns:

  • dgridSPH (array) – Grid SPH density estimation.

  • fgridSPH (array) – If f is not None then the field is estimated via SPH.

fiesta.gridsph.gridSPH3D(x: ndarray, y: ndarray, z: ndarray, boxsize: float | List[float], ngrid: int, minpart: int = 1, w: ndarray | None = None, f: ndarray | None = None, periodic: bool | List[bool] = True, dgrid: ndarray | None = None, fgrid: ndarray | None = None) Tuple[ndarray, ndarray]

The grid SPH method. This method is similar to a k-Nearest Neighbour method although performed on a grid for speed.

Parameters:
  • x (array) – X, Y, and Z coordinates of the points.

  • y (array) – X, Y, and Z coordinates of the points.

  • z (array) – X, Y, and Z coordinates of the points.

  • boxsize (float) – Size of the 3D grid.

  • ngrid (int) – Grid size.

  • minpart (int, optional) – Minimum number of particles.

  • w (array, optional) – Weights for the points, if None assumed to be unitary for all.

  • f (array, optional) – Field values for the points, if None it is assumed the intention is to compute density.

  • periodic (bool, optional) – Periodic boundary condition.

  • dgrid (array, optional) – Precomputed density grid, computed using p2g.part2grid3D.

  • fgrid (array, optional) – Precomputed field grid, computed using p2g.part2grid3D, and unnormalised by density.

Returns:

  • dgridSPH (array) – Grid SPH density estimation.

  • fgridSPH (array) – If f is not None then the field is estimated via SPH.