SPH Classes

Overview

The SPH classes implement Smooth Particle Hydrodynamics (SPH) density estimation and field interpolation using KDTree-based nearest-neighbour searches.

Supported dimensions:

  • SPH1D — 1D particle systems

  • SPH2D — 2D particle systems

  • SPH3D — 3D particle systems

All classes support:

  • Adaptive smoothing lengths based on nearest neighbours

  • Density estimation

  • Field interpolation

  • Optional particle masses

  • Cubic spline kernel

The general SPH estimator follows:

\[ \begin{align}\begin{aligned}\rho(\mathbf{x}) = \sum_i m_i W(|\mathbf{x} - \mathbf{x}_i|, h)\\f(\mathbf{x}) = \frac{\sum_i m_i f_i W(|\mathbf{x} - \mathbf{x}_i|, h)} {\sum_i m_i W(|\mathbf{x} - \mathbf{x}_i|, h)}\end{aligned}\end{align} \]

where W is the cubic SPH kernel and h is the smoothing length.

SPH1D

The SPH1D class performs SPH estimation in one dimension.

Initialization

sph = fiesta.sph.SPH1D()

By default, the cubic kernel is used:

sph.kernel_type = "cubic"

Setup

sph.setup(k=20, mass=None)

Parameters:

  • kint

    Number of nearest neighbours used for smoothing

  • massarray, optional

    Particle masses (defaults to 1 if None)

Assigning Mass

sph.assign_mass(mass)

If no mass is provided:

sph.mass = np.ones(len(points))

Density Estimation

dens = sph.get_density(x)

Returns SPH density evaluated at positions x.

Field Interpolation

sph.set_field(f)
f_est = sph.estimate(x)
  • f must be defined at particle positions

  • Returns SPH-smoothed field values

Core Method

sph.sph_estimate(x, f=None, dens=None)

If f is None → returns density If f is provided → returns interpolated field

SPH2D

The SPH2D class performs SPH estimation in two dimensions.

Initialization

sph = fiesta.sph.SPH2D()

Setup

sph.setup(k=20, mass=None)

Arguments:

  • k : number of nearest neighbours

  • mass : optional particle masses

Kernel

The SPH kernel is evaluated in 2D:

sph.kernel(r, h)

Uses cubic spline kernel:

\[W(r, h) = W_{\mathrm{cubic}}^{2D}(r, h)\]

Density Estimation

dens = sph.get_density(x, y)

Field Interpolation

sph.set_field(f)
f_est = sph.estimate(x, y)

Core Method

sph.sph_estimate(x, y, f=None, dens=None)

Returns:

  • density if f is None

  • interpolated field otherwise

SPH3D

The SPH3D class performs SPH estimation in three dimensions.

Initialization

sph = fiesta.sph.SPH3D()

Setup

sph.setup(k=50, mass=None)

Parameters:

  • k : number of nearest neighbours (default: 50)

  • mass : optional particle mass array

Kernel

sph.kernel(r, h)

Uses cubic kernel in 3D:

\[W(r, h) = W_{\mathrm{cubic}}^{3D}(r, h)\]

Density Estimation

dens = sph.get_density(x, y, z)

Field Interpolation

sph.set_field(f)
f_est = sph.estimate(x, y, z)

Core Method

sph.sph_estimate(x, y, z, f=None, dens=None)

Behavior:

  • If f is None → returns density

  • If f is provided → returns interpolated field

Algorithm Details

Smoothing Length

For each query point:

h = max(ndist)

This defines the adaptive smoothing radius.

Kernel Weighting

Each contribution is weighted:

w_i = m_i * W(r_i, h)

Density or field is computed via summation.

Performance Notes

  • Complexity: O(N log N) for KDTree queries

  • Best performance with vectorized mass arrays

Usage Example

sph = fiesta.sph.SPH2D()
sph.setup(k=30)

sph.points = np.column_stack([x, y])
sph.assign_mass()

dens = sph.get_density(x, y)

sph.set_field(f)
f_interp = sph.estimate(x, y)