cs 231 fluid simulation - computer science and …vbz/cs231f15/lecture11-15.pdf · fluid simulation...
TRANSCRIPT
![Page 1: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/1.jpg)
CS 231
Fluid simulation
![Page 2: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/2.jpg)
Why Simulate Fluids?
Feature film special effects
Computer games
Medicine (e.g. blood flow in heart)
Because it’s fun
![Page 3: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/3.jpg)
Fluid Simulation
Called Computational Fluid Dynamics (CFD)
Many approaches from math and
engineering
Graphics favors finite difference
Introduced fast and stable methods to
graphics [Stam 1999]
![Page 4: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/4.jpg)
Vector Fields (Fluid Velocity)
uij = (ux,uy)
![Page 5: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/5.jpg)
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion
Body Forces
Pressure
![Page 6: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/6.jpg)
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion Pressure
Body Forces
![Page 7: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/7.jpg)
Fluid Grids
All values live on regular grids
Need scalar and vector fields
Scalar fields: amount of smoke or dye
Vector fields: fluid velocity
Subtract adjacent quantities to approximate
derivatives
![Page 8: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/8.jpg)
Scalar Field (Smoke, Dye)
cij
1.2 3.7 5.1 …
![Page 9: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/9.jpg)
Diffusion
cij
![Page 10: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/10.jpg)
Diffusion
1
1
1
1
-4
cijnew = cij + k Dt (ci-1j + ci+1j + cij-1 + cij+1 - 4cij)
ct = k2c
value relative
to neighbors
![Page 11: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/11.jpg)
Diffusion = Blurring
Original Some Diffusion More Diffusion
![Page 12: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/12.jpg)
Vector Field Diffusion
ut = k2u
… blur the x-velocity and the y-velocity
uxt = k2ux
uyt = k2uy
Two separate diffusions:
viscosity
![Page 13: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/13.jpg)
Effect of Viscosity
• Each one is ten times higher
viscosity than the last
Low Medium High Very High
![Page 14: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/14.jpg)
Variable Viscosity
Viscosity can vary based on position
Viscosity field k can change with temperature
![Page 15: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/15.jpg)
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion Pressure
Body Forces
![Page 16: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/16.jpg)
Advection = Pushing Stuff
![Page 17: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/17.jpg)
Scalar Field Advection
ct = –(u)c
change in value advection current values
![Page 18: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/18.jpg)
Vector Field Advection
ut = –(u)u
uxt = –(u)ux
uyt = –(u)uy
Two separate advections:
… push around x-velocity and y-velocity
![Page 19: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/19.jpg)
Advection
Easy to code
Method stable even at large time steps
Problem: numerical inaccuracy diffuses flow
![Page 20: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/20.jpg)
Diffusion/dissipation
in first order advection
Original Image After 360 degree rotationusing first order advection
![Page 21: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/21.jpg)
Solution: Error Correction
1) Perform forward advection
2) Do backward advection from new position
3) Compute error and take correction step
4) Do forward advection from corrected
position
![Page 22: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/22.jpg)
error
Compensate
Forward
BackwardForward
Solution: Error Correction
![Page 23: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/23.jpg)
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion Pressure
Body Forces
![Page 24: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/24.jpg)
Divergence
High divergence Low divergence
Zero divergence
![Page 25: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/25.jpg)
Enforcing Incompressibility
First do velocity diffusion and advection
Find “closest” vector field that is divergence-
free
Need to calculate divergence
Need to find and use pressure
![Page 26: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/26.jpg)
Measuring Divergence
u=?
uij=(uxi+1j - ux
i-1j) + (uyij+1-u
yij-1)
?
-uyij-1
uyij+1
-uxi-1j uxi+1j
![Page 27: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/27.jpg)
Pressure Term
unew = u – p
Take divergence of both sides…
unew = u – p
u = 2p
zero
![Page 28: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/28.jpg)
Pressure Term
u = 2p
pnewij = pij + ( uij - (pi-1j + pi+1j + pij-1 + pij+1 - 4pij))
known unknown
?
pij-1
pij+1
pi-1j pi+1j
![Page 29: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/29.jpg)
Pressure Term
unew = u – p
…and velocity is now divergence-free
![Page 30: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/30.jpg)
Fluid Simulator
1) Diffuse velocity
2) Advect velocity
3) Add body forces (e.g. gravity)
4) Pressure projection
5) Diffuse dye/smoke
6) Advect dye/smoke
![Page 31: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/31.jpg)
![Page 32: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/32.jpg)
Where is the Water?
Water is often modeled as a fluid with a
free surface
The only thing we’re missing so far is how to
track where the water is:
Voxelized: which cells are fluid vs. empty?
Better: where does air/water interface cut
through grid lines?
![Page 33: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/33.jpg)
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
Move particles in incompressible grid velocity field
(interpolating as needed)
![Page 34: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/34.jpg)
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 35: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/35.jpg)
Improvement
Sample (implicit) surface function on simulation grid
Even just union of spheres is reasonable if we smooth
and render from the grid
Issues, must make sure that each particle always shows up
on grid or droplets can flicker in and out of existence…
Or: you must delete stray particles
But still not perfect for flat fluid surfaces.
![Page 36: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/36.jpg)
Level Sets
Idea: drop the particles all together, and just sample the
implicit surface function on the grid
In particular, best behaved type of implicit surface function is
signed distance
![Page 37: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/37.jpg)
Computing Signed Distance
Many algorithms exist
Simplest and most robust (and accurate enough for
animation) are geometric in nature
Our example algorithm is based on a Fast Sweeping method
[Tsai’02]
![Page 38: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/38.jpg)
Level Sets
Surface is exactly where =0
We need to evolve on the grid
The surface (=0) moves at the velocity of the fluid (any fluid
particle with =0 should continue with =0)
See e.g. the book [Osher&Fedkiw’02]
![Page 39: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/39.jpg)
Reinitializing
One problem is that 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
Ideally shouldn’t change surface at all, just
values in the volume
![Page 40: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/40.jpg)
![Page 41: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/41.jpg)
Small-scale liquid-solid
Interactions
Lake ( >1 meter) Water drops (millimeters)
What makes large water and small water behave
differently?
Surface Tension
Viscosity
![Page 42: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/42.jpg)
Surface Tension
Normal (always pointing outward)
Surface Tension Force
surfF N
0 0
![Page 43: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/43.jpg)
Virtual Surface Method
Solid
Virtual
Surface
Virtual Liquid
Liquid
Air
![Page 44: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/44.jpg)
60s 90s 120s
hydrophillic hydrophobic
Virtual Surface Method
![Page 45: CS 231 Fluid simulation - Computer Science and …vbz/cs231f15/lecture11-15.pdf · Fluid Simulation Called Computational Fluid Dynamics (CFD) Many approaches from math and engineering](https://reader031.vdocument.in/reader031/viewer/2022022603/5b5d28297f8b9ad21d8d939a/html5/thumbnails/45.jpg)