Fluid Animation - Columbia University

82
Fluid Animation Christopher Batty November 17, 2011

Transcript of Fluid Animation - Columbia University

Page 1: Fluid Animation - Columbia University

Fluid Animation

Christopher Batty

November 17, 2011

Page 2: Fluid Animation - Columbia University

What distinguishes fluids?

Page 3: Fluid Animation - Columbia University

What distinguishes fluids?

β€’ No β€œpreferred” shape

β€’ Always flows when force is applied

β€’ Deforms to fit its container

β€’ Internal forces depend on velocities, not

displacements

Watch fluid simulation clips

Page 4: Fluid Animation - Columbia University

Basic Theory

Page 5: Fluid Animation - Columbia University

Eulerian vs. Lagrangian

Lagrangian: Point of reference moves with

the material.

Eulerian: Point of reference is stationary.

e.g. Weather balloon (Lagrangian) vs.

weather station on the ground (Eulerian)

Page 6: Fluid Animation - Columbia University

Eulerian vs. Lagrangian

Consider an evolving temperature field.

β€’ Lagrangian: Set of moving particles,

each with a temperature value.

Page 7: Fluid Animation - Columbia University

Eulerian vs. Lagrangian

Consider an evolving temperature field.

β€’ Eulerian: A fixed grid of temperature

values, that temperature flows through.

Page 8: Fluid Animation - Columbia University

Consider the temperature 𝑇(π‘₯, 𝑑) at a point following a given path, π‘₯(𝑑).

Two ways temperature changes: 1. Heating/cooling occurs at the current point.

2. Following the path, the point moves to a cooler/warmer location.

Relating Eulerian and Lagrangian

π‘₯(𝑑0)

π‘₯(𝑑1) π‘₯(π‘‘π‘›π‘œπ‘€)

Page 9: Fluid Animation - Columbia University

Time derivatives

Mathematically:

Chain

rule!

Definition

of 𝛻

Choose πœ•π‘₯

πœ•π‘‘= 𝑒

𝐷

𝐷𝑑𝑇 π‘₯ 𝑑 , 𝑑 =

πœ•π‘‡

πœ•π‘‘+πœ•π‘‡

πœ•π‘₯

πœ•π‘₯

πœ•π‘‘

=πœ•π‘‡

πœ•π‘‘+ 𝛻𝑇 βˆ™

πœ•π‘₯

πœ•π‘‘

=πœ•π‘‡

πœ•π‘‘+ 𝒖 βˆ™ 𝛻𝑇

Page 10: Fluid Animation - Columbia University

Material Derivative

This is called the material derivative, and

denoted 𝐷

𝐷𝑑 .

Change at the

current (fixed) point.

𝐷𝑇

𝐷𝑑=πœ•π‘‡

πœ•π‘‘+ 𝒖𝛻𝑇

Change due

to movement.

Change at a point moving

with the velocity field.

Page 11: Fluid Animation - Columbia University

Advection

To track a quantity T simply moving (passively) through a velocity field:

This is the advection equation.

Think of colored dye or massless particles drifting around in fluid.

𝐷𝑇

𝐷𝑑= 0

πœ•π‘‡

πœ•π‘‘+ 𝒖𝛻𝑇 = 0 or equivalently

Watch dye in fluid clip

Page 12: Fluid Animation - Columbia University

Equations of Motion

β€’ For general materials, we have Newton’s

second law: F = ma.

β€’ Specialized for fluids:

β€œNavier-Stokes Equations”

Page 13: Fluid Animation - Columbia University

Navier-Stokes

Density Γ— Acceleration = Sum of Forces

πœŒπ·π’–

𝐷𝑑= 𝑭𝑖𝑖

Expanding the material derivative…

πœŒπœ•π’–

πœ•π‘‘= βˆ’πœŒ 𝒖 βˆ™ 𝛻𝒖 + 𝑭𝑖

𝑖

Page 14: Fluid Animation - Columbia University

What are the forces on a fluid? Primarily for now:

β€’ Pressure

β€’ Viscosity

β€’ Simple β€œexternal” forces – (e.g. gravity, buoyancy, user forces)

Also:

β€’ Surface tension

β€’ Coriolis

