Professional Documents
Culture Documents
Finite Difference
Approximations-II
CFD Computational Fluid Dynamics
Outline
2
Solving
Partial Differential
Equations
CFD Computational Fluid Dynamics
Model Equations
4
∂f ∂f ∂ f 2
+U =D 2
∂t ∂x ∂x
to demonstrate how to solve a partial differential equation
numerically.
Although this equation is much simpler than the full
Navier Stokes equations, it has both an advection term
and a diffusion term.
Before attempting to solve the equation, it is useful to
understand how the analytical solution behaves.
CFD Computational Fluid Dynamics
Model Equations
5
Finite Difference
Approximations of
the Derivatives
CFD Computational Fluid Dynamics
Finite Difference Approximations
7
Time derivative
∂f (t ) ∂ 2 f (t ) ∆t 2
f (t + ∆t ) = f (t ) + ∆t + +⋯
∂t ∂t 2
2
∂f (t ) f (t + ∆t ) − f (t ) ∂ 2 f (t ) ∆t
= − +⋯
∂t ∆t ∂t 2
2
CFD Computational Fluid Dynamics
Finite Difference Approximations
9
∂f ( x)
Spatial first-order derivative:
∂x
When using FINITE DIFFERENCE approximations,
the values of f are stored at discrete points.
h h
∂f ( x) ∂ 2 f ( x) h 2 ∂ 3 f ( x) h 3 ∂ 4 f ( x) h 4
f ( x + h) = f ( x ) + h+ + + +⋯
∂x ∂x 2
2 ∂x 3
6 ∂x 24
4
∂f ( x) ∂ 2 f ( x) h 2 ∂ 3 f ( x) h 3 ∂ 4 f ( x) h 4
f ( x − h) = f ( x ) − h+ − + −⋯
∂x ∂x 2
2 ∂x 3
6 ∂x 24
4
∂f ( x) ∂ 3 f ( x) h 3
f ( x + h) − f ( x − h) = 2 h+2 +⋯
∂x ∂x 3
6
CFD Computational Fluid Dynamics
Finite Difference Approximations
11
∂f ( x) f ( x + h) − f ( x − h) ∂ f ( x) h
3 2
= − +⋯
∂x 2h ∂x 3
6
⇒ Second order central differencing
CFD Computational Fluid Dynamics
Finite Difference Approximations
12
∂x 2
h h
CFD Computational Fluid Dynamics
Finite Difference Approximations
13
∂f ( x) ∂ 2 f ( x) h 2 ∂ 3 f ( x) h 3 ∂ 4 f ( x) h 4
f ( x + h) = f ( x ) + h+ + + +⋯
∂x ∂x 2
2 ∂x 3
6 ∂x 24
4
∂f ( x) ∂ 2 f ( x) h 2 ∂ 3 f ( x) h 3 ∂ 4 f ( x) h 4
f ( x − h) = f ( x ) − h+ − + −⋯
∂x ∂x 2
2 ∂x 3
6 ∂x 24
4
∂f 2 ( x) h 2 ∂ 4 f ( x) h 4
f ( x + h) + f ( x − h) = 2 f ( x ) + 2 +2 +⋯
∂x 2
2 ∂x 24
4
CFD Computational Fluid Dynamics
Finite Difference Approximations
14
∂f 2 ( x) h 2 ∂ 4 f ( x) h 4
f ( x + h) + f ( x − h) = 2 f ( x ) + 2 +2 +⋯
∂x 2
2 ∂x 24
4
∂ 2 f ( x ) f ( x + h) − 2 f + f ( x − h) ∂ 4 f ( x ) h 2
= − +⋯
∂x 2
h 2
∂x 12
4
Solving Partial
Differential Equations
CFD Computational Fluid Dynamics
Finite Difference Approximations
16
A numerical approximation to
∂f ∂f ∂2 f
+U =D 2
∂t ∂x ∂x
is found by replacing the derivatives by the following
approximations
n
∂f ∂f ∂ f
n n 2
+ U = D 2
∂t j ∂x j ∂x j
n+1
fj
f jn−1 f jn f jn+1 ∆t
h h
CFD Computational Fluid Dynamics
Finite Difference Approximations
17
Solving for the new value and dropping the error terms yields
n +1 U∆t n D∆t n
f j = f −j
n
( f j +1 − f j −1 ) + 2 ( f j +1 − 2 f jn + f jn−1 )
n
2h h
CFD Computational Fluid Dynamics
Finite Difference Approximations
19
n +1 U∆t n D∆t n
f j = f −
j
n
( f j +1 − f j −1 ) + 2 ( f j +1 − 2 f jn + f jn−1 )
n
2h h
The value of every point at level n+1 is given
explicitly in terms of the values at the level n.
f jn+1
Forward in Time,
f n
fj n
f n ∆t Central in Space
j −1 j +1
(FTCS)
h h
CFD Computational Fluid Dynamics
20
Example:
A short MATLAB program
The model equation is computed by the spatial
differencing and time integration.
Domain length = 2
Two waves (wavelength = 1)
Periodic boundary conditions.
21
22
Evolution
for
U=1;
D=0.05;
k=1
N=21
∆t=0.05
Exact
Numerical
CFD Computational Fluid Dynamics
23
Accuracy
CFD Computational Fluid Dynamics
24
-1
Exact
0 0.5 1 1.5 2
Numerical x
CFD Computational Fluid Dynamics
Accuracy
26
Repeat with
m = 20, time = 0.50
a smaller 1
time-step
∆t=0.025 0.5
f(x,t)
0
-0.5
-1
Exact
0 0.5 1 1.5 2
Numerical x
CFD Computational Fluid Dynamics
Accuracy
27
Repeat with
m = 40, time = 0.50
a smaller 1
time-step
∆t=0.0125 0.5
f(x,t)
0
-0.5
-1
Exact
0 0.5 1 1.5 2
Numerical x
CFD Computational Fluid Dynamics
Accuracy
28
29
Exact
time=0.50
Numerical
n=11; E = 0.1633
n=21; E = 0.0403
n=41; E = 0.0096
n=61; E = 0.0041
n=81; E = 0.0022
n=101; E = 0.0015
N n=121; E = 0.0011
E=h ∑( f
j =1
j − fexact )
2
n=161; E = 9.2600e-04
CFD Computational Fluid Dynamics
Order of Accuracy
31
time=0.50
0
10
Accuracy. Effect of
spatial resolution 10
-1
dt = 0.0005
-2
N = 11 to N = 161 E 10
10-3
10-4 0
10 101 102
1/ h
CFD Computational Fluid Dynamics
Order of Accuracy
32
N
~ −2
E = CN
(
~ −2
)~
ln E = ln C N = ln C − 2 ln N
time=0.50
0
Accuracy. Effect of 10
spatial resolution
-1
10
dt = 0.0005
-2
E 10 2
?
N = 11 to N = 161 1
10-3
10-4 0
10 101 102
1/ h
CFD Computational Fluid Dynamics
34
Why is does the error deviate from the line for the
highest values of N?
Total
Error
Roundoff
Truncation
35
Order of Accuracy
f ( x) = e ikx
δf f j +1 − f j −1
= , ∆ = L/ N
δx j 2∆
sin( 2πn / N )
k′ =
∆
CFD Computational Fluid Dynamics
Modified Wave Number
40
Summary:
2π 2π n
k= n; k∆ =
L N
sin(2π n / N ) 2π n
k′ = ; k ′∆ = sin( )
∆ N
CFD Computational Fluid Dynamics
Modified Wave Number
41
3 Exact
2nd Order Central
4th Order Central
6th Order Central
4th Order Pade
6th Order Pade
2
k'∆
0
0 1 2 3
k∆
CFD Computational Fluid Dynamics
Enhancing Accuracy - Padé Scheme
42
12h
4th Order Padé Scheme:
4
3 h
f j′+1 + 4 f j′ + f j′−1 = ( f j +1 − f j −1 ) +
v
fj
h 30
Tridiagonal system of equations for f j′
CFD Computational Fluid Dynamics
43
Stability
CFD Computational Fluid Dynamics
Stability
44
Evolution
for
U=1;
D=0.05;
k=1
N=21
∆t=0.2
Exact
Numerical
CFD Computational Fluid Dynamics
Stability
46
Stability Analysis of
1st Order ODE
(Euler Method)
CFD Computational Fluid Dynamics
Stability
48
y ' = f ( y, t ), y (0) = y0
Stability analysis seeks the conditions (of stepsize h)
for which the numerical solution remains bounded.
Taylor Expansion:
f ( y, t ) = f ( y0 , t0 ) + ( y − y0 ) f ′( y0 , t0 )
′ [
+(t − t0 ) f ( y0 , t0 ) + O ( y − y0 ) , (t − t0 )
2 2
]
y′ = λy + α + βt + ⋯
CFD Computational Fluid Dynamics
Stability
49
yn +1 = yn + λhyn = yn (1 + λh)
Solution at time step n
yn = y0 (1 + λh) n
CFD Computational Fluid Dynamics
Stability
50
1 + λh ≤ 1 ( λ = λ R + iλ I )
λI h
Stability boundary
(1 + λR h) + λI h = 1
2 2 2
1
h≤
2 −1 λR h
λ −1
CFD Computational Fluid Dynamics
Stability
51
Stability Analysis of
Advection-Diffusion Equation:
Von Neumann Method
CFD Computational Fluid Dynamics
Stability
52
∂f ∂f ∂2 f
+U =D 2
∂t ∂x ∂x
In finite-difference form:
Substitute
f jn = f j,exact
n
+ ε nj
(f n +1
j ,exact ) (
+ ε nj +1 − f jn,exact + ε nj )+
∆t
U
( f n
j +1,exact ) (
+ ε nj+1 − f jn−1,exact + ε nj−1 )=
2h
D
( ) ( ) (
f jn+1,exact + ε nj+1 − 2 f jn,exact + ε nj + f jn−1,exact + ε nj−1 )
h2
CFD Computational Fluid Dynamics
Stability
55
n
f
Since j ,exact satisfies the equation, we get
ε =ε e
n
j
n ikx j
CFD Computational Fluid Dynamics
Stability
56
Substituting
ε =ε e
n
j
n ikx j
ε n
j +1 =ε e n ikx j
e ikh
ε n
j −1 =ε e
n ikx j
e
−ikh
into
ε nj +1 − ε nj ε nj+1 − ε nj−1 ε nj+1 − 2ε nj + ε nj−1
+U =D
∆t 2h h2
yields
ε n +1e − ε ne εn
ikx j ikx j
+U − e −ikh e )=
ikx j ikx j
(e ikh e
∆t 2h
εn
− 2e + e −ikh e
ikx j ikx j ikx j
D 2
(eikh e )
h
CFD Computational Fluid Dynamics
Stability
58
ε n +1
U∆t ikh −ikh D∆t ikh −ikh
= 1 − ( e − e ) + ( e − 2 + e )
ε n
2h h 2
U∆t D∆t
=1− 2i sin kh + 2 2(cos kh − 1)
2h h
or
D∆t 2 h U∆t
= 1 − 4 2 sin k − i sin kh
h 2 2h
CFD Computational Fluid Dynamics
Stability
59
ε n+1 D∆t 2 h
n = 1− 4 2 sin k
ε h 2
Since sin () ≤ 1 the amplification factor is always
2
D∆t 1
2
≤
h 2
CFD Computational Fluid Dynamics
Stability
61
D∆t 1 U 2
∆t
2
≤ and ≤2
h 2 D
or
2D h2
∆t ≤ Min 2 ,
U 2D
D∆t 1 (| U | + | V |) 2
∆t
2
≤ and ≤4
h 4 D
D∆t 1 (| U | + | V | + | W |) 2 ∆t
2
≤ and ≤6
h 6 D
CFD Computational Fluid Dynamics
Stability
65
66
Consistency
Does the error always
go to zero?
CFD Computational Fluid Dynamics
Consistency
67
∂f ∂f ∂2 f
+U =D 2
∂t ∂x ∂x
and its finite-difference approximation
Substituting
f jn +1 − f jn ∂f (t ) ∂ 2 f (t ) ∆t
= − +⋯
∆t ∂t ∂t 2
2
f n
j +1 −f n
j −1 ∂f ( x) ∂ f ( x) h
3 2
= − +⋯
2h ∂x ∂x 3
6
f jn+1 − 2 f jn + f jn−1 ∂ 2 f ( x) ∂ 4 f ( x) h 2
= − +⋯
h 2
∂x 2
∂x 12
4
70
∂f ∂f ∂2 f
+U −D 2 =
∂t ∂x ∂x
∂ 2 f (t ) ∆t ∂ 3 f ( x) h 2 ∂ 4 f ( x) h 2
+ + U − D + ⋯ = O ( ∆t , h 2
)
∂t 2
2 ∂x 3
6 ∂x 12
4