Brief Technical Discussion
The main contribution of Stam's paper was the application of a numerical method known as the
Method of Characteristics to resolve the nonlinear advection term of the Navier-Stokes equations. When using this method, to update the velocity a a current position
x(t), trace the velocity field back in time to the previous timestep and find the velocity at its corresponding position
x(t-1), and use this velocity to update the velocity as position
x(t). This prevents the velocity field from blowing up, since its updated velocity always existed in the previous timestep at a different location. Using this method provides a stable simulation with an arbitrarily large time step, allowing the simulation to run easily in realtime. To keep the simulation fast, I used an FFT library (
FFTW) to accomplish pressure projection and to resolve the diffusion term in the equations. More information on this process can be found in the paper.
The videos below show as best I can the functionality that is included in this program. All below simulations are run on a 2D 50x50 grid. The timestep is set to 1/30 s for periodic boundary conditions. When boundary conditions are enforced, the timestep is set adaptively based on the maximum velocity in the field. This will cause the simulation to jump a little when particles are moving quickly near a boundary. I tried to minimize compression artifacts as much as possible, so some of the videos below are quite large and may take a minute to load. The video will open in a new window, so click on the image first and you can read the description while its loading. I'd be willing to pass the code out if anyone is interested, just send me an email and let me know what you would be using it for.
Videos
|
I plot the particles as single blue pixels in the simulation. There is a total 10,000 particles that are simply advected through the velocity field at each iteration of the simulation. Boundaries in this simulation are periodic, so there is no need to enforce any restrictions on the timestep. I therefore just use a 1/30 s timestep (30 fps). There is initally no forces in the velocity field. Forces are added with the mouse, and the particles respond to the changes in the velocity field. The actual simulation is very smooth, but there is some subtle jerkiness in the video that is probably due to the video capture method I used.
|
|
This video shows a visualization of the velocity field. The grid is also shown in this video. Velocity values are actually stored in a staggered formation, so horizontal (u) components of velocity are stored on the left side of each cell, and vertical (v) components of velocity are stored on the bottom of each cell. I plot the combined velocity vector from the middle of the cell because it is much easier to follow what is going on. As in the above video, this simulation uses periodic boundaries so there are no restrictions on the timestep.
|
|
This video shows a density field being advected through the velocity field. This effect might be similar to stirring milk into coffee, and is actually quite useful in simulating smoke-like behavior. Density values are stored at the center of cells and are drawn using an array of quads with color values corresponding the density values at the corners. In this video I add a density source and then push a velocity field through it. I show the density laid over both the particles and the velocity field, as well as its flow around an object that is inserted midway through the simulation. When the object is inserted, some density gets caught inside the object and is unable to move unless the object is removed.
|
|
This video shows texture coordinates of images being advected through the velocity field. I show a few different images, starting with one of my girlfriend and I in Cancun. This could be really useful for creating flow textures, as is described in Stam's paper. There are no boundary conditions in this simulation, so notice as soon as forces are applied parts of the image can jump from one side to the other. I choose images with water because I think the resulting effect looks really cool. There is also one of outer space, which I think is pretty nice too.
|
|
Here is a quick simulation of the outer space image being pushed into a boundary. All border edges have boundary conditions enforced, so notice that parts of the image are no longer able to jump from one side to the other as they did in the previous simulation. Notice also that this simulation is a little jumpier than the previous one, since restrictions must be place on the timestep. When the texture hits the wall it is simply pushed out to the side. There are some unusual compression artifacts on this one but you get the idea.
|
|
This video shows the interaction between a moving object and the particles in the velocity field. Boundary conditions are set differently on the boundariers of a moving object. I also display the grid discretization around the object in this video, shown in green. On a coarse grid, this is the best you can do without putting a lot of extra effort into it, since boundary conditions must be stored in the center of the bordering faces. The results are still quite good though.
|
>> Back