β€’ Possibilities for more exotic fluid types: – Elasticity (e.g. silly putty)

– Shear thickening / thinning (e.g. β€œoobleck”, ketchup)

– Electromagnetic forces

β€’ Sky’s the limit... Watch oobleck clip

Page 15: Fluid Animation - Columbia University

In full…

πœŒπœ•π’–

πœ•π‘‘= βˆ’πœŒ 𝒖 βˆ™ 𝛻𝒖 + 𝑭𝑖

𝑖

Advection

Change in

velocity at a

fixed point

Forces

(pressure,

viscosity

gravity,…)

Page 16: Fluid Animation - Columbia University

Operator splitting

Break the equation into steps:

1. Advection: πœŒπœ•π’–

πœ•π‘‘= βˆ’πœŒ 𝒖 βˆ™ 𝛻𝒖

2. Pressure: πœŒπœ•π’–

πœ•π‘‘= π‘­π‘π‘Ÿπ‘’π‘ π‘ π‘’π‘Ÿπ‘’

3. Viscosity: πœŒπœ•π’–

πœ•π‘‘= π‘­π‘£π‘–π‘ π‘π‘œπ‘ π‘–π‘‘π‘¦

4. External: πœŒπœ•π’–

πœ•π‘‘= π‘­π‘œπ‘‘β„Žπ‘’π‘Ÿ

Page 17: Fluid Animation - Columbia University

1. Advection

Page 18: Fluid Animation - Columbia University

Advection

Previously, we considered advection of a passive scalar quantity, 𝑇, by velocity 𝒖.

In Navier-Stokes we saw:

Velocity 𝒖 is advected by itself!

πœ•π’–

πœ•π‘‘= βˆ’π’– βˆ™ 𝛻𝒖

πœ•π‘‡

πœ•π‘‘= βˆ’π’– βˆ™ 𝛻𝑇

Page 19: Fluid Animation - Columbia University

Advection

i.e., The scalar components 𝑒, 𝑣 of the

vector 𝒖 are each advected in the same

way.

We can reuse the same numerical method.

Page 20: Fluid Animation - Columbia University

2. Pressure

Page 21: Fluid Animation - Columbia University

Pressure

What does pressure do?

– Enforces incompressibility.

Typical fluids (mostly) do not compress.

β€’ Exceptions: high velocity, high pressure, …

Page 22: Fluid Animation - Columbia University

Incompressibility

Compressible

velocity field Incompressible

velocity field

Page 23: Fluid Animation - Columbia University

Incompressibility

Intuitively, net flow into/out of a given region is zero (no sinks/sources).

Integrate the flow across the boundary of a closed region:

𝒖 βˆ™ π’πœ•Ξ©

= 0

𝒏

Page 24: Fluid Animation - Columbia University

Incompressibility

𝒖 βˆ™ π’πœ•Ξ©

= 0

By divergence theorem:

𝛁 βˆ™ 𝒖 = 0

But this is true for any region, so 𝛁 βˆ™ 𝒖 = 𝟎 everywhere.

Page 25: Fluid Animation - Columbia University

Pressure

How does pressure enter in? – Pressure is the force required to ensure that

𝛻 βˆ™ 𝒖 = 0.

– Pressure force has the following form:

𝑭𝑝 = βˆ’π›»π‘

Page 26: Fluid Animation - Columbia University

Helmholtz-Hodge Decomposition

= +

Input Velocity field Curl-Free

(irrotational)

Divergence-Free

(incompressible)

𝑒 = 𝛻𝑝 + 𝛻 Γ— πœ‘

π‘’π‘œπ‘™π‘‘ = πΉπ‘π‘Ÿπ‘’π‘ π‘ π‘’π‘Ÿπ‘’ + 𝑒𝑛𝑒𝑀

Page 27: Fluid Animation - Columbia University

Aside: Pressure as Lagrange Multiplier

Interpret as an optimization:

Find the closest 𝒖𝑛𝑒𝑀 to π’–π‘œπ‘™π‘‘ where 𝛻 βˆ™ 𝒖𝑛𝑒𝑀 = 0

min𝒖𝑛𝑒𝑀𝒖𝑛𝑒𝑀 βˆ’ π’–π‘œπ‘™π‘‘

s. t. 𝛻 βˆ™ 𝒖𝑛𝑒𝑀 = 0

A Lagrange multiplier to enforce the

constraint is exactly pressure.

Page 28: Fluid Animation - Columbia University

3. Viscosity

[Carlson et al.

2003]

Page 29: Fluid Animation - Columbia University

Viscosity

What characterizes a viscous liquid?

β€’ β€œThick”, damped behaviour

β€’ Higher resistance to flow

Watch viscous honey clip

Page 30: Fluid Animation - Columbia University

Viscosity

Loss of energy due to internal friction between molecules moving at different velocities.

Interactions between molecules in different layers causes shear stress that…

β€’ acts to oppose relative motion.

β€’ causes an exchange of momentum

Page 31: Fluid Animation - Columbia University

Viscosity

Loss of energy due to internal friction between molecules moving at different velocities.

Interactions between molecules in different layers causes shear stress that…

β€’ acts to oppose relative motion.

β€’ causes an exchange of momentum

Page 32: Fluid Animation - Columbia University

Viscosity

Loss of energy due to internal friction between molecules moving at different velocities.

Interactions between molecules in different layers causes shear stress that…

β€’ acts to oppose relative motion.

β€’ causes an exchange of momentum

Page 33: Fluid Animation - Columbia University

Viscosity

Loss of energy due to internal friction between molecules moving at different velocities.

Interactions between molecules in different layers causes shear stress that…

β€’ acts to oppose relative motion.

β€’ causes an exchange of momentum

Page 34: Fluid Animation - Columbia University

Viscosity

Imagine fluid particles with general velocities.

Each particle interacts with nearby neighbours, exchanging momentum.

Page 35: Fluid Animation - Columbia University

Viscosity

Amount of momentum exchanged is proportional to:

β€’ Velocity gradient, 𝛻𝒖.

β€’ Viscosity coefficient, πœ‡

For any closed region, net in/out flow of momentum:

πœ‡π›»π’– βˆ™ 𝒏 = πœ‡π› βˆ™ π›π’–πœ•Ξ©

So the viscosity force is: π‘­π‘£π‘–π‘ π‘π‘œπ‘ π‘–π‘‘π‘¦ = πœ‡π› βˆ™ 𝛁𝒖

Page 36: Fluid Animation - Columbia University

Viscosity

The end result is a smoothing of the velocity.

This is exactly the action of the Laplacian

operator, 𝛁 βˆ™ 𝛁.

For scalar quantities, the same operator is

used to model diffusion.

Page 37: Fluid Animation - Columbia University

4. External Forces

Page 38: Fluid Animation - Columbia University

External Forces

Any other forces you may want.

β€’ Simplest is gravity:

– 𝐹𝑔 = πœŒπ’ˆ for π’ˆ = (0,βˆ’9.81)

β€’ Buoyancy models are similar,

– e.g., 𝐹𝑏 = 𝛽(π‘‡π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘ βˆ’ π‘‡π‘Ÿπ‘’π‘“)π’ˆ

Page 39: Fluid Animation - Columbia University

Numerical Methods

Page 40: Fluid Animation - Columbia University

1. Advection

Page 41: Fluid Animation - Columbia University

Advection of a Scalar

β€’ First, we’ll consider advecting a scalar

quantity, πœ‘.

– temperature, color, smoke density, …

β€’ The grid stores πœ‘ and 𝒖.

Page 42: Fluid Animation - Columbia University

Eulerian

Approximate derivatives with finite differences. πœ•πœ‘

πœ•π‘‘+ 𝒖 βˆ™ π›»πœ‘ = 0

FTCS = Forward Time, Centered Space:

πœ‘π‘–π‘›+1 βˆ’ πœ‘π‘–

𝑛

βˆ†π‘‘+ π‘’πœ‘π‘–+1

𝑛 βˆ’ πœ‘π‘–βˆ’1𝑛

2βˆ†π‘₯= 0

Unconditionally

Unstable!

Conditionally

Stable!

Lax:

πœ‘π‘–π‘›+1 βˆ’ (πœ‘π‘–+1

𝑛 + πœ‘π‘–βˆ’1𝑛)/2

