Fluid Dynamics
SPH Smoothed-Particles-Hydrodynamics
October 26, 2023 - Tommy Dräger
Imagine using particles. Each particle has a position, mass, forces, velocity, and density. The idea of SPH is to calculate the density of each particle based on its proximity to its neighbors in a highly optimized manner, all while maintaining a 60fps frame rate. Higher density leads to higher pressure force, echoing Newton's principle that 'For every force, there is an equal and opposite reaction.' This pressure force is then balanced by the fluid's viscosity, resulting in a satisfying fluid simulation.
The Basics of SPH
The core idea of SPH is to derive fluid properties by averaging over nearby particles. Each particle's density is influenced by its neighbors, leading to a pressure force derived from Newton's principle: "For every action, there is an equal and opposite reaction." Higher density results in higher pressure, pushing particles away from crowded areas.
A Dive into Three.js and SPH
Recently, I dived into SPH simulations using Three.js, aiming to simulate water but ended up with something even more fascinating—an accidental magma-like effect. Inspired by Sebastian Lague, this unexpected result showcases the versatility of SPH in creating different fluid-like phenomena.
Click here to check out this simple example:
https://apps.fenixfox-studios.com/sph_fluid_dynamics/
Further Reading
- Smoothed Particle Hydrodynamics on Wikipedia
- Three.js Documentation
- Sebastian Lague's YouTube Channel
Feel free to dive into SPH simulations and explore the endless possibilities of fluid dynamics in real-time graphics!