← ⚡ Physics & Mechanics

💧 SPH Fluid

Particles: 800
FPS:
Pressure
lowhigh
Drag — rotate · Scroll — zoom

💧 SPH Fluid — Smoothed Particle Hydrodynamics

Real-time fluid simulation using Smoothed Particle Hydrodynamics (SPH) — the same numerical method used in NASA astrophysics simulations and Hollywood VFX to compute realistic fluid dynamics.

🔬 What It Demonstrates

Each particle carries pressure, density, and velocity. Interactions with nearby particles approximate the Navier-Stokes equations, producing viscosity, pressure gradients, and surface tension behaviour.

🎮 How to Use

Click or drag on the fluid to push it. Use the sliders to change gravity, viscosity, and particle count. Try increasing particle emission from the top to simulate a waterfall.

💡 Did You Know?

SPH was originally developed in 1977 by Lucy and Gingold to simulate galaxy collisions in astrophysics. The same method now runs in real-time on modern GPUs to simulate water in video games.

About this simulation

This simulation models a body of liquid in real time using Smoothed Particle Hydrodynamics, a mesh-free method that represents the fluid as up to 2,000 moving particles instead of a fixed grid. Each particle computes its local density and pressure from neighbours found within a smoothing radius, then responds to pressure, viscosity and gravity forces using the Müller (2003) SPH kernels. Splashing, sloshing and free-surface motion all emerge from these simple particle-to-particle interactions.

🔬 What it shows

Liquid behaviour inside a wireframe tank, computed with SPH. A spatial-hash grid finds each particle's neighbours within radius h, the poly6 kernel sums density, pressure follows p = k(rho - rho0), and spiky and viscosity Laplacian kernels supply pressure and viscous forces before semi-implicit Euler integration.

🎮 How to use

Six sliders set particle count (200-2000), gravity (0-20), pressure stiffness, viscosity, kernel radius h (0.5-3) and wall damping. Drag to rotate the camera and scroll to zoom. Press Restart to rebuild the block of fluid, or Wave to fire an upward splash impulse into a random third of the particles.

💡 Did you know?

SPH was invented in 1977 by Gingold, Monaghan and Lucy to model the fission of rotating stars in astrophysics, long before it was ever applied to water. Here each particle's colour maps to its pressure, so you can watch high-pressure shockwaves ripple through the liquid after a splash.

Frequently asked questions

What is Smoothed Particle Hydrodynamics?

SPH is a mesh-free numerical method that represents a fluid as a set of discrete particles, each carrying mass, velocity, density and pressure. Field quantities are estimated by summing smoothing-kernel-weighted contributions from neighbouring particles within a radius h. Because there is no fixed grid, it handles splashing free surfaces and large deformations naturally.

How does the simulation compute fluid forces?

Each step it builds a spatial-hash grid, then for every particle it sums neighbour contributions to get density with the poly6 kernel and derives pressure from p = k(rho - rho0). Pressure forces use the spiky kernel gradient and viscosity uses the viscosity-kernel Laplacian, after which gravity is added and positions are advanced by semi-implicit Euler integration.

What do the sliders actually control?

Particles sets how many points make up the liquid, Gravity is the downward acceleration, and Pressure is the stiffness k that resists compression and keeps the fluid roughly incompressible. Viscosity is internal friction that makes the fluid thicker, Kernel radius h is the neighbour interaction distance, and Damping is the fraction of speed retained after each wall bounce.

Is this physically accurate?

It captures the qualitative behaviour of a real liquid, including pressure gradients, viscous drag and wall collisions, but it is a simplified real-time model. The particle count is limited for smooth frame rates, the kernels are the standard Müller 2003 approximations, and parameters use simulation units rather than calibrated physical values, so results are illustrative rather than quantitatively exact.

Why are the particles different colours?

Colour encodes each particle's pressure, mapped from blue at low pressure through cyan and green to red at the highest pressure in the current frame. This makes compression visible: after pressing Wave you can see bands of high pressure travel through the fluid as a shockwave before the liquid settles back under gravity.