CSCI 4530/6530 - Spring 2012
Advanced Computer Graphics
The goal of this assignment is to implement and experiment with two different physical simulation engines: a spring-mass cloth system and a grid-based fluid system. The bulk of the rendering, visualization, and interaction code including the basic data structures is provided.
In the cloth simulation a 2D grid of point masses are connected with structural, shear, and flexion/bend springs. To mitigate the "super-elastic" effect of these springs without increasing the stiffness (which requires a smaller timestep) you will implement the correction term described in "Deformation Constraints in a Mass-Spring Model to Describe Rigid Cloth Behavior", Xavier Provot, 1995.
For the fluid simulation, you will track a collection of marker particles as they move through a 3D grid of cells, monitoring the cell pressure and velocity through each face of each cell. The implementation requires tri-linear interpolation of the velocities, handling free-slip and no-slip boundary conditions, and adjustment for incompressible flows as described in "Realistic Animation of Liquids", Foster and Metaxas, Graphics Interface 1996.
./simulation -cloth small_cloth.txt -timestep 0.001
You will need to complete the implementation for the force visualization. Your visualization does not need to match the one above (the blue lines), as long as you find its output informative and helpful in your debugging.
./simulation -cloth provot_original.txt -timestep 0.001 ./simulation -cloth provot_correct_structural.txt -timestep 0.001 ./simulation -cloth provot_correct_structural_and_shear.txt -timestep 0.001
./simulation -cloth denim_curtain.txt -timestep 0.001 ./simulation -cloth silk_curtain.txt -timestep 0.001
./simulation -cloth table_cloth.txt -timestep 0.005
./simulation -fluid fluid_random_xy.txt -timestep 0.01
The images below show some visualizations of this dataset of random particles on a 5x5x1 grid. On the left we see the random particles (approximately 64 per cell) and the random initial velocities measured at the center of each cell. Marker particle visualization and velocity visualization are toggled by pressing the 'm' and 'v' keys. Remember that the velocities are actually stored as vectors perpendicular to the face of each cell, visualized by red (x) and green (y) triangles (toggled by pressing the 'e' key). The velocity at the center of each cell (drawn as a line segment colored red->white) is computed by averaging the velocities at the faces on either side of the cell.
To move particles within the field, we need to compute the velocity at an arbitrary position within the volume (not just the cell center). The simplest (but incorrect) thing to do is just use the velocity at the center of the cell for all particles in that cell. The image below left shows this discontinuous velocity field (press 'd' to visualize this "dense" velocity field). Go ahead and press 'a' to animate the particles within this field and you should see why this isn't a good assignment of velocities.
So, your first task is to implement proper velocity interpolation as described in Foster & Metaxas. The interpolation is somewhat complicated because the velocities are defined at the center of each cell face. Study this image from their paper:
To compute the horizontal component of the velocity at the grey point, k, we determine the indices for the 4 closest u velocities. The horizontal component will be a weighted average of these 4 values. The weights correspond to the 4 subareas in the diagram, formed by cutting a unit square centered at the grey point with unit squares centered at the velocity samples. Intuititively, velocity samples closer to the grey point will have larger area and higher weight. The sum of the areas (& weights) is 1. To find the vertical component of the velocity at the same point, we determine the 4 closest v velocities. Note that the indices (cells) of these points are generally not the same because the u and w velocities are defined on the cell faces so the grids are shifted. Similarly, the areas (weights) are not the same.
Once you've carefully implemented the interpolation in the xy plane, run the above simulation again and you should see dense velocity fields like the ones above middle and right. NOTE: In the implementation provided, each cell stores the face velocities (u, v, & w) for the face it shares with the cell in the positive direction along each axis. That is, celli,j,k stores ui+1/2,j,k, vi,j+1/2,k, and wi,j,k+1/2. These values are stored in the variables u_plus, v_plus, and w_plus, and the corresponding accessors get_u_plus(), get_v_plus(), and get_w_plus().
./simulation -fluid fluid_spiral_xy.txt -timestep 0.01 ./simulation -fluid fluid_spiral_yz.txt -timestep 0.01 ./simulation -fluid fluid_spiral_zx.txt -timestep 0.01
./simulation -fluid fluid_compressible.txt -timestep 0.01
You can press "p" to visualize the pressure in each cell by drawing little cubes for each cell colored by pressure. Initially all the cells are white (pressure == 0). After just a few timesteps (press the spacebar to advance by a single timestep) a negative pressure (blue) appears in the middle of the grid surrounded by a ring of positive pressure (red). Later in the simulation these values are quite chaotic, introducing noise into the velocity field.
In order to enforce the incompressibility of the flow, you will need to implement the divergence correction originally described by Harlow & Welch and later by Foster & Metaxas. Compute the divergence of each "full" cell and adjust each non-boundary face velocity to absorb its share of excess inflow or outflow. When correctly implemented, the pressure in each cell should be (within epsilon of) zero throughout the simulation and the flow should no longer "bounce".
./simulation -fluid fluid_incompressible.txt -timestep 0.01
./simulation -fluid fluid_drop.txt -timestep 0.001
./simulation -fluid fluid_dam.txt -timestep 0.005
To perform these simulations you will need to extend your incompressibility code to handle surface cells. The divergence of inflow or outflow should be dissipated over the "free" faces of the cell (i.e., faces that this cell shares with EMPTY cells). Note: You can edit the dimensions of your grid by editing the top line of the simulation data file. The "drop" and "dam" shapes will adjust to your new dimensions.
Similar to Assignments 0 & 1.
A class to store, animate, and paint a 2D grid of masses & springs.
Code to store, animate, and render a grid based fluid simulation.
Please read the Homework information page again before submitting.