You are on page 1of 10

Computational Fluid Dynamics I

Computational Fluid Dynamics I


http://users.wpi.edu/~gretar/me612.html Outline

The Advection- Advection Diffusion equation


The cell Reynolds number
Diffusion Equation-I

Grétar Tryggvason
Worcester Polytechnic Institute,
Spring 2009

Computational Fluid Dynamics I Computational Fluid Dynamics I

1D Advection/diffusion equation
∂f ∂f ∂2 f
+U = D 2
∂t ∂x ∂x
Methods for the Forward in time/centered in space (FTCS)
f jn +1 − f jn f n − f j−1
n
f n − 2 f jn + f j−1
n

advection-diffusion € Δt
+ U j +1
2h
= D j +1
h 2

Stability limits
equation UΔt
2D
≤1 &
DΔt 1
h2

2
R=
UL
D

2D h2
Δt = & Δt =
U 2D

Δt → 0 For high and low D


Computational Fluid Dynamics I Computational Fluid Dynamics I

∂f ∂f ∂2 f
+U = D 2
∂t ∂x ∂x

FTCS O(Δt,h 2 ) UΔt DΔt 1


2D
≤1 &
h2

2 The Cell Reynolds
UΔt DΔt


Upwind O(Δt,h )

h
+ 2 2 ≤1
h number
 UΔt  2  DΔt 
L-W O(Δt 2 ,h 2 )   ≤ 2 2  ≤ 1
 h   h 
€ €
C-N O(Δt ,h 2 )
2
Unconditionally stable
€ €


Computational Fluid Dynamics I Computational Fluid Dynamics I

Steady state solution to the advection/diffusion equation


1

∂f ∂2f 0.9
U =D 2
∂x ∂x 0.8

RL=1 0.7

U RL=5 0.6
f =0 f =1 RL=10 0.5

RL=20 0.4
L
0.3

€Exact solution € 0.2

0.1

exp( RL x€
/ L) − 1 UL
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
f = RL =
exp( RL ) − 1 D

€ €

Computational Fluid Dynamics I Computational Fluid Dynamics I

Numerical solution of: Centered difference approximation


2 fj +1 − f j −1 f j +1 − 2 f j + f j −1
∂f ∂ f U =D
U =D 2 2h h2
∂x ∂x
Rearrange:
Centered difference approximation Uh 2
f j +1 − f j−1 f − 2 f j + f j−1
( f − f j −1 ) = f j +1 − 2 f j + f j −1
2hD j +1
€ U = D j +1
2h h2 Rearrange:
Upwind ( R − 2) f j +1 + 4 f j − ( R + 2) f j −1 = 0
f − f j−1 f − 2 f j + f j−1
U j = D j +1 Uh
€ h h2 Where: R =
D

Computational Fluid Dynamics I Computational Fluid Dynamics I

( R − 2) f j +1 + 4 f j − ( R + 2) f j −1 = 0 ( R − 2)q2 + 4q1 − ( R + 2 ) = 0
Solution Solving for q gives two solutions:
j
fj = q 2+R
q1 = 1 and q2 =
Substitute: 2− R
( R − 2)q j +1 + 4q j − ( R + 2)q j −1 = 0 The general solution is:
j j
j −1 f j = C1 q1 + C2 q2
Divide by q
or
j
( R − 2)q2 + 4q1 − ( R + 2 ) = 0  2 + R
f j = C1 + C2
 2 − R
Computational Fluid Dynamics I Computational Fluid Dynamics I

Upwind
Apply the boundary conditions f j − f j−1 f − 2 f j + f j−1
U = D j +1
 2 + R
0
h h2
f 0 = C1 + C2  = C1 + C2 = 0 or
2 − R (R + 2) f j − (R + 1) f j−1 − f j +1 = 0 Uh
N R=
 2 + R fj =qj D
f N = C1 + C2  =1 € Try solutions
2 − R
The final solution is: € giving
j q 2 − ( R + 2)q1 + ( R + 1) = 0
 2 + R €
  −1
f j = 2 − R N +1 Solution j
 2 + R 1− (1+ R)
−1 fj = N
 2 − R € 1− (1+ R)

