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 systemsSPH2D— 2D particle systemsSPH3D— 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:
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:
kintNumber of nearest neighbours used for smoothing
massarray, optionalParticle 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)
fmust be defined at particle positionsReturns 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 neighboursmass: optional particle masses
Kernel¶
The SPH kernel is evaluated in 2D:
sph.kernel(r, h)
Uses cubic spline kernel:
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 Noneinterpolated 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:
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 densityIf
f is provided→ returns interpolated field
Algorithm Details¶
Nearest Neighbour Search¶
All SPH classes rely on KDTree queries:
nind, ndist = sph.nearest(..., k=self.k, return_dist=True)
nind: indices of nearest neighboursndist: distances to neighbours
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)