Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🌀 Smoothed-Particle Hydrodynamics (SPH) Simulation

A simple Smoothed-Particle Hydrodynamics (SPH) simulation developed with guidance from Computer Science PhD students at the University of Toronto. This project explores computational fluid dynamics using the Lagrangian Approach of particle-based simulation methods.


🚀 Features

✔️ Real-time SPH fluid simulation
✔️ Time slider and speed controls
✔️ Fully implemented boundary conditions


📸 Demo

SPH Demo


🛠️ The Theory

1️⃣ Discretization Fluids are continuous in reality, but for simulation, we break them down into discrete particles. Each SPH particle represents a small volume of fluid and influences its surroundings through a smoothing kernel.

2️⃣ Motion Each particle moves accordingly to Newton's second law, F=ma. We update its velocity by integrating acceleration over 𝑑𝑡 and update its position by integrating velocity over 𝑑𝑡.

3️⃣ Forces The simulation uses two key forces: gravity and pressure forces. Gravity applies a downward force F=mg which results in an acceleration. Fluids resist compression, so pressure forces push particles apart if they are too close, maintaining near-constant density.

The pressure force is computed by using the gradient of the pressure:

Screenshot 2025-03-14 at 21 03 32

The pressure gradient (∇𝑝) tells us how quickly and in what direction pressure changes. Since fluids naturally move from high-pressure to low-pressure areas, we negate the pressure force to ensure that particles are pushed outward from regions of high pressure.

Screenshot 2025-03-14 at 21 04 23

4️⃣ SPH Kernel SPH particles interact through a kernel function that defines their influence range. We will use the Gaussian Kernel:

Screenshot 2025-03-14 at 21 05 02

where:

  • 𝒅=𝒙−𝒚 is the distance between two particles.
  • 𝒉 is the smoothing length, controlling how far the influence extends (similar to standard deviation on the normal distribution). The gradient (∇𝐺) of the kernel is:
Screenshot 2025-03-14 at 21 06 58

5️⃣ Density

Each particle has a local density, which is computed as:

Screenshot 2025-03-14 at 21 05 47

where the sum runs over all neighboring particles. This means that each particle’s density is influenced by nearby particles.

6️⃣ Pressure The pressure at each particle is computed as:

Screenshot 2025-03-14 at 21 06 08

where:

  • 𝑝 is the pressure
  • 𝜌 is the density
  • 𝜌rest is the initial rest density
  • 𝑘 is the "stiffness" constant

Using the Symmetric Gradient Formula (since the gradient of the original pressure function is not a very good pressure force), we can compute the gradient of the pressures:

Screenshot 2025-03-14 at 21 06 26

7️⃣ Apply After computing the density, and pressure gradient, the force acting on each particle is calculated, resulting in acceleration from the pressure.

8️⃣ Boundaries We used fixed boundary particles define the simulation area. Fluid particles collide with boundaries and experience repelling forces. Boundary particles exert pressure forces on fluid particles, preventing most particles from passing through.

9️⃣ Optimizations: Vectorization & Performance To make the simulation faster, we used NumPy vectorization. This allowed us to avoid high rendering times.

👥 Acknowledgments

This project was developed with guidance from Computer Science PhD students at the University of Toronto. Special thanks to:

  • Abhishek Madan
  • Mengfei Liu

📚 Resources

This simulation is based on the concepts from this SPH tutorial: https://sph-tutorial.physics-simulation.org/.

About

A Smoothed-Particle Hydrodynamics (SPH) simulation developed with guidance from CS PhD students at the University of Toronto.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages