Skip to content

novaphy.solvers.SolverSPH

Smoothed Particle Hydrodynamics fluid solver. Direct SolverBase subclass that reads and writes SimState.particle_* buffers. CUDA support is gated by build-time NOVAPHY_WITH_SPH_CUDA=ON and runtime has_sph_cuda().

Compared with SolverPBF, SolverSPH runs a classic SPH pressure-force pipeline rather than an iterative density-constraint formulation.

Pipeline

graph LR
    A[Density<br/>estimate] --> B[Pressure<br/>forces]
    B --> C[Viscosity<br/>forces]
    C --> D[Integrate]

Uses SPHKernels and SpatialHashGrid. When contacts are supplied, particle / rigid coupling is consumed from Contacts.soft_contact_*.

Constructor

novaphy.solvers.SolverSPH(model: Model, config: SPHConfig)
Parameter Description
model Required. Model with particles.
config SPHConfig.

Backend Selection

cfg = novaphy.solvers.SPHConfig()
cfg.kernel_radius = 0.2

if novaphy.has_sph_cuda():
    cfg.preferred_backend = novaphy.solvers.SPHBackendKind.CUDA

solver = novaphy.solvers.SolverSPH(model, cfg)

Only SPHBackendKind.CUDA is currently exported as an explicit enum value. Leave preferred_backend at its default for the build's normal fallback path.

Example

import novaphy

cfg = novaphy.solvers.SPHConfig()
cfg.kernel_radius = 0.2
cfg.rest_density = 1000.0

solver = novaphy.solvers.SolverSPH(model, cfg)
state = model.state()

dt = 1.0 / 240.0
for _ in range(steps):
    solver.step(state, state, None, None, dt)

Use a CollisionPipeline and pass populated Contacts when SPH should couple to rigid collision shapes.

When To Use

Scenario Recommendation
More physically meaningful pressure behavior Classic SPH is appropriate.
Real-time water visuals on CPU only SolverPBF is usually faster per step.
GPU acceleration on CUDA hosts Enable with NOVAPHY_WITH_SPH_CUDA=ON.

Demos

Demo What it shows
python/demos/demo_sph_fluid.py Standalone SPH fluid simulation.

See Also