Computational Fluid Dynamics I Computational Fluid Dynamics I

Exact solution Upwind


exp( RL x / L) − 1 UL Exact
f = RL =
exp( RL ) − 1 D
Centered
Centered differences
€ j €
 2 + R
  −1
f j = 2 − R N +1
 2 + R
−1
 2 − R Uh
R=
Upwind D
j
1− (1+ R)
fj = N
1− (1+ R)

Computational Fluid Dynamics I Computational Fluid Dynamics I

Upwind Upwind
Exact Exact
Centered Centered
Computational Fluid Dynamics I Computational Fluid Dynamics I

2D example
When centered differencing is used for the
advection/diffusion equation, oscillations may ∂ 2 f ∂ 2 f 
∂f ∂f ∂f
appear when the Cell Reynolds number is +U + V = D 2 + 2 
higher than 2. For upwinding, no oscillations ∂t ∂x ∂y  ∂x ∂y 
appear. In most cases the oscillations are
small and the cell Reynolds number is
f =0
frequently allowed to be higher than 2 with
relatively minor effects on the result. €
Flow Compuitations
f =1 using centered
Uh differences on a
R= <2 €
D 32 by 32 grid
f =0


Computational Fluid Dynamics I Computational Fluid Dynamics I

Recell=3.2258 Recell=6.4516

D=0.02 D=0.01
t=1.5088 t=1.5088

Computational Fluid Dynamics I Computational Fluid Dynamics I

Recell=12.9032 D=0.02
D=0.005 t=1.50
t=1.5088
Fine grid Coarser grid
Recell=3.2258 Recell=6.6716
1.5
1.5

1
1

0.5
0.5

0
0
30
25 15
30
20 25 15
15 20 10
10 15 10
5 10 5
5 5
0 0
0 0
Computational Fluid Dynamics I Computational Fluid Dynamics I
http://users.wpi.edu/~gretar/me612.html Outline

Higher order in space


The Advection- QUICK
Compact schemes
Diffusion Equation-II Conservation of energy
Higher order in time for
the ω-ψ formulation

Grétar Tryggvason
Worcester Polytechnic Institute,
2009

Computational Fluid Dynamics I Computational Fluid Dynamics I

Higher order finite difference approximations

The simplest approach is to use more points:

Higher order f(x-2h) f(x-h) f(x) f(x+h) f(x+2h)

in space h h

Computational Fluid Dynamics I Computational Fluid Dynamics I

Centered
∂f  f j−2 − 8 f j−1 + 8 f j +1 − f j +2
 = + O(h 4 )
∂x  j 12h
∂ 2 f  − f j−2 + 16 f j−1 − 30 f j + 16 f j +1 − f j +2
 = + O(h 4 ) Compact schemes
∂x 2  j 12h 2

Skewed
∂f  f j−2 − 6 f j−1 + 3 f j + 2 f j +1
 = + O(h 3 )
€ ∂x  j 6h


Computational Fluid Dynamics I Computational Fluid Dynamics I

Solution of the vorticity-streamfunction equations By a Taylor series expansion the following forth order
 ∂ 2ω ∂ 2ω  relations between the values of f and the derivatives of
∂ω ∂ψ ∂ω ∂ψ ∂ω f can be derived
= − + ν 2 + 2 
∂t ∂x ∂y ∂ y ∂x  ∂x ∂x  3
∂ 2ψ ∂ 2ψ ( f x ) i+1, j + 4( f x ) i, j + ( f x ) i−1, j =
h
( f i+1, j − f i−1, j ) (1)
+ = −ω
∂x 2 ∂x 2 3
( f y )i, j +1 + 4( f y )i, j + ( f y )i, j−1 = h ( f i, j +1 − f i, j−1) (2)
€ Use “compact schemes” to find O(h4)
approximations for the spatial derivatives 12

( f xx ) i+1, j + 10( f xx ) i, j + ( f xx ) i−1, j =
h2
( f i+1, j − 2 f i, j + f i−1, j ) (3)

12
( f yy )i, j +1 + 10( f yy )i, j + ( f yy )i, j−1 = h 2 ( f i, j +1 − 2 f i, j + f i, j−1) (4)

Computational Fluid Dynamics I Computational Fluid Dynamics I

