Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid...

34
Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Transcript of Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid...

Page 1: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Lecture XI: Fluid Simulation

(based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Page 2: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Example: Fluid Simulation

2

https://youtu.be/F5KuP6qEuew

Page 3: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Coupled Particle System• Particles interact with each other depending on

their spatial relationship.• these relationships are dynamic, so geometric and

topological changes can take place.• Each particle !" has a potential energy #$".• The sum of the pairwise potential energies between the

particle !" and the other particles.

#$" =&'("

#$"'

3

Page 4: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Coupled Particle System

• The force !" applied on the particle at position #" is!" = −&'()*( = −+

,-"&'()*(.

where &'()*( =/)*(/0(

, /)*(/2(, /)*(/3(

• Reducing computational costs by localizing.• potential energies weighted according to distance to

particle.

4

Page 5: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Smoothed Particle Hydrodynamics (SPH)

• Any quantity ! at any point " is given by! " =$

%&%

!%'%(( " − "% , ℎ)

• (:smoothing kernel• '%: particle density

• usually Gaussian function or cubic spline. • ℎ: smoothing length.

• Example: the density can be calculated as' " =$

%&% (( " − "% , ℎ)

• Applied to pressure and viscosity forces.• External forces are applied directly to the particles.

5

http://rnd-zimmer.de/images/sph_particles2.png

http://www.nuigalway.ie/media/publicsub-sites/engineering/images/bio_sphkernel1.jpg

Page 6: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Smoothed Particle Hydrodynamics• Derivatives of quantities: by derivatives of !:

"# $ =&'('

#')'"!( $ − $' , ℎ)

• Varying ℎó tunes the resolution of a simulation locally.• Typically use a large length in low particle density

regions and vice versa.• Pro: easy to conserve mass (constant number of

particles).• Con: difficult to maintain material incompressibility.

6

Page 7: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Reminder: Navier-Stokes Equations

• Representing the conservation of mass and momentum for an incompressible fluid (! " # = 0):

& #' + # " !# = )! " !# − !+ + ,

• +: pressure field• ): kinematic viscosity.• ,: body force per density (usually just gravity ρ.).

7

Material Derivative

Unsteady acceleration

Convective acceleration Pressure gradientViscosity External

body forces

/#/0

Page 8: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Reduced form• No Viscosity:

! "# + " % &" = −&) + *• Incompressibility:

& % " = 0• Denoted as Euler equations.• Solid-wall boundary conditions: " % ,- = 0• There is no velocity on the boundary!• Bouncing creates force\impulse.• Relate: shooting up and falling own.

8

Page 9: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Splitting• Consider PDE:

!"!# = % " + '(")

• Solution mechanism: one after the other:"* # = " # + ∆#% "

"′ # + ∆# = "* # + ∆#' "′• First-order accurate

• Good for: when solving separately is much easier.

9

Page 10: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Discrete inviscid NS Equations• Three split steps in each iteration:

• Advection:!"!# = 0.

• Body forces: &# = ' .• Pressure and incompressibility:

(&# + *+ = 0 so that* , & = 0

10

( -&-. = −*+ + '

Page 11: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Discrete inviscid NS Equations • For each time step:• ! " : all discrete values of #. $ for % .• !& = ()*+,-(! " , ∆", !(")) (Advection)• !2 = !& + ∆"$ (Body forces)• ! " + ∆" = 4567+,-(!2, ∆") (Pressure and

incompressibility)

11

Page 12: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

MAC Grid• Marker-and-Cell• Different values are stored in different locations• Advantages:• Stability• Staggered instead of collocated.

12

Page 13: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

MAC Grid• In our case:• Velocities: on mid-edges

• Each dimension ! = !, $, % on each type of mid-edge!• Pressures: in mid cells.• Interpolation: by bilinear\trilinear functions.

13

Page 14: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Derivatives• Central differences:

!"!# ≈

"%&'/) − "%+'/)∆#

• Derivatives of mid-edges live on grid centers.• And vice versa.

14

Page 15: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Interpolation

Page 16: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Interpolation

Page 17: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Interpolation

Page 18: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Advection• Continuous equation:

!"!# = "% + ' ( )" = 0

• Naïve discretization:"+ # + ∆# − "+ #

∆# + '+, /+, 0+"+12 # − "+32 #

2∆5

• Conditionally unstable!• Will blow up for every ∆#.

18

Page 19: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Semi-Lagrangian

• Recall that !"!# = 0 is trivial for Lagrangian particles.• Insight: if we have &(() at some grid point *+ with

velocity , it was advected from another point *- in the grid:

, = *+ − *-∆(

• Value &(() at *+ = value &(( − ∆() in *-.• Getting &(( − ∆() in *- from bi\trilinear

interpolation.

19

Page 20: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Semi-Lagrangian

!"!#

Page 21: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Extrapolation• Position !" might be outside of the fluid• We need to extrapolate the flow field to be defined

everywhere.• Grid boundaries: ”no-stick” condition: # $ %& = 0• More simply in our case: just # = 0 outside.

• In grid, outside of fluid: more complicated…• Basic idea: closest-neighbor interpolation.

21

Page 22: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Incompressibility• Let us take the divergence on !"# + %& = 0:

∇ * ! +"+, + ∇ * %& = 0è

! ++, ∇ * " + ∇ * %& = 0• That’s because “ ..# ” and “∇ * ” work on

independent variables and therefore commute.

22

!"# + %& = 0 s.t. % * " = 0

Page 23: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Incompressibility

• We need to solve for ! " # = 0• Pressure is solved for to make this happen.

• Idea: discretize & ''( ∇ " # + ∇ " !+ = 0 as

∇ " !+ = −& ∇ " # - + ∆- − ∇ " # -∆-

• As we want ∇ " # - + ∆- = 0 we solve for:

∆+ = & ∇ " # -∆-

23

Page 24: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

The Discrete Divergence• Lives in faces (like pressure)

! " # ≈#%& '( ) − #%+ '( )

∆- +/0& '( ) − /0+ '( )

∆- +⋯

• Laplacian of pressure is similar:∆2 ≈ 2%,0 − 2%+(,0

∆- + 2%,0 − 2%&(,02∆- +⋯

• Need to solve for pressure and consequently velocity.• Details are a bit nasty (Section 4.3 of notes)

24

Page 25: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Velocity from pressure• The discretization of

!" = −1&'(

• Becomes ! ) + ∆) = ! ) − ∆", (-./ − (-./

• And similarly for every dimension.• The advantage of MAC: gradient of pressures lives

on mid-edges, like velocities!

25

&!" + '( = 0 s.t. ' 1 ! = 0

Page 26: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Fluid Surface Conditions• “Ghost” pressure for solid walls:

!"#$ = !" +'∆)∆* +"#$/-

• Just inverting the pressure equation.• For free boundary (water surface): !" = 0.

26https://www.fxguide.com/wp-content/uploads/2011/08/realtimewaves.jpg

Page 27: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Linear Equations

• End up with a sparse set of linear equations to solve for pressure• Matrix is symmetric positive (semi-)definite

• In 3D on large grids, direct methods unsatisfactory• Instead use Preconditioned Conjugate Gradient, with

Incomplete Cholesky preconditioner

Page 28: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Discrete Boundaries• Grid cells are either solid, fluid, or empty.

S

S

S

E

S

S FS S

E E

F

FFF

F

F

F

Page 29: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Voxelization is Suboptimal

• “8-bit water”• Waves less than a grid cell high aren’t “seen” by the fluid

solver – thus they don’t behave right• Strangely textured surface

• Solid wall artifacts:• If boundary not grid-aligned, noticeable geometric error.• Slopes are turned into stairs.

Page 30: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Marker Particles

• Simplest approach is to use marker particles• Sample fluid volume with particles !"• At each time step, mark grid cells containing any

marker particles as Fluid, rest as Empty or Solid• Advect particles with velocity:

#!"#$ = 0

Page 31: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Rendering Marker Particles• Need to wrap a surface around the particles• e.g. blobbies, or Zhu & Bridson ‘05

• Problem: rendered surface has bumpy detail that the fluid solver doesn’t have access to• The simulation can’t animate that detail properly if it

can’t “see” it.• Result: looks fine for splashy, noisy surfaces, but

fails on smooth, glassy surfaces.

Page 32: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Level Sets• Model a function !(#) on the grid so that the fluid boundaries

are at ! # = 0• In particular, best behaved type of implicit surface function is

signed distance:

• e.g. the book [Osher&Fedkiw’02]

! # = ' ()*+ #, *-./012−()*+ #, *-./012# outside# inside

Page 33: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Surface Capturing• Evolving !(#) on the grid by advection as well.• The surface (!(#) =0) moves at the velocity of the fluid• Topological changes automatically inferred.

Page 34: Lecture 11 - Fluid Simulation 11... · Lecture XI: Fluid Simulation (based on “Fluid Simulation” course notes from SIGGRAPH 2007)

Reinitializing

• Advecting !(#) this way doesn’t preserve signed distance property• Eventually gets badly distorted• Causes problems particularly for extrapolation, also for

accuracy in general• Reinitialize: recompute distance to surface every

once in a while.• Ideally shouldn’t change surface at all, just values in the

volume