Smoothed-Particle Hydrodynamics

Kyne Sun

Howdy! For my final project I decided to implement a fluid simulation using a basic Smoothed-Particle Hydrodynamics (SPH) method. SPH is a Lagrangian method, meaning we discretize the fluid using particles that hold certain properties. These properties can be obtained by summing the properties of the surrounding particles using a kernel function. The kernel functions I used were the three kernel functions outlined in the paper “Particle-Based Fluid Simulation for Interactive Applications” [Müller et al 2003]. The Navier-Stoke equations describe the motion of fluids which I used to calculate pressure, viscosity, and external forces such as gravity.

Implementation

For my implementation, I used Lab 8 as a starting point and modified the particle system that was provided. Although the particle system is in 3d, I first wanted to get working fluid behavior in 2d so I held the z values of the particles at a constant. Below is a video of a 2d simulation using 500 particles.

After I was able to get fluid behavior in 2d, I simply made the simulation run in 3d by initializing the z values. Below is a video of a 3d simulation using 500 particles.

A lot of time was spent playing around with the constants in my calculations to get realistic fluid behavior. Although my implementation isn't perfectly realistic, some effects I wanted to accomplish were the particles spreading along the ground as the column of particles collide with the floor, then having the particles go back up as they collide with the side walls and finally have the fluid come to rest.

Challenges

A big challenge I faced was being able to simulate the fluid in real time. It is important to note that both of the videos above are sped up. There were two areas of optimization that I attempted in my project.

Nearest Neighbor Search

A nearest neighbor search is used to sum properties of surrounding particles as mentioned above. The naive approach is to search all particles, making the runtime O(n). This is what I implemented at first, but two common approaches to optimize this is storing the particles in a grid structure or using a KD tree data structure. For my implementation, I wanted to try using a KD tree data structure where I found an implementation online by Christoph Dalitz and Jens Wilberg, Institute for Pattern Recognition, Niederrhein University of Applied Sciences, Krefeld, Germany. However, after modifying the KD tree implementation to work with my particle system there was no signficant performance improvements.

Parallelization

One advantage of SPH is that the calculations for each particle can be parallelized. For this I used OpenMP, but again I had trouble seeing performance improvements.

Conclusion

Although I couldn't sucessfully optimize my implementation, my main goal for this project was to be able to simulate fluid behavior, which I believe I was able to accomplish. Of course, given more time I would like to solve these issues and get the simulation running in real time with more particles. There are also other areas I would like to explore given more time, the first being that basic SPH has disadvantages when pursuing realistic fluids and there are many approaches that build off of the SPH approach which I would be interested in looking into and possibly implementing myself. Another area is improving the rendering as there are approaches to render fluids as fluid surfaces using ellipsoid splatting.

Overall, I am very grateful to be able to learn about and implement a fluid simulation. This project provided many challenges and problem solving but I am grateful that I could accomplish all that I did.

References

C. Dalitz: Kd-Trees for Document Layout Analysis. In C. Dalitz (Ed.): "Document Image Analysis with the Gamera Framework." Schriftenreihe des Fachbereichs Elektrotechnik und Informatik, Hochschule Niederrhein, vol. 8, pp. 39-52, Shaker Verlag (2009)

Muller, M., Charypar, D., and Gross, M. 2003. Particlebased fluid simulation for interactive applications. Proceedings of the 2003 ACM SIGGRAPH/Eurographics symposium on Computer animation.