Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

47
Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen,

Transcript of Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Page 1: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Modeling, Simulating and Rendering Fluids

Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan

Page 2: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Applications

• Mostly Hollywood– Shrek– Antz– Terminator 3– Many others…

• Games• Engineering

Page 3: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Animating Fluids is Hard…

• Too complex to animate by hand– Surface is changing very quickly– Lots of small details

• Need automatic simulations

Page 4: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Ad-Hoc Methods

• Some simple algorithmsexist for special cases– Mostly waves

• What about water glass?

• Too much work to comeup with empirical algorithmsfor each case

Page 5: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Physically-Based Approach

• Borrow techniques from Fluid Dynamics– Long history. Goes back to Newton…– Equations that describe fluid motion

• Use numerical methods to approximate fluid equations, simulating fluid motion– Like mass-spring systems

Page 6: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

What do we mean by ‘Fluid’?

• liquids or gases

• Mathematically:– A vector field u (represents the fluid velocity)– A scalar field p (represents the fluid pressure)– fluid density (d) and fluid viscosity (v)

Page 7: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Vector Fields

• 2D Scalar function:– f(x,y) = z – z is a scalar value

• 2D Vector function:– u(x,y) = v – v is a vector value

• v = (x’, y’)

• The set of valuesu(x,y) = v is called avector field

Page 8: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Fluid Velocity == Vector Field

• Can model a fluid as a vector field u(x,y)– u is the velocity of the fluid at (x,y)– Velocity is different at each point in fluid!

• Need to compute change in vector field

Page 9: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Particles carry Velocities

• Particle Simulation:– Track particle positions x = (x,y)– Numerically Integrate: change in

position

• Fluid Simulation :– Track fluid velocities u = (u,v) at

all points x in some fluid volume D– Numerically Integrate: change in

velocity

dt

dx

dt

du

Page 10: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Some Math

Del Operator:

Laplacian Operator:

Gradient:

Page 11: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

More Math

Vector Gradient:

Divergence:

Directional Derivative:

Page 12: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Navier-Stokes Fluid Dynamics

Velocity field u, Pressure field p Viscosity v, density d (constants) External force f

Navier-Stokes Equation:

Mass Conservation Condition:

Page 13: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Navier-Stokes Equation

Derived from momentum conservation condition

4 Components: Advection/Convection Diffusion (damping)

Pressure External force (gravity, etc)

Page 14: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Mass Conservation Condition

Velocity field u has zero divergence Net mass change of any sub-region is 0 Flow in == flow out Incompressible fluid

Comes from continuum assumption

Page 15: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Change in Velocity

• Derivative of velocity with respect to time

• Change in velocity, or acceleration– So this equation models acceleration of fluids

Page 16: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Advection Term

• Advection term– Force exerted on a particle

of fluid by the other particlesof fluid surrounding it

– How the fluid “pushes itself around”

Change in

Velocity

Page 17: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Diffusion Term

• Viscosity constant controls velocity diffusion

• Essentially, this term describes how fluid motion is damped

• Highly viscous fluids stick together– Like maple syrup

• Low-viscosity fluids flow freely– Gases have low viscosity

Advection

Change in

Velocity

Page 18: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Weather: Advection & Diffusion

• “Jet-Stream”

Page 19: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Pressure Term

• Pressure follows a diffusion process– Fluid moves from high-pressure

areas to low-pressure areas

• Moving == velocity– So fluid moves in direction of

largest change in pressure– This direction is the gradient

Diffusion

Advection

Change in

Velocity

p = 0.5

p = 1

p = 0

Time…

Page 20: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Weather: Pressure

• “Fronts” are the boundaries between regions of air with different pressure…

• “High Pressure Zones” will diffuse into “Low Pressure Zones”

Page 21: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Body Force

• Body force term represents external forces that act on the fluid– Gravity– Wind– Etc…

Diffusion

Advection

Change in

Velocity

Pressure

Page 22: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Summary

• Add mass conservation (1 liter in == 1 liter out) constraint:

• Need to simulate these equations…

Diffusion

Advection

Change in

Velocity

Pressure

Page 23: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Incompressible Euler Equations

self-advection forces

incompressible

(Navier-Stokes without viscosity)

Page 24: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Additional Equations

smoke’sdensity

temperature

Page 25: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Discretization

u

v

Page 26: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Algorithmadd forces self-advect project

t = t + dt

t = 0

Page 27: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Step 1 – Add Force

Assume change in force is small during timestep

Just do a basic forward-Euler step

Note: f is actually an acceleration?

Page 28: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Step 2 - Advection

Page 29: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Method of Characteristics

p is called the characteristic Partial streamline of velocity field u Can show u does not vary along streamline

Determine p by tracing backwards

Unconditionally stable Maximum value of w2 is never greater

than maximum value of w1

Page 30: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

Semi-Lagrangian solver (Courant, Issacson & Rees 1952)

t t+dt

Page 31: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

For each u-component…

Page 32: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

Trace backward through the field

Page 33: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

Interpolate from neighbors

Page 34: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

Set interpolated value in new grid

Page 35: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

Repeat for all u-nodes

Page 36: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

Similar for v-nodes

Page 37: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Self-Advection

Advected velocity field

Vmax > Vmax

Page 38: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Enforcing Zero Divergence

Pressure and Velocity fields related Say we have velocity field w with non-zero divergence

Can decompose into Helmholtz-Hodge Decomposition u has zero divergence

Define operator P that takes w to u:

Apply P to Navier-Stokes Equation:

(Used facts that and )

Page 39: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Operator P

Need to findImplicit definition:

Poisson equation for scalar field p Neumann boundary condition

Sparse linear system when discretized

Page 40: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Adding Viscosity – Diffusion

Standard diffusion equation

Use implicit method:

Sparse linear system

Page 41: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Step 4 - Projection

Enforces mass-conservation condition

Poisson Problem:

Discretize q using central differences Sparse linear system Maybe banded diagonal…

Relaxation methods too inaccurate Method of characteristics more precise for divergence-free field

Page 42: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Solving the System

Need to calculate:

Start with initial state

Calculate new velocity fields

New state:

Page 43: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Vorticity Confinement

Basic idea:

Add energy lost as an external force. Avoid very quick dissipation.

“Vorticity Confinement” force preservesswirling nature of fluids.

Page 44: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Vorticity Confinement

Page 45: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Vorticity Confinement

Page 46: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Vorticity Confinement

Page 47: Modeling, Simulating and Rendering Fluids Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan.

Videos