The vorticity-streamfunction equations at grid point i,j are 1. Given the vorticity, ω, we solve tridiagonal
equations (1-4) for ω x , ω y , ω xx , ω yy
 ∂ω   ∂ψ   ∂ω   ∂ψ   ∂ω 
  =     −    2. For ψ use (3) and (4) plus the elliptic equation
 ∂t  i, j  ∂x  i, j  ∂y  i, j  ∂y  i, j  ∂x  i, j
for the streamfunction (6) for ψ xx , ψ yy , ψ
 ∂ 2ω   ∂ 2ω  
+ ν  2  +  2   (5) 3. Then €
use 1 and 2 for (tridiagonal systems) ψ x , ψ y
 ∂x  i, j  ∂x  i, j 
 ∂ 2ψ   ∂ 2ψ  4. Everything on the right hand side of (5) is now

 2  +  2  = −ω i, j known to O(h4) accuracy and
 ∂x  i, j  ∂y  i, j (6)
€ ∂ψ €
To find the time derivative, we need ∂t
can be found
€ ψ x , ψ y , ψ xx , ψ yy , ω x , ω y , ω xx , ω yy

Computational Fluid Dynamics I Computational Fluid Dynamics I

The main advantage of compact schemes


is that it is somewhat easier to implement
Higher order
boundary conditions than for high order
schemes that use a broad stencil upwind
QUICK
Computational Fluid Dynamics I Computational Fluid Dynamics I

s=5/2 s=5/2 Use to solve:


s=1 s=2 s=3 s=4 s=1 s=2 s=3 s=4 ∂f 1 ∂f 2 ∂2 f
+ =D 2
f1 f2 f3 f4 f1 f2 f3 f4 ∂t 2 ∂x ∂x

Linear interpolation: At s = 5/2


1-2: ( 2 − s) f1 + ( s − 1) f 2 f 5 / 2 = (1/8)[ 3 f 3 + 6 f 2 − f1]
2-3: ( 3−
s) f 2 + ( s − 2) f 3 €

Quadratic interpolation: ∂f 2  1 2 2
€ 1-3: Add the above: €  ≈ { f i+1/ 2 − f i−1/ 2 }
∂x  i h
€ 0.5 ( 3− s)[( 2 − s) f1 + ( s − 1) f 2 ] + 0.5( s − 1)[( 3− s) f 2 + ( s − 2) f 3 ]
1 2 2

At s = 5/2
=
64h
{
[3 f i+1 + 6 f i − f i−1 ] − [3 f i + 6 f i−1 − f i− 2 ] }
f 5 / 2 = (1/8)[ 3 f 3 + 6 f 2 − f1]


Computational Fluid Dynamics I Computational Fluid Dynamics I

∂f 1 ∂f 2 ∂2 f
+ =D 2
∂t 2 ∂x ∂x
∂f 1 ∂f 2 ∂2 f
+ =D 2 10
∂t 2 ∂x ∂x 10

9
Centered
9

8
8
€ QUICK 7
7

6
Upwind 6

€ 5 5

4 4
Centered 3 3

QUICK 2 2

Upwind 1 1

0 0
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40

Re_cell=10 Re_cell=20

Computational Fluid Dynamics I Computational Fluid Dynamics I

Conservation of kinetic energy on a centered


regular mesh
∂f ∂f 1
Consider:
∂t
+ f
∂x
=0 Define: E kin =
2
∫ f 2 dx

Conservation of Multiply by f and integrate


 ∂f ∂f 
kinetic energy € ∫  f ∂t + f 2
dx = 0€
∂x 

Therefore:
d 1 1 ∂f 3 The kinetic

dt
∫2f 2
dx = − ∫
3 ∂x
dx = 0 energy is
conserved


Computational Fluid Dynamics I Computational Fluid Dynamics I

Consider two different discretizations of the Check conservation:


