CSCI 5980/8980: Special Topics in Computer Science Physics-Based Animation 13 Fluid simulation with grids October 20, 2015
Today Presentation schedule Fluid simulation with grids Course feedback survey (again)
(Tentative) presentation schedule Oct Nov Dec Tue Thu 20 Fluids on grids Liquid surfaces 22 27 Elasticity Finite element method 29 3 Sound (Bryan) Cloth and hair 5 10 Cloth (Alex & Morgan) Fluids (Ran & Jingying) 12 17 Fire (Devin & Lei) TBD 19 24 Solids (George & Jie) Thanksgiving 26 1 Real-time stuff (Zahra) Real-time stuff (Dan & Matt) 3 8 Wrap-up day Project presentations 10 15 Project presentations
Course feedback survey
Representing continua
Particles (SPH) Values on moving particles Approximate continuous field by weighted averaging A(x) = X A i m i i W (x x i,h) Derivatives by differentiating weighting kernel
Grids Values on nodes of rectilinear grid Easy to interpolate using only 4 (in 2D) or 8 (in 3D) nearest values
Grids class Grid { int m, n, o; Vec3d origin; double dx; Type *values; Type get(int i, int j, int k);... };
Grids (finite differences) @c @x 11 c 21 c 11 x 0 1 1 c 02 c 12 c 22 c 01 c 11 c 21 c 00 c 10 c 20 @c @x 11 c 11 c 01 x 1 1 0 @c @x 11 c 21 c 01 2 x ½ 0 ½
Grids (finite differences) c 02 c 12 c 22 c 01 c 11 c 21 r 2 c 1 h 2 1 1 4 1 1 c 00 c 10 c 20
Meshes (FEM) Values on nodes of (not necessarily regular) mesh Evaluate derivatives on elements (triangles/ tetrahedra/etc.)
Fluids on grids
Grids vs. particles Particles Mass, velocity, pressure, etc. stored on particles Particles move with fluid Grids Velocity, pressure, etc. stored on grid cells Grid doesn t move
Advection Grid doesn t move, fluid flows through grid Lagrangian Dc Dt @c =0 but @t 6=0 Eulerian
Advection Dc Dt = @c @t + u rc Lagrangian derivative Change due to movement of fluid ( advection ) Eulerian derivative Proof: differentiate c(x(t), t) with respect to t
The fluid equations Du Dt = f ext rp + µr 2 u Du Dt = f ext 1 rp + r2 u @u @t + u ru = f ext 1 rp + r2 u
Operator splitting @u @t + u ru = f ext 1 rp + r2 u Lots of different terms, hard to integrate safely in one step Deal with one term at a time, ignoring all the others (e.g. IMEX)
u n Operator splitting Integrate @u @t + u ru =0 for time Δt Advection Integrate @u @t = 1 f ext for time Δt External forces Viscosity Integrate @u @t = µ r2 u for time Δt Pressure Integrate @u @t = 1 rp for time Δt u n+1
Advection
Advection Goal: Integrate c/ t + u c = 0 for time Δt Interpretation: c moves with speed u for time Δt Solution: To get the value of c n+1 at any point, figure out where it came from and take the value of c n from there
Advection Trace backwards through u and look up values c n u n c n+1 Semi-Lagrangian advection
Advection Input: initial grid c n, velocity field u n Output: final grid c n+1 For each grid cell x i Backtrace position, e.g. x back = x i u i Δt Set output c i n+1 = interpolate c n at x back To advect velocities, just use u n as the initial grid too.
Pressure
Pressure In SPH, density ρ was used for two things: 1. Normalizing for uneven particle distribution 2. Computing pressure forces With grids, we don t need to track ρ. But what about pressure? Treat it as a constraint force: ρ = const dρ/dt = 0
Incompressibility Flow Fixed surface n u Net flow ZZinto/out of region = u ˆn da ZZZ = r u dv [Divergence theorem] We want net flow to be 0 for all possible regions, so u = 0 everywhere
Pressure u new = u t rp r u new =0 Constraint: u new should be divergence-free, find the constraint response p that makes it so (analogous to computing λ so that Jv = 0) r 2 p = t r u Ignore the /Δt (just a rescaling)
Staggered grids Store pressure at cell centers, but velocity at cell faces (r u) i,j u i+1,j u i,j x Finite differences line up u and p at cell centers Components of p and u at cell faces + v i,j+1 v i,j x p p i,j+1 p v u i,j v i,j+1 u i+1,j p i 1,j p i,j p i+1,j v u u v i,j u u v v p p i,j 1 p
Boundary conditions Solid obstacles: u n = 0 Fluid cannot flow into or out of obstacles Free surface: p = 0 p = 0 Air applies negligible force on water
Pressure solve 2 p = u Build a big linear system Ap = b and solve it Rows of A contain stencil for 2 (except at boundaries, be careful!) b contains values of u Then update u u p
The other bits External forces e.g. f = β(t T 0 )g Gravity, buoyancy, user interaction, Explicit integration is fine Viscosity Often ignored because numerical damping is enough For really thick fluids, use implicit integration
u n Operator splitting Integrate @u @t + u ru =0 for time Δt Advection Integrate @u @t = 1 f ext for time Δt External forces Viscosity Integrate @u @t = µ r2 u for time Δt Pressure Integrate @u @t = 1 rp for time Δt u n+1
Further reading Bridson and Müller-Fischer, Fluid Simulation for Computer Animation (SIGGRAPH 2007 course notes) Bridson, Fluid Simulation for Computer Graphics (2008 book)
Course feedback survey
Next class Even more fluids Hybrid (particles + grid) techniques for advection Liquid surface reconstruction