TE2652.Finite Difference Approximation
TE2652.Finite Difference Approximation
approximation – Phương
pháp xấp xỉ Sai phân hữu
hạn
PVS.TE2652.SME.HUST 1
Ý thức:
PVS.TE2652.SME.HUST 2
Partial differential
equations – Phương trình
vi phân đạo hàm riêng
PVS.TE2652.SME.HUST 3
Numerical simulation – mô phỏng số
Object in fluid flow (fluid flow around a ship, a
submarine, a car; fluid flow in pipes system, … ):
Fluid
flow
PVS.TE2652.SME.HUST 5
Finite difference,
Finite element,
Finite volume,
Boundary element,
methods:
PVS.TE2652.SME.HUST 6
Numerical methods:
Finite differences - time-dependent PDEs
- seismic wave propagation
- geophysical fluid dynamics
- Maxwell’s equations
- Ground penetrating radar
-> robust, simple concept, easy to
parallelize, regular grids, explicit method
PVS.TE2652.SME.HUST 8
Partial Differential Equations
The Acoustic
¶ 2t p = c 2 Dp + s wave equation
- seismology
D = (¶ 2x + ¶ 2y + ¶ 2z ) - acoustics
- oceanography
P pressure - meteorology
c acoustic wave speed - Wave propagation
s sources
10
PVS.TE2652.SME.HUST
Taylor Series
Taylor series are expansions of a function f(x) for some finite distance dx to
f(x+dx)
2 3 4
dx dx dx
f ( x ± dx) = f ( x) ± dxf ' ( x) + f '' ( x ) ± f ''' ( x ) + f '''' ( x) ± ...
2! 3! 4!
Rearranging gives
f ( x + dx) - f ( x) 1 é dx 2
dx 3
ù
= êdxf ( x) +
'
f ( x) +
''
f ( x) + ...ú
'''
dx dx ë 2! 3! û
= f ' ( x) + O(dx)
Thus, it form an approximation for the first derivative:
f ( x + dx / 2) - f ( x - dx / 2) 1 é dx 3
ù
= êdxf ( x) +
'
f ( x) + ...ú
'''
dx dx ë 3! û
= f ' ( x) + O(dx 2 )
The error of the first derivative using the centered approximation is of order dx2.
Important note: it DOES matter which formulation we use! The centered scheme is
more accurate!
PVS.TE2652.SME.HUST 12
Approximations of the first derivatives
PVS.TE2652.SME.HUST 13
Error
Truncation/Discretization Error:
introduced in the solution by the
approximation of the derivative
Local Error: from each term of
the equation
Global Error: from the
accumulation of local error
Roundoff Error: introduced in the
computation by the finite number
of digits used by the computer
PVS.TE2652.SME.HUST 14
Approximations of the 2nd, 3rd, 4th
derivatives
PVS.TE2652.SME.HUST 15
Alternative Derivation
Consider an arbitrary x location:
+ What is the (approximate) value of the function or its (first, second ..) derivative
at the desired location?
+ How can we calculate the weights for the neighboring points?
f(x) f ( xj )
dx h
x
xj - 1 xj xj + 1 xj + 2 xj + 3
desiredPVS.TE2652.SME.HUST
x location 16
Alternative Derivation
f ( x)
f(x) dx
x
f ( x + dx) » f ( x) + f ' ( x)dx
f ( x - dx) » f ( x) - f ' ( x)dx
We are looking for something like
f (i )
( x ) » å w f ( xindex ( j ) )
(i )
j
j =1, L
PVS.TE2652.SME.HUST 17
2nd order weights
Deriving the second-order scheme:
+
af » af + af ' dx
-
bf » bf - bf ' dx
+ -
Þ af + bf » ( a + b) f + ( a - b) f ' dx
Interpolation Derivative
a +b =1 a+b = 0
a -b = 0 a - b = 1 / dx
PVS.TE2652.SME.HUST 18
Interpolation and difference
weights
Interpolation Derivative
æ1 1 öæ a ö æ 1 ö æ1 1 öæ a ö æ 0 ö
çç ÷÷çç ÷÷ = çç ÷÷ çç ÷÷çç ÷÷ = çç ÷÷
è1 - 1øè b ø è 0 ø è1 - 1øè b ø è1 / dx ø
The solution for the weights:
-1 -1
æ a ö æ1 1 ö æ1ö æ a ö æ1 1 ö æ 0 ö
çç ÷÷ = çç ÷÷ çç ÷÷ çç ÷÷ = çç ÷÷ çç ÷÷
è b ø è1 - 1ø è0ø è b ø è1 - 1ø è1 / dx ø
æ a ö æ1 / 2 ö æaö 1 æ 1ö
çç ÷÷ = çç ÷÷ çç ÷÷ = çç ÷÷
è b ø è1 / 2 ø è b ø 2dx è - 1ø
Can we generalize this idea to longer operators?
PVS.TE2652.SME.HUST 19
Higher order operators
Start by extending the Taylor expansion beyond f(x±dx):
(2dx) 2 (2dx) 3
a*| f ( x - 2dx) » f - (2dx) f '+ f ' '- f ''' + 𝑂(𝑑𝑥 ! )
2! 3!
We are looking for the coefficients a,b,c,d with which the function values at
x±(2)dx must be multiplied to obtain the interpolated value or the first (or
second) derivative!
PVS.TE2652.SME.HUST 20
Higher order operators
Adding up all these above equations:
af -- - +
+ bf + cf + df ++
» f (a + b + c + d ) +
dxf ' (-2a - b + c + 2d ) +
b c
dx f ' ' (2a + + + 2d ) +
2
2 2
8 1 1 8
dx f ' ' ' (- a - b + c + d )
3
6 6 6 6
We are going to find the coefficients a,b,c,d, so that the left-hand-side
yields either f, f’, f’’, f’’’
PVS.TE2652.SME.HUST 21
High-order interpolation
If you want the interpolated value:a +b + c + d =1
- 2a - b + c + 2d = 0
b c
2a + + + 2d = 0
2 2
8 1 1 8
- a- b+ c+ d =0
6 6 6 6
You need to solve the matrix system:
æ 1 1 1 1 öæ a ö æ 1 ö æ a ö æ -1/ 6ö
ç ÷ç ÷ ç ÷ ç ÷ ç ÷
ç -2 -1 1 2 ÷ç b ÷ ç 0 ÷ çb÷ ç 2/3 ÷
ç 2 1/ 2 1/ 2 2 ÷ç c ÷ =ç ÷
0 çc÷ = ç 2/3 ÷
ç ÷ç ÷ ç ÷ ç ÷ ç ÷
ç - 8 / 6 - 1 / 6 1 / 6 8 / 6 ÷ç d ÷ ç 0 ÷ ç d ÷ ç -1/ 6÷
è øè ø è ø è ø è ø
The approximation error is of order 𝒅𝒙𝟒 𝑶 (𝒅𝒙𝟒 )
PVS.TE2652.SME.HUST 22
High-order First derivative
æ 1 1 1 1 öæ a ö æ 0 ö
ç ÷ç ÷ ç ÷
ç -2 -1 1 2 ÷ç b ÷ ç1 / dx ÷
ç 2 ÷ç ÷ =ç
1/ 2 1/ 2 2 c 0 ÷
ç ÷ç ÷ ç ÷
ç - 8 / 6 - 1 / 6 1 / 6 8 / 6 ÷ç d ÷ ç 0 ÷
è øè ø è ø
æaö æ 1/ 6 ö
ç ÷ ç ÷
çb÷ 1 ç - 4 / 3÷
ç c ÷ = 2dx ç 4 / 3 ÷
ç ÷ ç ÷
çd ÷ ç -1/ 6 ÷
è ø è ø
Idea: replace the derivatives in the heat equation with finite difference
approximations. We consider the relationships between u at (x, t) and its
neighbors a distance ∆x apart and at a time ∆t later.
PVS.TE2652.SME.HUST 24
Solving the heat equation
Substituting gives:
PVS.TE2652.SME.HUST 25
Solving the heat equation
Re-arranging:
Implementation:
+ Subdivide the spatial interval [0, 1] into N + 1 equally spaced sample points xn = n∆x.
+ Subdivide the time interval [0, T] into M + 1 equal time levels tk = k∆t.
PVS.TE2652.SME.HUST 26
Solving the heat equation
At each of these space-time sample points, we introduce approximations:
PVS.TE2652.SME.HUST 27
Solving the heat equation
Implementing Boundary Conditions:
"
→ 𝑢!" = 0; 𝑢# = 0;
PVS.TE2652.SME.HUST 28