Assignment2 - Smoke Simulation

Due Date: March 17, at midnight

Description:

For this assignment you will implement a basic 3D smoke simulator based on the material presented in the class (Lectures 2/11, 2/13, 2/18).

No startup code is provided for this assignment. Your simulator needs to include the following:

o       3D

o       Assume that the smoke lives in a closed box (you need to implement boundary conditions as discussed in the class)

o       Staggered grid

o       Air, smoke density and temperature simulation:

-         semi-lagrangian approach to solve the advection step for air velocity, smoke density and air temperature

-         solve the poisson equation for pressure as described in class

-         add buoyancy forces

-         add vorticity confinement forces

-         you can skip viscosity step for air velocity

-         you can skip diffusion step for smoke density and air temperature

o       Basic rendering of smoke

-         you can do anything you want here.

-         for example, you can visualize the density field. One way to do this is to just opengl render a bunch of cubes(corresponding to grid cells) that have alpha values based on how dense the smoke is.

o       Use Conjugate Gradient algorithm to solve the system of linear equations (use this code ConjGrad.h (C++) or MatrixUtils.java (java))

Text References:

o       Class Slides

o       Fluid simulation: SIGGRAPH 2007 course notes (Chapters 1,2,3,4,5)
(By Bridson, Fedkiw, and Muller-Fischer)

o        Stable Fluids, Jos Stam, SIGGRAPH 1999

o        Visual Simulation of Smoke, Fedkiw, Stam, Wann Jensen, SIGGRAPH, 2001

Extra Credit:

You will get 10 extra points if you implement ANY of the following (at most, you will get 20 extra points):

o       Nice rendering of smoke (different from the simple algorithm above, describe the algorithm you used and give the reference to a paper/website it came from).

o       Add objects that user can move with the mouse (could be done in 2D or 3D).

o       Add mouse interaction forces (could be done in 2D or 3D) .

o       Solve linear system using Preconditioned Conjugate Gradient. Describe the preconditioner you used and also analyze the speedup you got.

o       Implement diffusion step for smoke density and temperature. Compare results with/without diffusion step.

o       Implement better interpolation scheme to decrease numerical dissipation (described in  Visual Simulation of Smoke paper).

o       Implement viscosity step for fluid. Compare results with/without viscosity step.

Additional Theoretical Questions:

Please answer the following questions:

 

o       For a Lagrangian representation of a fluid, a mesh is defined as edges, faces, and volumes with vertices given by the particles in the system. What problems can this cause for long-running Lagrangian fluid simulations?

o       Suppose that I have a reasonably implemented simulation of water being poured out of a cup, and want to change that simulation to instead have the water sucked out of the cup through a straw. What will I need to do to accomplish this?

o       Suppose we had used constrained dynamics on the first project instead of particle spring forces and penetration penalty forces. What problems might we have run into which our soft constraint system did not encounter? How might we have solved these problems?

o       Why would repulsion forces be more efficient at preventing self-intersections in cloth than exact intersection detection and resolution? Keep in mind that detecting and resolving penetrations between cloth and our skeleton was relatively trivial.

o       In Baraff’s notes on implicit methods, he uses a linear approximation of the forces on a particle, then solves that linear system. What would the benefits and drawbacks be of using a higher-order approximation of the forces and solving that instead?

Submission Instructions:

Submit your source code as a single ZIP file to the Blackboard site before the deadline.

If you are using C++, you need to provide Visual Studio project/solution files, such that the code compiles and runs on the Moore 100 lab machines. You can use uBLAS for math stuff, and OpenGL, GLUT, and/or FLTK for graphics.

If you are using Java, you are STRONGLY encouraged to use Eclipse and export the entire project to an archive file (there’s a menu option for this). If you are not using Eclipse, provide a JAR file with the compiled code, and include all source files separately. You can use the JAMA Java matrix package for math stuff, and JOGL, LWJGL, and/or J3D.

If you want to use libraries not listed above, or if you want to use another language, you must contact TA at least 10 days before the deadline to make special arrangements.

In your writeup, include your responses to the questions above. Discuss problems you ran into, and how you solved them. If you used other sources of information, cite them in the writeup. If you used — or looked at — any source code you found somewhere else or which someone else wrote, even a single line, you SHOULD describe that in the writeup.

Also include a movie showing the results you’re most proud of. You can use FRAPS to record this movie, or integrate movie capture into your application. The former will be easier; the latter will produce smoother results. We will show your movies in the class.

Implementation Tips:

Few tips on implementation from Adam Bargteil who is an expert in this field!

Spend some time thinking about how to implement the static grid and how you will encode your boundary conditions. If you have an nxnxn grid of cells then you will have three arrays of velocity components u[n+1][n][n], v[n][n+1][n], and w[n][n][n+1]. The pressures, smoke density, etc will be stored at the cell centers, e.g. p[n][n][n]. Then the six faces around cell i,j,k are u[i][j][k], u[i+1][j][k], v[i][j][k], v[i][j+1][k], w[i][j][k], and w[i][j][k+1].

You will want to write your interpolation function before you begin writing the simulator. For each velocity component, you will in general interpolate the values stored at 8 faces. This can be a bit tricky. To test it, set the velocities to the half-index notation of position. That is u[i][j][k] = i*dx and v[i][j][k] = j*dx, where dx is the width of a grid cell. This assumes the origin of your coordinate system is at the lower corner (not center) of the 0,0,0 cell. If you interpolate this velocity field at any position x (in this coordinate system), you should get x as the answer.

Once you have interpolation working everything else is relatively easy. You'll also need a traceBack(x,dt) function which traces a point backwards through the velocity field for a timestep dt. Now you have everything you need for advection. If you decide to skip viscosity (a fine decision) all thats left is to compute the divergence, solve the poisson equation and subtract the gradient of the pressure field.

To compute the divergence, for each cell you subtract the velocity of the left (front, down) face from the right (back, up) face. I.e. div(i,j,k) = (u[i+1][j][k] - u[i][j][k] + v[i][j+1][k] - v[i][j][k] + w[i][j][k+1] - w[i][j][k]) / dx.

You can build the laplacian matrix explicitly if you like. Or you can just code the matrix vector product. For each cell, laplacian(p) = (p[i-1][j][k] + p[i+1][j][k] + p[i][j-1][k] + p[i][j+1][k] + p[i][j][k-1] + p[i][j][k+1] - 6 * p[i][j][k]) / dx^2. There could be another constant in there... I forget. When you are near the boundary, this is a little trickier. The key idea is to realize that the gradient across the boundary should be zero (so that we don't change the velocity on the boundary face). So, if the face between cell i-1,j,k and i,j,k is constrained, then we remove the p[i-1][j][k] term from the above and change the 6 to a 5. This essentially copies the pressure from i,j,k to i-1,j,k. To solve the poison equation, you need a linear system solver. Once you've solved the poisson equation you'll need to subtract the gradient of the pressure field from the velocity field. To do this simply do u[i][j][k] -= (p[i][j][k] - p[i-1][j][k]) / dx and the analogs in the other 2 dimensions.

We may add more info here as class progresses and as we get questions from you.