nonlinear term First scheme:
∂f ∂f h  ∂f 2  1
=−f ≈ − f i ( f i+1 − f i−1 ) /2h d 1 2 
∫2f dx = −∑ f j  = −∑  f j ( f j +1 − f j−1 )
2 2
∂t ∂x 
dt 2  ∂x  j 2 
and
1 1
∂f 1 ∂f 2 1 2 =…+ f j−1 ( f j2 − f j−2
2
) + 2 f j ( f j2+1 − f j−12) + … ≠ 0
=− ≈ − ( f i+1 2
− f i−1 ) /2h 2
€ ∂t 2 ∂x 2
€ Second scheme:
Both conserve f d 1 2  ∂f 
€∫ f dx = −∑ f j h f  = −∑{ f j ( f j +1 − f j−1 )}
2

€ dt 2  ∂x  j
Is f2 conserved?
= … + f j−1
2
( f j − f j−2 ) + f j2 ( f j +1 − f j−1) + … ≠ 0

Computational Fluid Dynamics I Computational Fluid Dynamics I

Combine both schemes: = … + α ( f j−1 f j−2 ) +


(1− α )
2 2
f j − f j−1
2
(f j−1 f j2 − f j−1 f j−2
2
)+
∂f 1  (1− α ) f 2 − f 2 
∂t
≈ − α f i ( f i+1 − f i−1 ) −
2h  2
( i+1 i−1) (1− α )
α ( f j2 f j +1 − f j2 f j−1 ) − (f j f j2+1 − f j f j−1
2
) +… = 0
2
Write out the terms for the kinetic energy
α−
(1− α ) = 0 3α −1
=0 1
α=
€ ∂f 2 1  (1− α )  2 2 3
∫ ∂t dx ≈ − 2 ∑ α f j2 ( f j +1 − f j−1) − 2 f j ( f j2+1 − f j−12) €
∂f 1
≈ − { f i ( f i+1 − f i−1 ) − ( f i+1
2 2
− f i−1 )}
(1− α ) f ∂t 6h
= … + α f j−1
2
( f j − f j−2 ) + 2
j−1 (f 2
j
2
− f j−2 )+ € €
1  f + f i + f i−1 € 
= −  i+1 ( f i+1 − f i−1)
€ (1− α ) f 2h  3 
α f j2 ( f j +1 − f j−1 ) −
2
j (f 2
j +1
2
− f j−1 ) +… = 0 Conserves both f and f2


Computational Fluid Dynamics I Computational Fluid Dynamics I

The Jacobian can be written in several ways


The same idea is used in Arakawaʼs scheme
(JCP 119, 1966) ∂ψ ∂ω ∂ψ ∂ω
J (ψ,ω ) = −
∂x ∂y ∂y ∂ x
Consider the vorticity advection equation
∂  ∂ω  ∂  ∂ω 
∂ω = ψ  − ψ 
+ u ⋅ ∇ω = 0 ∂x  ∂ y  ∂y  ∂x 
∂t
Rewrite the nonlinear terms to introduce the Jacobian ∂  ∂ψ  ∂  ∂ψ 
= ω  − ω 
∂ψ ∂ω ∂ψ ∂ω ∂y  ∂ x  ∂x  ∂y 
u ⋅ ∇ω = − + = J (ψ,ω )
€ ∂y ∂x ∂ x ∂y since
giving ∂  ∂ω  ∂ψ ∂ω ∂ 2ω
ψ = −ψ
∂ω € ∂x  ∂ y  ∂x ∂ y ∂x∂y
+ J (ψ,ω ) = 0
€ ∂t and so on



Computational Fluid Dynamics I Computational Fluid Dynamics I

we also have Discretization


1
J (ψ,ω ) = −J (ω,ψ ) J1i, j =
4h 2
{(ω i+1, j − ω i−1, j )(ψ i, j +1 − ψ i, j−1)
since − (ω i, j +1 − ω i, j−1 )(ψ i+1, j − ψ i−1, j )}
∂ψ ∂ω ∂ψ ∂ω  ∂ω ∂ψ ∂ω ∂ψ 
€ J (ψ,ω ) = − = − −  1
∂x ∂y ∂y ∂ x  ∂x ∂y ∂y ∂ x  J i,2 j =
4h 2
{ω i+1, j (ψi+1, j +1 − ψ i+1, j−1) − ω i−1, j (ψ i−1, j +1 − ψ i−1, j−1)
€ − ω i, j +1 (ψ i+1, j +1 − ψ i−1, j +1 ) − ω i, j−1 (ψ i+1, j−1 − ψ i−1, j−1 )}
Discretization of the different forms of
€ the Jacobian give schemes with slightly 1
different conservation properties
J i,3 j =
4h 2
{−ψi+1, j (ω i+1, j +1 − ω i+1, j−1) + ψ i−1, j (ω i−1, j +1 − ω i−1, j−1)
€ + ψ i, j +1 (ω i+1, j +1 − ω i−1, j +1 ) − ψ i, j−1 (ω i+1, j−1 − ω i−1, j−1 )}

