@@ -4,15 +4,13 @@ Many linear solvers can be accelerated by using what is known as a **preconditio
44an approximation to the matrix inverse action which is cheap to evaluate. These
55can improve the numerical conditioning of the solver process and in turn improve
66the 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.
88
99## Using Preconditioners
1010
1111### Mathematical Definition
1212
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:
1614
1715``` math
1816AP_r^{-1}(P_r u) = AP_r^{-1}y = b
@@ -31,10 +29,12 @@ A two-sided preconditioned system is of the form:
3129P_l^{-1}A P_r^{-1} (P_r u) = P_l^{-1}b
3230```
3331
34- By default, if no preconditioner is given, the preconditioner is assumed to be
32+ ### Specifying Preconditioners
33+
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
3536the identity `` I `` .
3637
37- ### Using Preconditioners
3838
3939In the following, we will use the ` DiagonalPreconditioner ` to define a two-sided
4040preconditioned system which first divides by some random numbers and then
@@ -55,6 +55,44 @@ sol = solve(prob, KrylovJL_GMRES(), Pl = Pl)
5555sol.u
5656```
5757
58+ Alternatively, preconditioners can be specified via the ` precs ` argument to the constructor of
59+ an iterative solver specification. This argument shall deliver a function mapping ` A ` and a
60+ parameter ` p ` to a tuple ` (Pl,Pr) ` consisting a left and a right preconditioner.
61+
62+
63+ ``` @example precon2
64+ using LinearSolve, LinearAlgebra
65+ n = 4
66+ s = rand(n)
67+
68+ A = rand(n, n)
69+ b = rand(n)
70+
71+ prob = LinearProblem(A, b)
72+ sol = solve(prob, KrylovJL_GMRES(precs = (A,p)->(Diagonal(A),I)) )
73+ sol.u
74+ ```
75+ This approach has the advantage that the specification of the preconditioner is possible without
76+ the knowledge of a concrete matrix ` A ` . It also allows to specifiy the preconditioner via a functor struct:
77+
78+ ``` @example precon2
79+ using LinearSolve, LinearAlgebra
80+
81+ struct DiagonalPrecs end
82+
83+ (::DiagonalPrecs)(A,p) = (Diagonal(A),I)
84+
85+ n = 4
86+ s = rand(n)
87+
88+ A = rand(n, n)
89+ b = rand(n)
90+
91+ prob = LinearProblem(A, b)
92+ sol = solve(prob, KrylovJL_GMRES(precs = DiagonalPrecs()) )
93+ sol.u
94+ ```
95+
5896## Preconditioner Interface
5997
6098To define a new preconditioner you define a Julia type which satisfies the
0 commit comments