Skip to content

Smoothed particle hydrodynamics

JavaScriptThree.js
Source

The simulation below offers an interactive smoothed particle hydrodynamics (SPH) implementation where you may manually stir the particles by moving your mouse/finger. Moreover, you can adjust a vast range of parameters such as gravity, viscosity, and rest density. It also serves as a somewhat more elaborate demo using the Helion library.

©️ Hydrodynamics based on Smoothed Particle Hydrodynamics (SPH) Fluid Simulation with WebGL
🐍 A VPython version is available as well, see smoothed_particle_hydrodynamics.py

There are two coordinate frames:

  • SPH-domein: coordinates for the physics and calculations for neighbor cells.
  • Helion-world: coordinates with which Circle and camera render particles.

These coordinates need not be identical. The view translates the SPHParticle.position during synchronization.

+---------------------------------------------+
| SPHParticle |
| │ |
| Velocity, pressure, mass, density, position |
+---------------------------------------------+
│
│
▼
+-----------------------------------+
| SPHParticleView.synchronizeWith() |
| │ |
| SPH-domein → Helion-wereld |
+-----------------------------------+
│
│
▼
+---------------------------------------+
| Circle |
| │ |
| Draw particle at transformed position |
+---------------------------------------+