βˆ†π‘‘+ π‘’πœ‘π‘–+1

𝑛 βˆ’ πœ‘π‘–βˆ’1𝑛

2βˆ†π‘₯= 0

Many possible methods, stability can be a challenge.

Page 43: Fluid Animation - Columbia University

Lagrangian

β€’ Advect data forward from grid points by integrating position according to grid velocity.

β€’ Problem: New data position doesn’t necessarily land on a grid point.

?

Page 44: Fluid Animation - Columbia University

Semi-Lagrangian

β€’ Look backwards in time from grid points,

to see where data is coming from.

β€’ Interpolate data at previous time.

Page 45: Fluid Animation - Columbia University

Semi-Lagrangian - Details

1. Determine velocity 𝒖𝑖,𝑗 at grid point,.

2. Integrate position for a timestep of βˆ’βˆ†π‘‘.

e.g. π‘₯π‘π‘Žπ‘π‘˜ = π‘₯𝑖,𝑗 βˆ’ βˆ†π‘‘π’–π‘–,𝑗

3. Interpolate πœ‘ at π‘₯π‘π‘Žπ‘π‘˜, call it πœ‘π‘π‘Žπ‘π‘˜.

4. Assign πœ‘π‘–,𝑗 = πœ‘π‘π‘Žπ‘π‘˜ for the next time.

Unconditionally stable!

Page 46: Fluid Animation - Columbia University

Advection of Velocity

β€’ This is great for scalars. What about velocity advection?

β€’ Same method: – Trace back with current velocity

– Interpolate velocity (component) at that point

– Assign it to the grid point at the new time.

β€’ Caution: Do not overwrite the velocity field you’re using to trace back!

πœ•π’–

πœ•π‘‘= βˆ’π’– βˆ™ 𝛻𝒖

Page 47: Fluid Animation - Columbia University

2. Pressure

Page 48: Fluid Animation - Columbia University

Recall… Helmholtz-Hodge

Decomposition

= +

Input Velocity field Curl-Free

(irrotational)

Divergence-Free

(incompressible)

𝑒 = 𝛻𝑝 + 𝛻 Γ— πœ‘

π‘’π‘œπ‘™π‘‘ = πΉπ‘π‘Ÿπ‘’π‘ π‘ π‘’π‘Ÿπ‘’ + 𝑒𝑛𝑒𝑀

Page 49: Fluid Animation - Columbia University

Pressure Projection - Derivation

(1) πœŒπœ•π’–

πœ•π‘‘= βˆ’π›»π‘ and (2) 𝛻 βˆ™ 𝒖 = 0

Discretize (1) in time…

𝒖𝑛𝑒𝑀 = π’–π‘œπ‘™π‘‘ βˆ’βˆ†π‘‘

πœŒπ›»π‘

Then plug into (2)…

𝛻 βˆ™ π’–π‘œπ‘™π‘‘ βˆ’βˆ†π‘‘

πœŒπ›»π‘ = 0

Page 50: Fluid Animation - Columbia University

Pressure Projection

Implementation:

1) Solve a linear system for p: βˆ†π‘‘

πœŒπ›» βˆ™ 𝛻𝑝 = 𝛻 βˆ™ π’–π‘œπ‘™π‘‘

2) Update grid velocity with:

𝒖𝑛𝑒𝑀 = π’–π‘œπ‘™π‘‘ βˆ’βˆ†π‘‘

πœŒπ›»π‘

Page 51: Fluid Animation - Columbia University

Implementation

Discretize with finite differences:

e.g., in 1D:

βˆ†π‘‘

𝜌

𝑝𝑖+1 βˆ’ π‘π‘–βˆ†π‘₯

βˆ’π‘π‘– βˆ’ π‘π‘–βˆ’1βˆ†π‘₯

βˆ†π‘₯=𝑒𝑖+1π‘œπ‘™π‘‘ βˆ’ 𝑒𝑖

π‘œπ‘™π‘‘

βˆ†π‘₯

𝑝𝑖+1 π‘π‘–βˆ’1 𝑝𝑖

𝑒𝑖+1 𝑒𝑖

βˆ†π‘‘

πœŒπ›» βˆ™ 𝛻𝑝 = 𝛻 βˆ™ π’–π‘œπ‘™π‘‘

Page 52: Fluid Animation - Columbia University

Solid Boundary Conditions

52

𝒏

𝒖

Free Slip: π’–π‘›π‘’π‘€βˆ™ 𝒏 = 0

Page 53: Fluid Animation - Columbia University

Staggered vs. Non-staggered

β€’ Two choices for grids:

– Velocity and pressure co-located

– Velocity and pressure staggered

𝑝𝑖+1 π‘π‘–βˆ’1 𝑝𝑖

𝑝𝑖+1 π‘π‘–βˆ’1 𝑝𝑖

𝑒𝑖+1 𝑒𝑖

𝑒𝑖+1 𝑒𝑖 π‘’π‘–βˆ’1

Page 54: Fluid Animation - Columbia University

Why prefer staggered?

β€’ Finite differences line up nicely.

– 𝑒 and 𝛻𝑝 match, 𝑝 and 𝛻 βˆ™ 𝑒 match

β€’ …which improves stability!

𝑝𝑖+1 π‘π‘–βˆ’1 𝑝𝑖

𝑒𝑖+1 𝑒𝑖

Page 55: Fluid Animation - Columbia University

3. Viscosity

[Carlson et al.

2003]

Page 56: Fluid Animation - Columbia University

Viscosity

PDE: πœŒπœ•π’–

πœ•π‘‘= πœ‡π›» βˆ™ 𝛻𝒖

Use finite differences.

Discretized in time:

π’–π’π’†π’˜ = π’–π‘œπ‘™π‘‘ +βˆ†π‘‘πœ‡πœŒπ›» βˆ™ π›»π’–βˆ—

Page 57: Fluid Animation - Columbia University

Viscosity – Time Integration

π’–π’π’†π’˜ = π’–π‘œπ‘™π‘‘ +βˆ†π‘‘πœ‡πœŒ 𝛻 βˆ™ π›»π’–βˆ—

Explicit integration, let π’–βˆ— be π’–π‘œπ‘™π‘‘: – Just estimate βˆ†π‘‘πœ‡

πœŒπ›» βˆ™ π›»π’–π‘œπ‘™π‘‘

– Add to current 𝒖. – Very unstable.

Implicit integration, let π’–βˆ— be 𝒖𝑛𝑒𝑀: – Stable for high viscosities.

– Need to solve a system of equations.

Page 58: Fluid Animation - Columbia University

Viscosity – Implicit Integration

Solve for π’–π’π’†π’˜:

π’–π’π’†π’˜ βˆ’βˆ†π‘‘πœ‡πœŒπ›» βˆ™ 𝛻𝒖𝑛𝑒𝑀 = π’–π‘œπ‘™π‘‘

Apply separately for each velocity component.

e.g. in 1D:

𝑒𝑖 βˆ’βˆ†π‘‘πœ‡

𝜌

𝑒𝑖+1 βˆ’ π‘’π‘–βˆ†π‘₯

βˆ’π‘’π‘– βˆ’ π‘’π‘–βˆ’1βˆ†π‘₯

βˆ†π‘₯= π‘’π‘–π‘œπ‘™π‘‘

𝑒𝑖+1 π‘’π‘–βˆ’1 𝑒𝑖

Page 59: Fluid Animation - Columbia University

Solid Boundary Conditions

59

No-Slip: 𝒖𝑛𝑒𝑀= 0

Watch no-slip clip

Page 60: Fluid Animation - Columbia University

4. External Forces

Page 61: Fluid Animation - Columbia University

Gravity

Discretized form is: π’–π’π’†π’˜ = π’–π‘œπ‘™π‘‘ + βˆ†π‘‘π’ˆ

Just add a downward acceleration to each

velocity, scaled by timestep.

Page 62: Fluid Animation - Columbia University

Gravity

β€’ Note: in a closed fluid-filled container,

gravity (alone) won’t do anything!

– Incompressibility cancels it out. – (Assuming constant density)

Start After gravity step After pressure step

Page 63: Fluid Animation - Columbia University

Simple Buoyancy

