1.03k likes | 1.42k Views
Flows on Surfaces of Arbitrary Topology. Jos Stam Alias GLunch Presentation by John Tran Friday, February 20, 2004. Basic Idea. Combine two pieces of code. Basic Result. Fluids in Computer Graphics. Want Good looking (convincing) Fast Easy to code How?. Far Cry (Ubisoft/Crytek 2003).
E N D
Flows on Surfaces of Arbitrary Topology Jos Stam Alias GLunch Presentation by John Tran Friday, February 20, 2004
Basic Idea • Combine two pieces of code
Fluids in Computer Graphics • Want • Good looking (convincing) • Fast • Easy to code • How? Far Cry (Ubisoft/Crytek 2003)
Stable Fluids • SG99, JGT01 (fft), GDC03, SG03, etc… • Incompressible Navier Stokes
Navier Stokes • Equations have been around forever • Lots of literature • Can reuse others’ code/algorithms • Nonlinear • Hard to solve – that’s why there’s lots of literature
Fluids – Previous work • “Why should we be able to solve these equations if the experts at NASA can’t? -Stam (from his Fluids talks notes) • Because we are computer graphicists!!!
Fluids – Previous work • Yaeger and Upson(SG86), Gamito et al(1995) • First 2D dynamical models of fluids • Used vortex method coupled with Poisson solver • Chen (1997) • Animated water surfaces • Used pressure term from Navier Stokes eqns • Limited to 2D • Unstable
Fluids – Previous work • Foster and Metaxas (1997) • Based on work of Harlow and Welch in computational fluid dynamics (~1965) • Full 3D Navier Stokes equations • Simple to code • Finite differencing • Explicit time solver • But explicit time solvers become unstable for large time-steps
Eulerian solver Smaller time steps for stability Lagrangian and implicit methods ANY time step can be used -- larger time steps lead to faster simulations (and funky results, but no “blow up”) Improvements
Stable Navier Stokes Fluids Solver Density Linear Velocity Conservation of momentum NONLINEAR Conservation of mass
Density • Assuming velocity known • For each time step
Density • Assuming velocity known • Density changes in the direction of velocity
Density • Assuming velocity known • Density diffuses over time at this rate (kappa)
Density • Assuming velocity known • Density increases due to sources from user
How to solve this density equation • Subdivide space into voxels • Velocity and density defined in the center of each voxel (for simplicity)
Diffusing Densities • Idea: examine exchange of density only between neighbors
Diffusing Densities • Unstable when k dt/h2 > 0.5
Diffusing Densities • Use implicit technique • Find densities which when diffused backward in time give the original densities
Diffusing Densities • Now we have a (not so bigass) linear system Ax=b • A can be huge but it is sparse • Need fast linear solver • Tradeoff: solving linear system over big time steps wins over taking lost of little steps in an unstable solver
Why FFT • JGT01 • Periodic boundary conditions • u(x,t) -> U(k,t) • Gradient operator turns into multiplication by ik • Diffusion and projection step are MUCH easier to solve • Raises complexity to NlogN, but easy to implement and fast
Moving Densities • Known velocity
Moving Densities • Again, can think about transfer only between neighbors, but again, this becomes unstable
Moving Densities • Cannot use conjugate gradient again because resulting linear system in this case has a nonsymmetrical matrix with varying constants • Easier idea…
Moving Densities • If density was sampled on particles, this would be easy. • Need particle tracer • But then you would have to use a particle solver for the other terms as well – don’t know how to do this
Moving Densities • New idea: find the positions of the particles that after one time step end up exactly at the grid centers
Moving Densities • Trace the particles backwards in time
Moving Densities • Determine four closest neighbors to the point
Moving Densities • Interpolate the density at this location from the 4 cells
Moving Densities • Set the interpolated value as the new density of the “departure cell” • Requires two grids (extra keeps track of density values of previous time step)
Moving Densities • This scheme is unconditionally stable • Density is always bounded
Velocity • Same frickin thing! • Only difference is velocity is moved by itself
Mass Conservation • Hodge Decomposition
Mass Conservation • Hodge Decomposition
Conservation of Mass • Gradient field found by solving the Poisson equation: • Conjugate gradient would be good. Jos uses Jacobi solver
Done! • UpdateVelocity • AddForce • Diffuse • Move • ConserveMass • Simple to code
Simple Stable Solver (60 lines of readable C, assuming a FFT solver)
Demo • CPU version AND PocketPC version
Future Work • Handle free boundaries for water rendering • Parallelize – a simple port to a dual P3 made it go much faster • (GPU?) • Adaptive grids • All in progress
Remember this? • Combine two pieces of code
Surfaces • Polygons • Splines • Implicit surfaces • Subdivision surfaces
Polygons • Fast hardware support • Arbitrary Topology • Smooth complex surfaces require many polygons • Editing hard
Splines • Easy to control • C2 • No sharp edges • (Damn this looks good… Is this a photograph?)