FDM Fem
FDM Fem
Georgy Gimel’farb
1 / 39
Outline Finite Differences Difference Equations FDM FEM
1 Finite Differences
2 Difference Equations
Learning outcomes:
• Be familiar with the finite difference models and methods (Euler FDMs)
• Optional: Runge-Kutta FDMs, more accurate FEMs
Recommended reading:
• M. T. Heath, Scientific Computing: An Introductory Survey. McGraw-Hill, 2002: Chapters 5, 8 – 11
• M. Shäfer, Computational Engineering - Introduction to Numerical Methods. Springer, 2006: Chapters 3, 5
• G. Strang, Computational Science and Engineering. Wellesley-Cambridge Press, 2007: Chapters 1.2, 3, 6
2 / 39
Outline Finite Differences Difference Equations FDM FEM
3 / 39
Outline Finite Differences Difference Equations FDM FEM
u(x+2∆x)−2u(x+∆x)+u(x)
= lim ∆x2
∆x→0
4 / 39
Outline Finite Differences Difference Equations FDM FEM
Mass m
x
Displacement x
u u
x x
∆x
6 / 39
Outline Finite Differences Difference Equations FDM FEM
• Results of testing:
du(x)
• The centred difference gives the exact derivative dx = 2x
7 / 39
Outline Finite Differences Difference Equations FDM FEM
dn u(x)
; 1≤n≤∞
dxn
n u(x)
• Given u(x0 ) and d dxn ; n = 1, 2, . . ., at x = x0 , the
x=x0
value u(x0 + h) at x = x0 + h is represented by the Taylor’s
series of the values at x = x0 :
∞ n dn (u(x)
P h
u(x0 + h) = u(x0 ) + n! n
n=1 dx
| {z x=x}0
≡u[n] (x0 )
∞
P hn [n]
≡ u(x0 ) + n! u (x0 )
n=1
8 / 39
Outline Finite Differences Difference Equations FDM FEM
1 1
u(0+h) ≡ 2
= 1−h2 +h4 −. . . ⇒ u(1) = = 1 − 1 + 1 − 1 + . . .
1+h 2
• Trivial for any polynomial
du(x) d2 u(x) d3 u(x)
• u(x) = x3 − 2 ⇔ u(1) = 1; dx
= 3x2 ; dx2
= 6x; dx3
= 6:
h2 h3
⇒ u(1 + h) = −1 + 3h + 6 +6 = −1 + 3h + 3h2 + h3
2 6
9 / 39
Outline Finite Differences Difference Equations FDM FEM
u(x+h)−u(x)
h = u0 (x) + 12 hu00 (x) + . . .
u(x)−u(x−h)
h = u0 (x) + 12 hu00 (x) + . . .
u(x + h) − u(x − h) 1
= u0 (x) + h2 u[3] (x) + . . .
2h 6
10 / 39
Outline Finite Differences Difference Equations FDM FEM
Second Difference
The second difference approximation of the second derivative:
12 / 39
Outline Finite Differences Difference Equations FDM FEM
13 / 39
Outline Finite Differences Difference Equations FDM FEM
2
• Differential equation: − ddxu2 = 1 with u(0) = u(1) = 0
• Complete solution ucomplete = upart + unull :
a particular one for u00 = 1 plus the nullspace one for u00 = 0
2 2
• Particular solution: − ddxu2 = 1 is solved by upart = − x2
2
• Nullspace solution: − ddxu2 = 0 is solved by unull = Cx + D
2
• u(x) = x2 + Cx + D ⇒ From the boundary conditions:
• u(0) = D = 0
• u(1) = − 12 + C + D = 0 → C = − 21 ⇒
2
• u(x) = x−x2
14 / 39
Outline Finite Differences Difference Equations FDM FEM
15 / 39
Outline Finite Differences Difference Equations FDM FEM
u1 n n − 1 n − 2 ... 1 1
u2
n − 1 n − 1 n − 2 ... 1
1
.. n − 2 n − 2 n − 2 ... 1 ..
= h2
. .
.. .. .. ..
un−1 . . . . 1 1
un 1 1 1 ... 1 1
| {z }
T−1
n
16 / 39
Outline Finite Differences Difference Equations FDM FEM
17 / 39
Outline Finite Differences Difference Equations FDM FEM
A
z
}| {
d v −50 49 v v(0) 2
Example: dt = ; =
w 49 −50 w w(0) 0
Solution: v(t) = e−t + e−99t and w(t) = e−t − e−99t
• Time scales differ by a factor of 99 (the condition number of A)
• Solution decays at the slow time scale of e−t , but computing e−99t
may require a very small step ∆t for stability
• Thus, ∆t is controlled by the fast decaying component, and this is
really counterproductive!
Stiffness comes with any problem involving very different time
scales (chemical kinetics, control theory, circuit simulations, etc.)
18 / 39
Outline Finite Differences Difference Equations FDM FEM
19 / 39
Outline Finite Differences Difference Equations FDM FEM
20 / 39
Outline Finite Differences Difference Equations FDM FEM
Since forward and backward differences are first order accurate, the
errors from both methods are O(∆t)
Second-order methods:
• Formal notation: fn = f (un , tn ) and fn+1 = f (un+1 , tn+1 )
• Crank-Nicolson:
21 / 39
Outline Finite Differences Difference Equations FDM FEM
• Backward
differences:
∇ + 12 ∇2 + . . . + p1 ∇p un+1 = ∆t · f (un+1 , tn+1 )
23 / 39
Outline Finite Differences Difference Equations FDM FEM
• The like implicit methods are even more stable and accurate
24 / 39
Outline Finite Differences Difference Equations FDM FEM
25 / 39
Outline Finite Differences Difference Equations FDM FEM
un + 21 ∆t[aun + a(u
un+1 = n + ∆taun )]
1 2 2
= 1 + a∆t + a ∆t un
2
| {z }
Growth factor G
26 / 39
Outline Finite Differences Difference Equations FDM FEM
−un
• Fourth-order RKM: un+1
∆t = 13 (k1 + 2k2 + 2k3 + k4 ) where
27 / 39
Outline Finite Differences Difference Equations FDM FEM
28 / 39
Outline Finite Differences Difference Equations FDM FEM
Z1 Z1 Z1
00
f (x)ν(x)dx = − u (x)ν(x)dx = u0 (x)ν 0 (x)dx
0 0 0
29 / 39
Outline Finite Differences Difference Equations FDM FEM
⇒ Ku = f ,
n
P
that is, Kij ui = fj ; j = 1, . . . , n, where
i=1
Z1 Z1
dφi (x) dνj (x)
Kij = dx and fj = f (x)νj (x)dx
dx dx
0 0
30 / 39
Outline Finite Differences Difference Equations FDM FEM
31 / 39
Outline Finite Differences Difference Equations FDM FEM
1
h = ; u(x) = u1 φ1 (x) + u2 φ2 (x) + u3 φ3 (x)
3
Basis and test functions φi (x) = νi (x); i = 1, 2, 3:
φ1 (x) φ2 (x) φ3 (x)
1
0 h 2h 1
φ1 (x) φ2 (x) φ3 (x)
1
0≤x≤ 3 3x 0 0
1 2
3 ≤x≤ 3 2 − 3x 3x − 1 0
2
3 ≤x≤1 0 3 − 3x 3x − 2
32 / 39
Outline Finite Differences Difference Equations FDM FEM
u1 u2 u3
0 h 2h 1 0 h 2h 1
Piecewise-linear function u(x) = u1 φ1 (x) + u2 φ2 (x) + u3 φ3 (x)
• Differential equation: −u00 = 1 (i.e. f (x) = 1)
Free-end border conditions u(0) = 0; u0 (0) = 1
• Complete solution of this differential eqution:
2
u(x) = A + Bx − x2 (nullspace + a particular solution);
x2
A = 0 and B = 1 (from the border conditions) ⇒ u(x) = x − 2
• Test functions:
νi : hats φ1 and φ2 and one half-hat φ3 ; h = 31
33 / 39
Outline Finite Differences Difference Equations FDM FEM
34 / 39
Outline Finite Differences Difference Equations FDM FEM
R1 1/3
R 2/3
R
f1 = φ1 (x)dx = 3xdx + (2 − 3x)dx
0 0 1/3
1/3 2/3
3x2 3x2 1 1 1
= + 2x − = + =
2 2 6 6 3
0 1/3
R1 2/3
R R1
f2 = φ2 (x)dx = (3x − 1)dx + (3 − 3x)dx
0 1/3 2/3
2/3 1
3x2 3x2 1 1 1
= − x + 3x − = + =
2 2 6 6 3
1/3 2/3
R1 R1
f3 = φ3 (x)dx = (3x − 2)dx
0 2/3
1
3x2 1
= − 2x =
2 6
2/3
35 / 39
Outline Finite Differences Difference Equations FDM FEM
37 / 39
Outline Finite Differences Difference Equations FDM FEM
u1 u2 u3
0 h 2h 1 0 h 0.5 2h 1
38 / 39
Outline Finite Differences Difference Equations FDM FEM
39 / 39