Computational Fluid Dynamics Elementary Numerical Analysis Grétar Tryggvason Spring 2011 http://www.nd.edu/~gtryggva/CFD-Course/ Computational Fluid Dynamics Outline • Finite Difference Approximations • Analysis of a Numerical Scheme • Modified Equation • Consistency • Richardson Extrapolation • Conservation Computational Fluid Dynamics Derivation of Finite Difference Approximations Computational Fluid Dynamics A second order upwind approximation to the first derivative: f ( x ! h) = f ( x) ! "f ( x) "x h + " 2 f ( x) "x 2 h 2 2 ! " 3 f ( x) "x 3 h 3 6 + " 4 f ( x) "x 4 h 4 24 ! L f ( x ! 2h) = f ( x) ! "f ( x) "x 2h + " 2 f ( x) "x 2 4 h 2 2 ! " 3 f ( x) "x 3 8h 3 6 + " 4 f ( x) "x 4 16h 4 24 !! Expand for x-h Expand for x-2h Subtract to eliminate the second derivative: Or: 4 f ( x ! h) ! f ( x ! 2h) = 3 f ( x) ! "f ( x) "x 2h + ! " 3 f ( x) "x 3 8h 3 6 + ! !f ( x) !x = 3 f ( x) " 4 f ( x " h) + f ( x " 2h) 2h + O(h 2 ) Finite Difference Approximations Computational Fluid Dynamics Subtracting the second equation from the first: f ( x + h) = f ( x) + !f ( x) !x h + ! 2 f ( x) !x 2 h 2 2 + ! 3 f ( x) !x 3 h 3 6 + ! 4 f ( x) !x 4 h 4 24 + O(h 5 ) f ( x ! h) = f ( x) ! "f ( x) "x h + " 2 f ( x) "x 2 h 2 2 ! " 3 f ( x) "x 3 h 3 6 + " 4 f ( x) "x 4 h 4 24 ! O(h 5 ) f ( x + h) ! f ( x ! h) = 2 "f ( x) "x h + 1 3 " 3 f ( x ) "x 3 h 3 + O( h 5 ) Start by expressing the value of f(x+h) and f(x-h) in terms of f(x) Finite Difference Approximations A fourth order centered approximation to the first derivative: Computational Fluid Dynamics By subtraction we found: f ( x + h) ! f ( x ! h) = 2 "f ( x) "x h + 1 3 " 3 f ( x ) "x 3 h 3 + O( h 5 ) Finite Difference Approximations Replacing h by 2h gives: f ( x + 2h) ! f ( x ! 2h) = 4 "f ( x) "x h + 8 3 " 3 f ( x ) "x 3 h 3 + O( h 5 ) f ( x + 2h) ! 8 f ( x + h) + 8 f ( x ! h) ! f ( x ! 2h) = !12 "f ( x) "x h + O(h 5 ) Subtract these two to eliminate the third derivative !f ( x) !x = f ( x " 2h) " 8 f ( x " h) + 8 f ( x + h) " f ( x + 2h) 12h + O(h 4 ) Or:
9
Embed
Finite Difference Approximations! Numerical Analysisgtryggva/CFD-Course/2011-Lecture-8.pdf · The following finite difference approximation is given (a) Write down the modified equation
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Use the leap-frog method (centered differences) to integrate the diffusion equation !
in time. Use the standard centered difference approximation for the second order spatial derivative.!(a) Write down the finite difference equation.!(b) Write down the modified equation!(c) Find the accuracy of the scheme!(d) Use the von Neuman's method to derive an equation for the amplification factor g. Hint: assume that the amplification is the same for each step:!
The following finite difference approximation is given
(a) Write down the modified equation (b) What equation is being approximated? (c) Determine the accuracy of the scheme (d) Use the von Neuman's method to derive an equation for the stability conditions
Notes:!You will do a few other schemes as homework problems.!
Generally we assume that results for the linear equations hold for the nonlinear one as well.!
The algebraic equation for the amplification factor can often be fairly complicated. It is, however, routinely solved. !
Computational Fluid Dynamics
Consistency!Does the error always
go to zero?!
Computational Fluid Dynamics
Using the finite difference approximation, we are effectively solving an equation that is slightly different than the original partial differential equations.!
Does the finite difference equation approach the partial differential equation in the limit of zero Δt and h?!
Consistency!Computational Fluid Dynamics
Consider the 1-D advection-diffusion equation!
and its finite-difference approximation!
f jn +1 ! f j
n
"t+U
f j+1n ! f j!1
n
2h= D
f j+1n ! 2 f j
n + f j!1n
h2
∂ f∂t
+U ∂ f∂x
= D ∂ 2 f∂x2
The discrepancy between the two equations can be found by deriving the modified equation.!
Consistency!
Computational Fluid Dynamics
Substituting!
f jn+1 ! f j
n
"t= #f (t)
#t+ # 2 f (t)
#t 2"t2
+!
f j+1n ! f j!1
n
2h= "f (x)
"x+ " 3 f (x)
"x 3h2
6+!
f j+1n ! 2 f j
n + f j!1n
h2= " 2 f (x)
"x 2+ " 4 f (x)
"x 4h2
12+!
into the finite difference equation!fjn+1 ! fj
n
"t+U
fj+1n ! fj!1
n
2h= D
f j+1n ! 2 fj
n + fj!1n
h2
Consistency!Computational Fluid Dynamics
!f!t
+U !f!x
"D! 2 f!x 2
= "!2 f (t)!t 2
#t2"U ! 3 f (x)
!x 3h2
6+ D! 4 f (x)
!x 4h2
12+!
In this case, the error goes to zero as h0 and Δt0, so the approximation is said to be CONSISTENT!
Results in:!
Original Equation! Error terms!
!f!t
+ U !f!x
"D! 2 f!x 2
= O(#t,h2 )
Shorthand:!
Consistency!
Computational Fluid Dynamics
Although most finite difference approximations are consistent, innocent-looking modifications can sometimes lead to approximations that are not!!
The Frankel-Dufort is an example of an non-consistent scheme.!
You will examine it in the homework!
Consistency!Computational Fluid Dynamics
HW: Examine the Frankel-Dufort method!
!f!t
= D! 2 f!x 2
Solve the diffusion equation!
Using the Leapfrog time integration method and standard finite-difference approximation for the spatial derivative gives:!
f jn+1 ! f j
n!1
2"t= Dh2
f j+1n ! 2 f j
n + f j!1n[ ]
Leapfrog method!
Consistency!
Computational Fluid Dynamics
This gives:!
f jn+1 ! f j
n!1
2"t= Dh2
f j+1n ! 2 f j
n + f j!1n[ ]
f jn =
12f jn +1 + f j
n!1( )
f jn+1 = f j
n!1 + 2"t D
h2f j+1n ! f j
n+1 ! f jn!1 + f j!1
n( ).Which is easily solved for f at the new time step!
Now modify it slightly:!
In the HW, you will examine the error!!
Replace by:!
Consistency!Computational Fluid Dynamics
The MODIFIED EQUATION is obtained by substituting the expression for the finite difference approximations, including the error terms, into the finite difference equation. For a CONSISTENT finite difference approximation the error terms go to zero as h0 and Δt0.
The modified equation can often be used to infer the nature of the error of the finite difference scheme. More about that later.!
Consistency!
Computational Fluid Dynamics
Richardson Extrapolation!
Computational Fluid Dynamics
Extrapolation to h=0:!The best way to estimate the error in a finite difference computation is to repeat the calculation on a different (finer or coarser) grid. Usually, the cost of doing another computation on a coarser grid is small. We can, however, estimate the error in the following way. Assume have a second order. The approximate solution can be written as a function of the resolution, h, as follows:!
f h( ) = f 0( ) + Ch2 + HOT
Richardson Extrapolation!
Computational Fluid Dynamics
Here, f(0) is the (unknown) exact solution and C is a constant determining the magnitude of the error. Given f(h) and f(2h), estimate C. Once C is known, we can use the above formula to find a better estimate for the solution. This procedure is called Richardson Extrapolation and is widely used in practice.!
f h( ) = f 0( ) + Ch2 + HOT
The approximate solution can be written as a Taylor series around the exact solution f(0):!
We have:!similarly, the solution on twice as coarse grid is:!
subtracting to eliminate the h2 term:!
Solving for the exact solution:!
Since the Higher Order Terms (HOT) are at least O(h3), f(0) is a better estimate than either f(h) or f(h2). Similar formulas can be derived for schemes of different orders.!
f h( ) = f 0( ) + Ch2 + HOT
f 2h( ) = f 0( ) + C4h2 + HOT
4 f h( ) ! f 2h( ) = 4 f 0( ) ! f 0( ) + HOT
f 0( ) =4 f h( ) ! f 2h( )
3+ HOT
Richardson Extrapolation!
Computational Fluid Dynamics
For an n-th order scheme we have:!
similarly, the solution on twice as coarse grid is:!
If F = 0 at the end points of the domain, f is conserved.!
Integrating over the domain L,!
�
∂f∂tdx
L∫ +
∂F∂x
dxL∫ = 0
�
F(L) − F (0) = 0
�
⇒ddt
fdxL∫ = 0
Conservative Schemes!
Computational Fluid Dynamics
�
∂f∂t
+ ∂∂x
12f 2
⎛ ⎝ ⎜
⎞ ⎠ ⎟ = 0
Examples of Conservative Form!
Discretize using upwind !
�
∂∂x
12f 2
⎛ ⎝ ⎜
⎞ ⎠ ⎟ ≈
12h
fi2 − f i−1
2( ) Conservative!�
∂f∂t
+ f ∂f∂x
= 0
�
f ∂f∂x
≈ f ih
f i − f i−1( ) Non-conservative!
versus!
Conservative Schemes!Computational Fluid Dynamics
�
∂F∂x
dxL∫ ≈ Fj+1/ 2 − Fj−1/ 2∑ =
+ fi−12 − f i−2
2 + f i2 − f i−1
2 + f i+12 − fi
2 +
�
∂F∂x
dxL∫ ≈ Fj+1/ 2 − Fj−1/ 2∑ =
+ fi−12 − f i−1 f i + f i
2 − f i f i−1 + f i+12 − f i+1 f i +
�
∂∂x
12f 2
⎛ ⎝ ⎜
⎞ ⎠ ⎟ ⎞ ⎠ ⎟ i
≈ 12h
fi2 − f i−1
2( )
�
f ∂f∂x
⎞ ⎠ ⎟ i
≈ f ih
fi − f i−1( )
Conservative Schemes!
Computational Fluid Dynamics
�
∂f∂t
+ ∂∂x
µ(x) ∂f∂x
⎛ ⎝ ⎜
⎞ ⎠ ⎟ = 0
Another example (variable diffusion coefficient)!
Discretize !
�
∂∂x
µ(x) ∂f∂x
⎛ ⎝
⎞ ⎠
Conservative!
�
µ∂2 f∂x 2
+∂µ∂x
∂f∂x
Non-conservative!
versus!
Conservative Schemes!Computational Fluid Dynamics
�
∂f∂t
+ f ∂f∂x
= 0
�
f ∂f∂t
+ f ∂f∂x
⎛ ⎝ ⎜
⎞ ⎠ ⎟ = 0
�
∂∂t
f 2
2+ ∂∂x
f 3
3= 0
�
ddt
f 2
2dx∫ = − ∂
∂xf 3
3dx∫ = f 3
3⎡
⎣ ⎢
⎤
⎦ ⎥ −∞
∞
= 0
�
f ∞( ) = f −∞( ) = 0
�
ddt
f n
ndx∫ = 0
Similarly, it can be shown that!
Conservation of higher order quantities!Consider:!
Integrate:!
Conservative Schemes!
Computational Fluid Dynamics
Generally it is believed that conservative schemes are superior to non-conservative ones and that the more conserved quantities the discrete approximation preserves, the better the scheme. While mostly true, there are exceptions as we will discuss later!!