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¶
| Parameter | Description |
|---|---|
model |
Required. Model with particles. |
config |
Optional SPHConfig; defaults are used when omitted. |
Backend Selection¶
cfg = novaphy.solvers.SPHConfig()
cfg.kernel_radius = 0.2
if not novaphy.has_sph_cuda():
raise RuntimeError("Rebuild with NOVAPHY_WITH_SPH_CUDA=ON")
cfg.preferred_backend = novaphy.solvers.SPHBackendKind.CUDA
solver = novaphy.solvers.SolverSPH(model, cfg)
Only SPHBackendKind.CUDA is currently exported as an explicit enum value.
It is the only implemented execution backend; a non-empty step() has no CPU
fallback.
Example¶
import novaphy
if not novaphy.has_sph_cuda():
raise RuntimeError("SolverSPH requires the SPH CUDA build")
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. |
| CPU-only particle fluid | Use SolverPBF; SolverSPH has no CPU backend. |
| SPH on a CUDA host | Enable NOVAPHY_WITH_SPH_CUDA=ON and gate with has_sph_cuda(). |
Demos¶
| Demo | What it shows |
|---|---|
python/demos/demo_sph_fluid.py |
Standalone SPH fluid simulation. |