Iterative Solvers for Finite Difference Methods
Iterative Solvers for Finite Difference Methods
1
Elliptic Model Problem (d = 2)
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
3
High Dimensionality
Thought Experiment
For quadratic convergence ∥u − u h ∥ ≲ h2 we want to reduce
the error by a factor 10. To do this, h must be reduced by a
√ √ d
factor of 10 and we obtain 10 = 10 times as many
difference equations for d = 2.
With linear convergence ∥u − u h ∥ ≲ h, on the other hand, we
get 10d = 100 times more equations for d = 2.
4
Sparsity, Memory Requirements
0 108
10
106
20
30
104
40
102
50
60
100
0 10 20 30 40 50 60 100 101 102 103 104
nz = 288
5
Condition Number
Definition 3.2
Let A ∈ Rn×n be an invertible matrix. Then κ(A) := ∥A∥∥A−1 ∥
is called the condition number of A.
∥x − x
e∥ ∥b − b∥
e
≤ κ(A) · (3.1)
∥x∥ ∥b∥
6
Condition Number of Lh
104
103
102
101
100
10-2 10-1 100
7
Note: The bound in (3.1) is a worst-case bound, i.e., it holds for
all perturbations ∥f h − e
f h ∥.
For Example 3.1 with f (x, y ) = sin(πx) sin(πy ) and
ef (x, y ) = sin(10πx) sin(10πy ) we get:
104
103
102
101
100
10-1
10-2 10-1 100
8
Symmetry, Positive Definiteness
Symmetry Lh = L⊤
h for symmetric stencils, e.g. the five-point
stencil.
Positive Definiteness: x ⊤ Lh x > 0 for all vectors x ̸= 0
Therefore the solution of Lh u h = f h is also the uniquely
determined minimum of the function
1 ⊤
ϕ(x) = x Lh x − x ⊤ f h ,
2
since ∇ϕ(x) = Lh x − f h and the Hessian matrix is H(x) = Lh .
This is important for advanced iterative solvers, e.g., the
conjugate gradient (CG) method.
9
Band Structure
Definition 3.3
A matrix A ∈ Rn×n is called (p, q)-band matrix, if p, q ∈ N exist
such that ai,k = 0 for all k > i + p and i > k + q.
The number w := p + q + 1 is called band width.
A matrix with p = q = 1 is called tridiagonal matrix.
10
Ordering of the Unknowns
(0, 4) (4, 4)
(0, 0) (4, 0)
11
Lexicographic Ordering
12
Lexicographic Ordering:
Lh is a (3, 3)-band matrix with a band width of 3 + 3 + 1 = 7:
4 −1 −1
−1 4 −1 −1
−1 4 −1
−1 4 −1 −1
1
Lh = 2 −1 −1 4 −1 −1
h
−1 −1 4 −1
−1 4 −1
−1 −1 4 −1
−1 −1 4
13
Checkerboard Ordering
14
Checkerboard Ordering:
Lh is a (6, 6)-band matrix with a band width of 6 + 6 + 1 = 13:
4 −1 −1
4 −1 −1
−1 −1 −1 −1
4
4 −1 −1
1
Lh = 2 4 −1 −1
h
−1 −1 −1 4
−1 −1 −1 4
−1 −1 −1
4
−1 −1 −1 4
15
Lexicographic ordering Checkerboard ordering
0 0
100 100
200 200
300 300
400 400
500 500
600 600
700 700
800 800
900 900
Random ordering
0
100
200
300
400
500
600
700
800
900
16
0 200 400 600 800
nz = 4681
Summary
Question
Which properties can be exploited in the solver? Which
properties are problematic?
17
Content
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
18
Gaussian Elimination
Memory Requirements
Without column pivot search: The factor L has the (lower) band
width p and the factor U has the (upper) band width q.
With column pivot search: U has the (upper) band width p + q.
However, the number of non-zero entries in L and U can be
(considerably) larger than the number of non-zero entries in A
(so-called fill-in).
20
Lower triangular matrix L - Lexicographic ordering Lower triangular matrix L - Checkerboard ordering
0 0
100 100
200 200
300 300
400 400
500 500
600 600
700 700
800 800
900 900
100
200
300
400
500
600
700
800
900
21
0 200 400 600 800
nz = 68278
Is There a Better Way to Order the Unknowns?
Ax = b ⇐⇒ PAx = Pb
Ax = b ⇐⇒ AP x
b = b, x = P x
b
22
Lexicographic ordering Reverse Cuthill-McKee ordering
0 0
100 100
200 200
300 300
400 400
500 500
600 600
700 700
800 800
900 900
Lower triangular matrix L - Lexicographic ordering Lower triangular matrix L - Reverse Cuthill-McKee orderi
0 0
100 100
200 200
300 300
400 400
500 500
600 600
700 700
800 800
900 900
23
0 200 400 600 800 0 200 400 600 800
nz = 29821 nz = 21266
Comparison of Computational Times
0.05
0.04
0.03
0.02
0.01
0
0 0.5 1 1.5 2
4 24
10
Iterative Solvers for Difference Equations
25
Content
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
26
Definition 3.4
Let A ∈ Rn×n be an invertible matrix and b ∈ Rn . An iterative
solver for Ax = b constructs a sequence of approximations
x 1 , x 2 , . . . , x k , . . . in Rn starting from a given initial vector
x 0 ∈ Rn .
Definition 3.5
An iterative solver is called convergent if
lim x k = x,
k →+∞
x k +1 = Sx k + T b, k = 0, 1, 2, . . . . (3.2)
Definition 3.8
An iterative solver is called consistent, if from x k = x it follows
that x k +1 = x holds.
Theorem 3.9
An linear iterative solver is consistent ⇐⇒ S = I − TA.
Proof:
x k +1 = Sx k + T b = Sx + TAx = (S + TA)x = x,
if and only if S + TA = I or, equivalently, S = I − TA.
28
Error Propagation
Definition 3.11
Let S ∈ Rn×n be a matrix. The number
30
Theorem 3.12 (Convergence)
Under assumption (A1) the linear iterative solver in (3.2) is
convergent for any initial vector x 0 ⇐⇒ ρ(S) < 1, i.e., the
spectral radius of the iteration matrix is smaller than one.
Sketch of Proof:
Assumption: There is a basis of Rn containing only
eigenvectors of S. (The general case is not considered here.)
Let (λℓ , v ℓ ), ℓ = 1, . . . , n denote the eigenpairs of the matrix S.
In particular, Sv ℓ = λℓ v ℓ , ℓ = 1, . . . , n.
Then the initial error e 0 has the representation
e 0 = c1 v 1 + · · · + cn v n (3.3)
Conclusion
Under assumption (A1), the iterative solver (3.2) is convergent
for any initial vector x 0 if ∥S∥ < 1 holds for any induced matrix
norm ∥ · ∥, e.g., the row sum norm.
33
Speed of Convergence
Question
How many iteration steps k are needed to reduce the norm of
the initial error by a factor R > 1?
Answer: With
1/k 1/k
∥e k ∥
1
σk := =
∥e 0 ∥ R
it follows
k = − ln(R)/ ln(σk ).
35
Content
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
36
Let A ∈ Rn×n be an invertible matrix.
Question: How can we construct the matrices S, T in a linear
iterative solver for Ax = b,
x k +1 = Sx k + T b, k = 0, 1, . . .?
Desired properties:
• Consistency: S = I − TA
• Matrix-vector multiplications with S, T are cheap
• Fast convergence, i.e. small spectral radius ρ(S) ≪ 1
37
Splitting Method
A = M − (M − A)
A = M(I − M −1 (M − A))
M (I − (I − M −1 A))
A = |{z}
| {z }
=:T −1 =:S
Conclusion
Choosing T = M −1 and S = I − M −1 A gives a consistent
linear iterative solver.
38
Splitting Method
x k +1 = Sx k + T b
x k +1 = (I − M −1 A)x k + M −1 b
x k +1 = x k + M −1 (b − Ax k )
x k +1 = x k + M −1 r k
Implementation
Given x k , b, A, and M, we carry out the following steps:
1. Calculate r k = b − Ax k
2. Solve the linear system Mz k = r k
3. Update x k +1 = x k + z k
This implementation requires only matrix-vector-multiplications with A and
linear system solves with M, no multiplications with T = M −1 or
S = I − M −1 A. M −1 is not computed, because this is often too expensive. 39
How to choose the matrix M?
Criteria:
• M is invertible and M ≈ A.
• The computational cost to solve a linear system with M is
smaller than the cost to solve a linear system with A.
Example: M is a diagonal or triangular matrix.
Idea of the so called Classical Iterative Solvers:
A=L+D+U
a1,1 a1,2 ··· a1,n−1 a1,n
a2,1 a2,2 ··· a2,n−1
a2,n
.. .. .. ..
A=
. . .
.
an−1,1 an−1,2 · · · an−1,n−1 an−1,n
Note
In all three cases M is invertible if A and D are invertible.
41
Convergence Criteria (Without Proof)
42
Matlab Demonstration Example 3.1
100 100
Relative norm of residual
10-4 10-4
10-6 10-6
0 1000 2000 3000 4000 5000 0 500 1000 1500 2000 2500
Number of iterations Number of iterations
43
Matlab Demonstration Example 3.1
h Jacobi Gauss–Seidel
2−2 40 21
2−3 175 89
2−4 713 357
2−5 2863 1433
2−6 11463 5733
Observations:
• The rate of convergence slows down as the mesh size h gets
smaller.
• The number of iterations approximately quadruples when the
mesh size is halved.
• Gauss–Seidel requires about half as many iterations as Jacobi.
44
Matlab-Demonstration Example 3.1
0.9
0.8
0.7
0.6
10-2 10-1
45
Jacobi Method for Lh u h = f h
Proof:
−1
1 1 2
Sh v ℓ = I − diag(Lh ) Lh v ℓ = v ℓ − h2 Lh v ℓ = 1 − h λℓ v ℓ
4 4
47
Content
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
48
Sneak Preview: Eigenvectors of Lh on the Grid
49
Eigenfunctions of the Laplace Operator
The functions
eνµ (x, y ) = sin(νπx) sin(µπy ), ν, µ ∈ N
are equal to zero on the boundary of the domain Ω = (0, 1)2 .
Furthermore, for all (x, y ) ∈ Ω it holds
−∆eνµ (x, y ) = −∂xx eνµ (x, y ) − ∂yy eνµ (x, y )
= (νπ)2 sin(νπx) sin(µπy ) + (µπ)2 sin(νπx) sin(µπy )
= (νπ)2 + (µπ)2 eνµ (x, y )
Conclusion
The functions eνµ (x, y ), ν, µ ∈ N, are eigenfunctions of the
operator −∆ on the unit square (with zero-boundary
50
conditions) with associated eigenvalue λνµ .
Trigonometric Identities:
51
Apply the five-point stencil on eνµ (x, y ):
−eνµ (xi − h, yk ) − eνµ (xi + h, yk ) − eνµ (xi , yk − h)
−∆h eνµ (x, y ) =
h2
νµ νµ
−e (xi , yk + h) + 4e (xi , yk )
+
h2
1
= 2 (4 − 2 cos(νπh) − 2 cos(µπh)) sin(νπx) sin(µπy )
h
4 1 1 1 1
= 2 − cos(νπh) + − cos(µπh) eνµ (x, y )
h 2 2 2 2
4 2
= 2 sin (νπh/2) + sin2 (µπh/2) eνµ (x, y )
h
= λνµ νµ
h e (x, y )
Conclusion
The function eνµ (x, y ) is an eigenfunction of the discrete
Laplace operator −∆h on the unit square (with zero-boundary
conditions) with associated eigenvalue λνµ h . 52
Plot of the eigenvalues λνµ und λνµ
h for different mesh sizes
500 500
400 400
300 300
200 200
100 100
0 0
0 5 10 15 20 25 30 0 5 10 15 20 25 30
500 500
400 400
300 300
200 200
100 100
0 0
0 5 10 15 20 25 30 0 5 10 15 20 25 30
53
νµ νµ
Idea: Define the vector vℓ(i,k ) = e (xi , yk ), i, k = 1, . . . , Nh .
54
Content
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
55
Jacobi Method for Lh u h = f h
h k Iter (Sh )
2−2 39 40
2−3 174 175
2−4 712 713
2−5 2863 2864
2−6 11462 11463
x k +1,GS = x k + (D + L)−1 (b − Ax k )
(D + L)x k +1,GS = (D + L)x k + (b − (D + L)x k − Ux k )
Dx k +1,GS = b − Lx k +1,GS − Ux k
x k +1,GS = D −1 (b − Lx k +1,GS − Ux k )
Component-wise for i = 1, . . . , n:
!
1
xik +1,GS ai,ℓ xℓk +1,GS
X X
= bi − − ai,ℓ xℓk
ai,i
ℓ<i ℓ>i
59
Relaxation parameter ω ≥ 1, Successive Over Relaxation:
xik +1,SOR = xik + ω(xik +1,GS − xik ), i = 1, . . . , n,
!
ω
xik +1,SOR ai,ℓ xℓk +1,SOR −
X X
= xik + bi − ai,ℓ xℓk − ai,i xik .
ai,i
ℓ<i ℓ>i
Vector notation:
x k +1,SOR = x k + ωD −1 (b − Lx k +1,SOR − Ux k − Dx k )
(D + ωL)x k +1,SOR = Dx k + ωb − ωUx k − ωDx k
= Dx k + ωLx k + ωr k
= (D + ωL)x k + ωr k
x k +1,SOR = x k + ω(D + ωL)−1 r k
This is a splitting method (p. 39) with
M = ω −1 (D + ωL) = ω −1 D + L.
60
SOR Method
SSOR = I − M −1 A = I − (ω −1 D + L)−1 A.
Theorem 3.13
Let A ∈ Rn×n be symmetric and positive-definite. Then
ρ(SSOR ) < 1 for all 0 < ω < 2.
61
SOR Method for Lh u h = f h
Theorem 3.14
Let Lh be the difference matrix of the discretized Poisson
equation and let ρJac be the spectral radius of the iteration
matrix of the Jacobi method. Then the spectral radius of the
iteration matrix of the SOR method is minimal for
2
2 ρ
ωopt = q =1+ qJac
2
1 + 1 − ρJac 1 + 1 − ρJac2
62
With ρJac = cos(πh) we get
q q
1 − ρ2Jac = 1 − cos2 (πh) = sin(πh)
and thus
2
1 − sin2 (πh)
cos(πh) 1 − sin(πh)
ρSOR,opt = ωopt − 1 = = =
1 + sin(πh) (1 + sin(πh))2 1 + sin(πh)
2 sin(πh)
=1− ≈ 1 − 2πh.
1 + sin(πh)
64
Computational Cost of the Splitting Method for Lh u h = f h
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
66
Error Propagation of the Jacobi Method, Example 3.1
67
Observation
Error components with different frequencies (ν, µ) are
reduced with different rates.
Example:
1. ν = µ = 1
λνµ = cos(πh) ≈ 1 − π 2 h2 /2 + O(h4 )
Very slow error reduction for small mesh sizes h!
2. ν = µ = Nh /2 = (1 − h)/2h
λνµ = cos((1 − h)π/2)
= cos(π/2) cos(hπ/2) + sin(π/2) sin(hπ/2)
= sin(hπ/2) = hπ/2 − O(h3 )
Very fast error reduction for small mesh sizes h!
68
Eigenvalues of the Iteration Matrix, Example 3.1
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3
69
Damped Jacobi Method
x kJac,ω
+1
= x k + ω(x kJac
+1
− x k ) = x k + ωD −1 r k
70
Damped Jacobi Method, Example 3.1
λνµ
h,ω = (1 − ω) + ω(cos(νπh) + cos(µπh))/2.
71
Nh = 63
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3
72
Nh = 63
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3
73
Nh = 63, ω = 1/2, error after k = 0, 1, 5, 10 iterations
74
Observation
Linear iterative methods (1) smooth high-frequency errors and
√
(2) require (at least) O(h−1 ) = O( nh ) steps on a grid with
mesh size h to “transport” information from A to B (one-step
method)!
A h
75
Idea
Perform the iterations on a coarser grid with mesh size
H = 2h. Low frequency error components with respect to h
become high frequency error components with respect to H.
A H
76
Content
3. Iterative Solvers
3.1 Properties of the Difference Matrix
3.2 Direct Methods and their Disadvantages
3.3 Linear Iterative Solvers
3.4 Practical Examples
3.5 Eigenvalues and Eigenvectors of the Difference Matrix
3.6 Back to Splitting Methods
3.7 Smoothing Property
3.8 Two-Grid Methods
77
Two-Grid Methods for Lh u h = f h
Test: Lh e kh = Lh (u h − u kh ) = f h − Lh u kh = r kh
Problem: The solution of (3.4) is too expensive!
78
Idea: Define grid transfer matrices
R : Ωh → ΩH (fine to coarse, restriction)
P : ΩH → Ωh (coarse to fine, prolongation)
with the properties that
PR ≈ I
for low-frequency grid functions on Ωh , e.g. e kh . Then it holds
RLh e kh = Rr kh
RLh PRe kh ≈ Rr kh
(RLh P)(Re kh ) ≈ Rr kh
eH c H = r k
L (3.5)
H
Implementation
Starting from u 0h , f h , Lh , R, P and L
eH = RLh P:
80
Error Propagation
Initial error: e 0h
After k1 smoothing steps: e kh1 = S k1 e 0h
Coarse Grid Correction (Steps 2.–5., p. 80):
u kh1 +1 = u kh1 + c h = u kh1 + Pc H = u kh1 + P L
e−1 r k1
H H
= u kh1 + P L
e−1 Rr k1
H h
= u kh1 + P L
e−1 RLh e k1
H h
81
Grid Transfer
82
Grid Transfer
1/4 1/8 0 1/8 1/16 0 0 0 0
0 1/8 1/4 0 1/16 1/8 0 0 0
R=
0 0 0 1/8 1/16 0 1/4 1/8 0
0 0 0 0 1/16 1/8 0 1/8 1/4
Rule of Thumb
Chose R = cP ⊤ with a constant c ∈ R, c > 0.
Why?
eH = RLh P = cP ⊤ Lh P
L
0 0
100
500
200
1000
300
1500 400
2000 500
600
2500
700
3000
800
3500 900
1000
0 500 1000 1500 2000 2500 3000 3500 0 200 400 600 800 1000
nz = 19593 nz = 8836
84
Matlab Demonstration Example 3.1
h k =1 k =2 k =5
2−2 6 4 3
2−3 6 5 4
2−4 6 5 4
2−5 6 4 4
2−6 5 4 4
2−7 5 4 3
85
Conclusion: The number of iterations of the two-grid method
with mesh sizes (h, 2h) is independent of h! This situation is
optimal and significantly better than using the splitting methods
alone.
Problem: Solving the correction equation (step 3., p. 80) with
direct methods is still too expensive, especially for small mesh
sizes 2h.
Idea: In step 3, p. 80 we use again a two-grid method with
coarser mesh sizes.
Multigrid Methods, e-g. V-Cycle:
h → 2h → 4h → 8h → · → H → · → 8h → 4h → 2h → h
87
Look closely!
88
Image Sources
• Wikimedia Commons: p. 88
• Society for Industrial and Applied Mathematics: p. 87
89