@@ -4,15 +4,13 @@ Many linear solvers can be accelerated by using what is known as a **preconditio
4
4
an approximation to the matrix inverse action which is cheap to evaluate. These
5
5
can improve the numerical conditioning of the solver process and in turn improve
6
6
the performance. LinearSolve.jl provides an interface for the definition of
7
- preconditioners which works with the wrapped packages.
7
+ preconditioners which works with the wrapped iterative solver packages.
8
8
9
9
## Using Preconditioners
10
10
11
11
### Mathematical Definition
12
12
13
- Preconditioners are specified in the keyword arguments to ` init ` or ` solve ` : ` Pl ` for left
14
- and ` Pr ` for right preconditioner, respectively.
15
- The right preconditioner, `` P_r `` transforms the linear system `` Au = b `` into the form:
13
+ A right preconditioner, `` P_r `` transforms the linear system `` Au = b `` into the form:
16
14
17
15
``` math
18
16
AP_r^{-1}(P_r u) = AP_r^{-1}y = b
@@ -31,30 +29,73 @@ A two-sided preconditioned system is of the form:
31
29
P_l^{-1}A P_r^{-1} (P_r u) = P_l^{-1}b
32
30
```
33
31
34
- By default, if no preconditioner is given, the preconditioner is assumed to be
35
- the identity `` I `` .
32
+ ### Specifying Preconditioners
36
33
37
- ### Using Preconditioners
34
+ One way to specify preconditioners uses the ` Pl ` and ` Pr ` keyword arguments to ` init ` or ` solve ` : ` Pl ` for left
35
+ and ` Pr ` for right preconditioner, respectively. By default, if no preconditioner is given, the preconditioner is assumed to be
36
+ the identity `` I `` .
38
37
39
- In the following, we will use the ` DiagonalPreconditioner ` to define a two-sided
40
- preconditioned system which first divides by some random numbers and then
41
- multiplies by the same values. This is commonly used in the case where if, instead
42
- of random, ` s ` is an approximation to the eigenvalues of a system.
38
+ In the following, we will use a left sided diagonal (Jacobi) preconditioner.
43
39
44
- ``` @example precon
40
+ ``` @example precon1
45
41
using LinearSolve, LinearAlgebra
46
42
n = 4
47
- s = rand(n)
48
- Pl = Diagonal(s)
49
43
50
44
A = rand(n, n)
51
45
b = rand(n)
52
46
47
+ Pl = Diagonal(A)
48
+
53
49
prob = LinearProblem(A, b)
54
50
sol = solve(prob, KrylovJL_GMRES(), Pl = Pl)
55
51
sol.u
56
52
```
57
53
54
+ Alternatively, preconditioners can be specified via the ` precs ` argument to the constructor of
55
+ an iterative solver specification. This argument shall deliver a factory method mapping ` A ` and a
56
+ parameter ` p ` to a tuple ` (Pl,Pr) ` consisting a left and a right preconditioner.
57
+
58
+ ``` @example precon2
59
+ using LinearSolve, LinearAlgebra
60
+ n = 4
61
+
62
+ A = rand(n, n)
63
+ b = rand(n)
64
+
65
+ prob = LinearProblem(A, b)
66
+ sol = solve(prob, KrylovJL_GMRES(precs = (A, p) -> (Diagonal(A), I)))
67
+ sol.u
68
+ ```
69
+
70
+ This approach has the advantage that the specification of the preconditioner is possible without
71
+ the knowledge of a concrete matrix ` A ` . It also allows to specify the preconditioner via a callable object
72
+ and to pass parameters to the constructor of the preconditioner instances. The example below also shows how
73
+ to reuse the preconditioner once constructed for the subsequent solution of a modified problem.
74
+
75
+ ``` @example precon3
76
+ using LinearSolve, LinearAlgebra
77
+
78
+ Base.@kwdef struct WeightedDiagonalPreconBuilder
79
+ w::Float64
80
+ end
81
+
82
+ (builder::WeightedDiagonalPreconBuilder)(A, p) = (builder.w * Diagonal(A), I)
83
+
84
+ n = 4
85
+ A = n * I - rand(n, n)
86
+ b = rand(n)
87
+
88
+ prob = LinearProblem(A, b)
89
+ sol = solve(prob, KrylovJL_GMRES(precs = WeightedDiagonalPreconBuilder(w = 0.9)))
90
+ sol.u
91
+
92
+ B = A .+ 0.1
93
+ cache = sol.cache
94
+ reinit!(cache, A = B, reuse_precs = true)
95
+ sol = solve!(cache, KrylovJL_GMRES(precs = WeightedDiagonalPreconBuilder(w = 0.9)))
96
+ sol.u
97
+ ```
98
+
58
99
## Preconditioner Interface
59
100
60
101
To define a new preconditioner you define a Julia type which satisfies the
0 commit comments