Look up π‘‡π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘ at grid point,

increment velocity based on difference

from a reference velocity.

π’–π’π’†π’˜ = π’–π‘œπ‘™π‘‘ + βˆ†π‘‘π›½ π‘‡π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘ βˆ’ π‘‡π‘Ÿπ‘’π‘“ π’ˆ

𝛽 dictates the strength of the

buoyancy force.

See paper for a more elaborate model:

β€œVisual simulation of smoke”, 2001.

Page 64: Fluid Animation - Columbia University

User Forces

Add whatever additional forces we want,

such as:

β€’ near the mouse when the user clicks

β€’ Paddle forces in Plasma Pong

Watch clip

Page 65: Fluid Animation - Columbia University

Ordering of Steps

Order turns out to be important.

Why?

1) Incompressibility is not guaranteed at

intermediate steps

2) Advecting with a compressible field

causes volume/material loss or gain!

Page 66: Fluid Animation - Columbia University

Ordering of Steps

Consider advection in this field:

Best ordering

1) Advection

2) Viscosity

3) Add Forces

4) Make incompressible (Pressure)

Page 67: Fluid Animation - Columbia University

Useful References

β€’ Robert Bridson’s SIGGRAPH 2007 Fluid

Course notes: http://www.cs.ubc.ca/~rbridson/fluidsimulation/

β€’ β€œStable Fluids” [Stam 1999]

β€’ β€œReal-Time Stable Fluid Dynamics for

Games” [Stam, 2003]

Page 68: Fluid Animation - Columbia University

Liquids

Page 69: Fluid Animation - Columbia University

Liquids

What’s missing so far?

We need:

β€’ A surface representation

β€’ Boundary conditions at the surface

Page 70: Fluid Animation - Columbia University

The Big Picture

Velocity Solver

Advect Velocities

Add Viscosity

Add Gravity

Project Velocities

to be

Incompressible

Page 71: Fluid Animation - Columbia University

What about liquids?

Advect Velocities

Add Viscosity

Add Gravity

Project Velocities

to be

Incompressible

Surface Tracker

Velocity Solver

Page 72: Fluid Animation - Columbia University

Surface Tracker

Given: liquid surface geometry, velocity field,

timestep

Compute: new surface geometry by

advection.

𝑇𝑛

𝑇𝑛+1

𝒖𝑛

Page 73: Fluid Animation - Columbia University

Surface Tracker

Ideally:

β€’ Efficient

β€’ Accurate

β€’ Handles merging/splitting (topology changes)

β€’ Conserves volume

β€’ Retains small features

β€’ Smooth surface for rendering

β€’ Provides convenient geometric operations

β€’ Easy to implement…

Very hard (impossible?) to do all of these at once.

Page 74: Fluid Animation - Columbia University

Surface Tracking Options

1. Particles

2. Level sets

3. Volume-of-fluid (VOF)

4. Triangle meshes

5. Hybrids (many of these)

Page 75: Fluid Animation - Columbia University

Particles

[Zhu & Bridson 2005]

Page 76: Fluid Animation - Columbia University

Particles

Perform passive Lagrangian advection on

each particle.

For rendering, need to reconstruct a surface.

Page 77: Fluid Animation - Columbia University

Level sets

[Losasso et al.

2004]

Page 78: Fluid Animation - Columbia University

Level sets Each grid point stores signed distance to the

surface (inside <= 0, outside > 0).

Surface is interpolated zero isocontour.

> 0

<= 0

Page 79: Fluid Animation - Columbia University

Volume of fluid

[Mullen et al 2007]

Page 80: Fluid Animation - Columbia University

Volume-Of-Fluid

Each cell stores fraction f Ο΅ 0,1 indicating

how empty/full it is.

Surface is transition region, f β‰ˆ 0.5.

0

0

0

0

0

0

0

0

0

0

0

0.4

0.4

0

0

0.

8

1

1

0.8

0.5

1

1

1

1

1

1

1

1

1

1

Page 81: Fluid Animation - Columbia University

Meshes

[Brochu et al 2010]

Page 82: Fluid Animation - Columbia University

Meshes

Store a triangle mesh.

Advect its vertices, and correct for collisions.