Skip to content

Commit 8b8b171

Browse files
committed
Provide a more thorough explanation of precs, including reinit! with
reuse_precs=true.
1 parent 89ed45b commit 8b8b171

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
34
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
45

56
[compat]

docs/src/basics/Preconditioners.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,30 @@ and `Pr` for right preconditioner, respectively. By default, if no preconditione
3636
the 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
4542
using LinearSolve, LinearAlgebra
4643
n = 4
47-
s = rand(n)
48-
Pl = Diagonal(s)
4944
5045
A = rand(n, n)
5146
b = rand(n)
5247
48+
Pl=Diagonal(A)
49+
5350
prob = LinearProblem(A, b)
5451
sol = solve(prob, KrylovJL_GMRES(), Pl = Pl)
5552
sol.u
5653
```
5754

5855
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
56+
an iterative solver specification. This argument shall deliver a factory method mapping `A` and a
6057
parameter `p` to a tuple `(Pl,Pr)` consisting a left and a right preconditioner.
6158

6259

6360
```@example precon2
6461
using LinearSolve, LinearAlgebra
6562
n = 4
66-
s = rand(n)
6763
6864
A = rand(n, n)
6965
b = rand(n)
@@ -73,26 +69,33 @@ sol = solve(prob, KrylovJL_GMRES(precs = (A,p)->(Diagonal(A),I)) )
7369
sol.u
7470
```
7571
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 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
7977
using 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
8585
n = 4
86-
s = rand(n)
87-
88-
A = rand(n, n)
86+
A = n*I-rand(n, n)
8987
b = rand(n)
9088
9189
prob = LinearProblem(A, b)
92-
sol = solve(prob, KrylovJL_GMRES(precs = DiagonalPrecs()) )
90+
sol = solve(prob, KrylovJL_GMRES(precs = WeightedDiagonalBuilder(w=0.9)) )
9391
sol.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

98101
To define a new preconditioner you define a Julia type which satisfies the

0 commit comments

Comments
 (0)