Computational Fluid Dynamics I Computational Fluid Dynamics I

Arakawa showed that

1 1
J1i, j =
3
(Ji, j + Ji,2 j + Ji,3 j ) Higher order
Conserves both the vorticity and the kinetic energy in time for the vorticity-

Arakawa also presented a fourth order scheme with streamfunction
the same properties
formulation

Computational Fluid Dynamics I Computational Fluid Dynamics I

Leapfrog
ω i,n +1 n−1
j − ω i, j
Due to the relatively straightforward coupling = −J i,n j + ν∇ 2hω i,n−1
j
2Δt
between the elliptic equation for the
streamfunction and the vorticity advection- Adams-Bashford/Crank-Nicholson
diffusion equation, the algorithms discussed ω i,n +1 n
j − ω i, j 1 ν 2 n +1
already can be used with ease. = − ( 3J i,n j − J i,n−1
j )+ (∇ hω i, j + ∇ 2hω i,n j )
€ Δt 2 2
Predictor-corrector
ω˜ i, j − ω i,n j
= −J i,n j + ν∇ 2hω i,n j
€ Δt
ω i,n +1
j −ω ˜ i, j 1 ν
= − ( J i,n j + J˜i, j ) + (∇ 2hω i,n j + ∇ 2hω˜ i, j )
Δt 2 2


Computational Fluid Dynamics I Computational Fluid Dynamics I

Runge Kutta methods: take intermidiate steps 4th order Runge-Kutta method

2nd order Runge-Kutta ∇ 2hψ i,n j = −ω i,n j


Δt First half step
∇ 2hψ i,n j = −ω i,n j
ω˜ i,n +1/
j
2
= ω i,n j +
2
(−Ji,n j + ν∇ 2hω i,n j )
Δt Half step
ω˜ i, j = ω i,n j + (−J i,n j + ν∇ 2hω i,n j ) € ∇ 2hψ˜ i,n +1/
j
2
= −ω˜ i,n +1/
j
2

2 Second half step


Δt
€ ω˜˜ i,n +1/
j
2
= ω i,n j + (− J˜i,n +1/
j
2
+ ν∇ 2hω˜ i,n +1/
j
2
)
€ 2
∇ 2hψ˜ i, j = −ω˜ i, j
€ Final step
€ ∇ 2hψ˜˜ i,n +1/
j
2
= −ω˜˜ i,n +1/
j
2
Predicted
ω˜ i, j = ω + Δt (− J˜i, j + ν∇ ω˜ i, j )
n 2
˜˜ n +1/ 2 + ν∇ 2ω˜˜ n +1/ 2 final value
i, j h € ω˜ i,n +1 n
(
j = ω i, j + Δt − J i, j h i, j )



Computational Fluid Dynamics I Computational Fluid Dynamics I

4th order Runge-Kutta method (continued)

∇ 2hψ˜ i,n +1 ˜ n +1
j = −ω i, j Generating higher order methods for the
Navier-Stokes equations in the corticity/
Δt
ω i,n +1 n
j = ω i, j + (
−J i,n j − 2 J˜i,n +1/
j
2
− 2 J˜˜i,n +1/
j
2
− J˜i,n +1
j
streamfunction form is relatively straight
6 forward and any method developed for the
€ 2 ˜ n +1/ 2 advection diffusion equation can be used
+ ν∇ hω i, j + 2ν∇ hω˜ i, j + 2ν∇ hω˜ i, j + ν∇ 2hω˜ i,n +1 j )
2 n 2 n +1/ 2
without much difficulty

corrected
final value

t t + Δt /2 t + Δt

€ € €