Pushkar Joshi
CS 294 - Graduate Graphics
Fall 2003

Real-time Lagrangian Particle System
Based on
Smoothed Particle Hydrodynamics

 

Introduction | SPH | Approach | Density Calculation | Velocity Calculation | Implementation

Introduction

I was impressed by the real-time Eulerian fluid system created by Jos Stam(1). For my final project, I decided to build a similar real-time fluid editing interface based on a Lagrangian particle system. However, to create interesting fluid animations, it is necessary to animate a large number of particles (often about tens of thousands), and computing interparticle dynamics for that many particles in real-time is not feasible. In order to speed up the interparticle force calculations, I used Smoothed Particle Hydrodynamics (SPH)(2,3) to approximate motion of all the particles from a small subset of the particles. That is, the system approximates overall fluid behaviour from a selected group of representative particles.

Before describing my system, it is important to understand the basic concepts behind SPH, which forms the core of the system.

 

Smoothed Particle Hydrodynamics

SPH is a fluids dynamics method traditionally used by astrophysicists to simulate the motion of celestial bodies in space. It is a purely Lagrangian method that approximates the values of continuous field values (such as mass density, temperature, speed etc.) at any point in the fluid from the known field values at particle locations.

...where f(r) is a continuous field at location r
approximated by a discrete sum over the field values at particle locations

In particular, one approximates the field values at any location within the fluid from a weighted average of the field values at the particle locations. The field values are weighted by their mass, density and by the distance from the location under consideration. By using the derivates of the kernel, one can also obtain approximate values of derivatives of the field at any location within the fluid.

The use of the kernel implies that the particle mass is considered to exist not as a point, but smeared out in space (over a radius equal to the kernel width). This gives rise to a smoothing effect of the field values, hence the name 'smoothed' particle hydrodynamics.

Usually, a Gaussian spline kernel is used for the distance weights. In this project, I have used a different kernel described in Desbrun and Cani (3), but can easily switch to the Gaussian kernel.

 

Approach

To re-iterate the problem: we need to simulate, in real-time, motion of a large number of particles by using inter-particle forces. I used the SPH mechanism to come up with a feasible solution. Instead of considering all the particles to compute inter-particle forces, I consider only a few selected ("special") particles for inter-particle dynamics. Then, I interpolate the special particles' velocity for the rest of the particles ("simple" particles) by using the SPH weighted average formula. This does not give physically accurate results, but works pretty well for the application at hand: a particle editing interface. Since the system is Lagrangian, handling particle-obstacle collisions is easy to implement.

In order to approximate the motion of all the particles, we must have the density and velocity for each particle.

 

Approximating Density

In order to approximate the density for each particle (special as well as simple), I obtain the weighted average of the densities of every special particle.

This gives good density values if the special particles are uniformly distributed. Obviously, if all the special particles are bunched up in one corner, the density at the other corner will be very low, which is physically incorrect. However, that corner of the fluid will experience very little motion anyway, so this physical inconsistency can be overlooked.

 

Approximating Velocity

In order to compute the velocity of the special particles, I use the method used by Desbrun and Cani(3) to compute pressure-acceleration for the special particles. This acceleration is combined with the forces from the user to give the total acceleration, which is then used to obtain the velocity.

Similar to the density approximation, the velocity for each simple particle is obtained by computing a weighted average of the velocities of each special particle.

This can be intuitively thought of as the special particles inducing motion in nearby particles, with closer particles moving more than farther particles. Again, this approach is not physically accurate as it will ignore the effect of motion of nearby simple particles, but it seems to give decent results for our application.

 

 

Implementation

Rendering

For displaying the particles, I used alpha-blended, textured quads in OpenGl; in my opinion, this was a good way to obtain a real-time display of a large Lagrangian particle system. I also implemented billboarding so the quads are always facing the viewer regardless of view direction.

 

3D Voxel Grid

In order to speed up nearest neighbour searches, I keep all the particles in bins in a 3D voxel grid. The width of each cell in this grid is twice the kernel width, as that is the maximum distance of a particle's influence.

 

Interface

For the editing interface, I provide several fluid parameters to the user that can be changed while the simulation is running, that are illustrated in the figure below.

various fluid parameters for fluid simulation

 

Picking Particles

The particles designated as "special" are picked using the mouse by the user. By clicking and dragging on the particle, the user can apply forces on the particle, thus affecting its motion.

In order to pick particles, I obtain a ray from the camera into the fluid, and find the particle that is closest to this ray. To apply force to this particle, one can drag in the desired direction. I obtain the direction of the force by first getting a direction of the dragged ray, and then subtracting from it the view direction.

(the force direction is obtained by subtracting the view direction from the dragged direction)

This ensures that the direction of the force acting on the force will always be in the view plane (as should be expected intuitively) and therefore enables use of the system in 3D.

 

Capture of Interactive Session

Here is a video (~ 4MB) of the interactive session that shows how I'm able to modify the particle system in real-time. Unfortunately the video is a little choppy as I did not have access to proper equipment to capture the video. However, as I have given this same demo in class, I felt it was not necessary to perfectly capture the on-screen real-time animation.

 

Future Work

Although this semester is over, I would like to continue work on this project in the future. In particular, I would like to add a more sophisticated viscosity calculation and random noise field (from the Komologorov Spectrum) so as to make the particles appear 'more lively'.

 

References

"Real-Time Fluid Dynamics for Games"
Jos Stam
Proceedings of the Game Developer Conference, 2003

“Simulating Free Surface Flows with SPH”
J. J. Monaghan
Comput. Phys. 110 399-406, 1994

“Smoothed Particles: A new paradigm for highly deformable bodies "
Mathieu Desbrun and Marie-Paule Cani
In 6th Eurographics Workshop on Animation and Simulation, 1996

Introduction | SPH | Approach | Density Calculation | Velocity Calculation | Implementation