@@ -36,34 +36,30 @@ and `Pr` for right preconditioner, respectively. By default, if no preconditione
3636the identity `` I `` .
3737
3838
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.
39+ In the following, we will use a left sided diagonal (Jacobi) preconditioner.
4340
44- ``` @example precon
41+ ``` @example precon1
4542using LinearSolve, LinearAlgebra
4643n = 4
47- s = rand(n)
48- Pl = Diagonal(s)
4944
5045A = rand(n, n)
5146b = rand(n)
5247
48+ Pl=Diagonal(A)
49+
5350prob = LinearProblem(A, b)
5451sol = solve(prob, KrylovJL_GMRES(), Pl = Pl)
5552sol.u
5653```
5754
5855Alternatively, 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
56+ an iterative solver specification. This argument shall deliver a factory method mapping ` A ` and a
6057parameter ` p ` to a tuple ` (Pl,Pr) ` consisting a left and a right preconditioner.
6158
6259
6360``` @example precon2
6461using LinearSolve, LinearAlgebra
6562n = 4
66- s = rand(n)
6763
6864A = rand(n, n)
6965b = rand(n)
@@ -73,26 +69,33 @@ sol = solve(prob, KrylovJL_GMRES(precs = (A,p)->(Diagonal(A),I)) )
7369sol.u
7470```
7571This 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 specify the preconditioner via a callable object:
72+ the knowledge of a concrete matrix ` A ` . It also allows to specify the preconditioner via a callable object
73+ and to pass parameters to the constructor of the preconditioner instances. The example below also shows how
74+ to reuse the preconditioner once constructed for the subsequent solution of a modified problem.
7775
78- ``` @example precon2
76+ ``` @example precon3
7977using LinearSolve, LinearAlgebra
8078
81- struct DiagonalPrecs end
79+ Base.@kwdef struct WeightedDiagonalBuilder
80+ w::Float64
81+ end
8282
83- (::DiagonalPrecs )(A,p) = (Diagonal(A),I)
83+ (builder::WeightedDiagonalBuilder )(A,p) = (builder.w* Diagonal(A),I)
8484
8585n = 4
86- s = rand(n)
87-
88- A = rand(n, n)
86+ A = n*I-rand(n, n)
8987b = rand(n)
9088
9189prob = LinearProblem(A, b)
92- sol = solve(prob, KrylovJL_GMRES(precs = DiagonalPrecs( )) )
90+ sol = solve(prob, KrylovJL_GMRES(precs = WeightedDiagonalBuilder(w=0.9 )) )
9391sol.u
94- ```
9592
93+ B=A.+0.1
94+ cache=sol.cache
95+ reinit!(cache,A=B, reuse_precs=true)
96+ sol = solve!(cache, KrylovJL_GMRES(precs = WeightedDiagonalBuilder(w=0.9)) )
97+ sol.u
98+ ```
9699## Preconditioner Interface
97100
98101To define a new preconditioner you define a Julia type which satisfies the
0 commit comments