Introduction to Computational Fluid Dynamics

Introduction to Modeling
Fluid Dynamics
1
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Different Kind of Problem
• Can be particles, but lots of them
• Solve instead on a uniform grid
2
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
No Particles => New State
Particle
• Mass
• Velocity
• Position
3
Fluid
• Density
• Velocity Field
• Pressure
• Viscosity
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
No Particles => New Equations
Navier-Stokes equations for viscous,
incompressible liquids.
u  0
ut  u   u  u 
2
4
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
What goes in must come out
Gradient of the velocity field= 0
Conservation of Mass
u  0
ut  u   u  u 
2
5
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Time derivative
Time derivative of velocity field
Think acceleration
u
a
t
u  0
ut  u   u  u 
2
6
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Advection term
Field is advected through itself
Velocity goes with the flow
u  0
ut  u   u  u 
2
7
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Diffusion term
Kinematic Viscosity times Laplacian of u
Differences in Velocity damp out
u  0
ut  u   u  u 
2
8
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Pressure term
Fluid moves from high pressure to low pressure
Inversely proportional to fluid density, ρ
u  0
ut  u   u  u 
2
9
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
External Force Term
Can be or represent anythying
Used for gravity or to let animator “stir”
u  0
ut  u   u  u 
2
10
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Navier-Stokes
How do we solve these equations?
u  0
ut  u   u  u 
2
11
1

p  f
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Discretizing in space and time
• We have differential equations
• We need to put them in a form
we can compute
• Discetization – Finite Difference
Method
12
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Discretize in Space
Staggered Grid vs Regular
X Velocity
Y Velocity
Pressure
13
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Discretize the operators
• Just look them up or derive them
with multidimensional Taylor
Expansion
• Be careful if you used a
staggered grid
14
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Example 2D Discetizations
Divergence Operator
Laplacian Operator
1
-1
0
-1
15
1
1
1
-4
1
1
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Make a linear system
It all boils down to
Ax=b.
 x1   b1 
? ?   ?
x  b 
? ?


 2  2

    



   


 
     

?    ? d d  xn d   xn d 
n xn
16
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Simple Linear System
• Exact solution takes O(n3) time
where n is number of cells
• In 3D k3 cells where k is
discretization on each axis
• Way too slow O(n9)
17
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Need faster solver
• Our matrix is symmetric and
positive definite….This means we
can use
♦ Conjugate Gradient
• Multigrid also an option – better
asymptotic, but slower in
practice.
18
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Time Integration
• Solver gives us time derivative
• Use it to update the system state
U(t+Δt)
U(t)
Ut
19
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Discetize in Time
• Use some system such as
forward Euler.
• RK methods are bad because
derivatives are expensive
• Be careful of timestep
20
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Time/Space relation?
• Courant-FriedrichsLewy (CFL)
condition
• Comes from the
advection term
21
x
t 
u
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Now we have a CFD simulator
• We can simulate fluid using only
the aforementioned parts so far
• This would be like Foster &
Metaxas first full 3D simulator
• What if we want it real-time?
22
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Time for Graphics Hacks
• Unconditionally stable advection
♦ Kills the CFL condition
• Split the operators
♦ Lets us run simpler solvers
• Impose divergence free field
♦ Do as post process
23
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Semi-lagrangian Advection
CFL Condition limits
speed of information
travel forward in time
Like backward Euler,
what if instead we
trace back in time?
p(x,t) back-trace
24
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Divergence Free Field
• Helmholtz-Hodge Decomposition
♦ Every field can be written as
w  u  q
• w is any vector field
• u is a divergence free field
• q is a scalar field
25
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Helmholtz-Hodge
STAM 2003
26
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Divergence Free Field
• We have w and we want u
w  u  q
  w    u  2q
  w  2q
• Projection step solves this equation
u  w  q
27
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Ensures Mass Conservation
• Applied to field before advection
• Applied at the end of a step
• Takes the place of first equation
in Navier-Stokes
28
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Operator Splitting
• We can’t use semi-lagrangian
advection with a Poisson solver
• We have to solve the problem in
phases
• Introduces another source of
error, first order approximation
29
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Operator Splitting
u  0
1
u t   u  u u  p  f

2
30
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Operator Splitting
1. Add External Forces
2. Semi-lagrangian
advection
 u  u
3. Diffusion solve
  u
u  0
4. Project field
31
f
2
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Operator Splitting
u(x,t)
u  0
 u  u
W0
W1
f
32
W2
W3
W4
  u
2
u(x,t+Δt)
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Various Extensions
• Free surface tracking
• Inviscid Navier-Stokes
• Solid Fluid interaction
33
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Free Surfaces
• Level sets
♦ Loses volume
♦ Poor surface detail
• Particle-level sets
♦ Still loses volume
♦ Osher, Stanley, & Fedkiw, 2002
• MAC grid
♦ Harlow, F.H. and Welch, J.E., "Numerical
Calculation of Time-Dependent Viscous
Incompressible Flow of Fluid with a Free Surface",
The Physics of Fluids 8, 2182-2189 (1965).
34
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Free Surfaces
MAC Grid
35
Level Set
-
+
+
+
+
+
+
+
+
-
0
+
+
+
+
+
+
+
-
-
0
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Inviscid Navier-Stokes
• Can be run faster
• Only 1 Poisson Solve needed
• Useful to model smoke and fire
♦ Fedkiw, Stam, Jensen 2001
36
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Solid Fluid Interaction
• Long history in CFD
• Graphics has many papers on 1
way coupling
♦ Way back to Foster & Metaxas, 1996
• Two way coupling is a new area
in past 3-4 years
♦ Carlson 2004
37
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
Where to get more info
• Simplest way to working fluid
simulator (Even has code)
♦ STAM 2003
• Best way to learn enough to be
dangerous
♦ CARLSON 2004
38
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL
References
CARLSON, M., “Rigid, Melting, and Flowing Fluid,” PhD Thesis, Georgia Institute of Technology, Jul.
2004.
FEDKIW, R., STAM, J., and JENSEN, H. W., “Visual simulation of smoke,” in Proceedings of ACM
SIGGRAPH 2001, Computer Graphics Proceedings, Annual Conference Series, pp. 15–22, Aug. 2001.
FOSTER, N. and METAXAS, D., “Realistic animation of liquids,” Graphical Models and Image Processing,
vol. 58, no. 5, pp. 471–483, 1996.
HARLOW, F.H. and WELCH, J.E., "Numerical Calculation of Time-Dependent Viscous Incompressible
Flow of Fluid with a Free Surface", The Physics of Fluids 8, 2182-2189 (1965).
LOSASSO, F., GIBOU, F., and FEDKIW, R., “Simulating water and smoke with an octree data structure,”
ACM Transactions on Graphics, vol. 23, pp. 457–462, Aug. 2004.
OSHER, STANLEY J. & FEDKIW, R. (2002). Level Set Methods and Dynamic Implicit Surfaces. SpringerVerlag.
STAM, J., “Real-time fluid dynamics for games,” in Proceedings of the Game Developer Conference,
Mar. 2003.
39
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL