Skip to content

Commit

Permalink
... format
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Nov 4, 2024
1 parent 020ea8c commit bd0d087
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions docs/src/basics/Preconditioners.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ One way to specify preconditioners uses the `Pl` and `Pr` keyword arguments to
and `Pr` for right preconditioner, respectively. By default, if no preconditioner is given, the preconditioner is assumed to be
the identity ``I``.


In the following, we will use a left sided diagonal (Jacobi) preconditioner.

```@example precon1
Expand All @@ -45,7 +44,7 @@ n = 4
A = rand(n, n)
b = rand(n)
Pl=Diagonal(A)
Pl = Diagonal(A)
prob = LinearProblem(A, b)
sol = solve(prob, KrylovJL_GMRES(), Pl = Pl)
Expand All @@ -56,7 +55,6 @@ Alternatively, preconditioners can be specified via the `precs` argument to th
an iterative solver specification. This argument shall deliver a factory method mapping `A` and a
parameter `p` to a tuple `(Pl,Pr)` consisting a left and a right preconditioner.


```@example precon2
using LinearSolve, LinearAlgebra
n = 4
Expand All @@ -65,9 +63,10 @@ A = rand(n, n)
b = rand(n)
prob = LinearProblem(A, b)
sol = solve(prob, KrylovJL_GMRES(precs = (A,p)->(Diagonal(A),I)) )
sol = solve(prob, KrylovJL_GMRES(precs = (A, p) -> (Diagonal(A), I)))
sol.u
```

This approach has the advantage that the specification of the preconditioner is possible without
the knowledge of a concrete matrix `A`. It also allows to specify the preconditioner via a callable object
and to pass parameters to the constructor of the preconditioner instances. The example below also shows how
Expand All @@ -80,22 +79,23 @@ Base.@kwdef struct WeightedDiagonalPreconBuilder
w::Float64
end
(builder::WeightedDiagonalPreconBuilder)(A,p) = (builder.w*Diagonal(A),I)
(builder::WeightedDiagonalPreconBuilder)(A, p) = (builder.w * Diagonal(A), I)
n = 4
A = n*I-rand(n, n)
A = n * I - rand(n, n)
b = rand(n)
prob = LinearProblem(A, b)
sol = solve(prob, KrylovJL_GMRES(precs = WeightedDiagonalPreconBuilder(w=0.9)) )
sol = solve(prob, KrylovJL_GMRES(precs = WeightedDiagonalPreconBuilder(w = 0.9)))
sol.u
B=A.+0.1
cache=sol.cache
reinit!(cache,A=B, reuse_precs=true)
sol = solve!(cache, KrylovJL_GMRES(precs = WeightedDiagonalPreconBuilder(w=0.9)) )
B = A .+ 0.1
cache = sol.cache
reinit!(cache, A = B, reuse_precs = true)
sol = solve!(cache, KrylovJL_GMRES(precs = WeightedDiagonalPreconBuilder(w = 0.9)))
sol.u
```

## Preconditioner Interface

To define a new preconditioner you define a Julia type which satisfies the
Expand Down Expand Up @@ -128,14 +128,14 @@ The following preconditioners match the interface of LinearSolve.jl.
Implementations of the algebraic multigrid method. Must be converted to a
preconditioner via `AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.precmethod(A))`.
Requires `A` as a `AbstractMatrix`. Provides the following methods:

+ `AlgebraicMultigrid.ruge_stuben(A)`
+ `AlgebraicMultigrid.smoothed_aggregation(A)`
- [PyAMG](https://github.com/cortner/PyAMG.jl):
Implementations of the algebraic multigrid method. Must be converted to a
preconditioner via `PyAMG.aspreconditioner(PyAMG.precmethod(A))`.
Requires `A` as a `AbstractMatrix`. Provides the following methods:

+ `PyAMG.RugeStubenSolver(A)`
+ `PyAMG.SmoothedAggregationSolver(A)`
- [ILUZero.ILU0Precon(A::SparseMatrixCSC{T,N}, b_type = T)](https://github.com/mcovalt/ILUZero.jl):
Expand All @@ -154,7 +154,7 @@ The following preconditioners match the interface of LinearSolve.jl.
and `HYPRE.BoomerAMG`.
- [KrylovPreconditioners.jl](https://github.com/JuliaSmoothOptimizers/KrylovPreconditioners.jl/): Provides GPU-ready
preconditioners via KernelAbstractions.jl. At the time of writing the package provides the following methods:

+ Incomplete Cholesky decomposition `KrylovPreconditioners.kp_ic0(A)`
+ Incomplete LU decomposition `KrylovPreconditioners.kp_ilu0(A)`
+ Block Jacobi `KrylovPreconditioners.BlockJacobiPreconditioner(A, nblocks, device)`
2 changes: 1 addition & 1 deletion test/resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using LinearSolve, LinearAlgebra, SparseArrays, InteractiveUtils, Test
using LinearSolve: AbstractDenseFactorization, AbstractSparseFactorization

for alg in vcat(InteractiveUtils.subtypes(AbstractDenseFactorization),
InteractiveUtils.subtypes(AbstractSparseFactorization))
InteractiveUtils.subtypes(AbstractSparseFactorization))
if alg in [PardisoJL]
## Pardiso has extra tests in test/pardiso/pardiso.jl
continue
Expand Down

0 comments on commit bd0d087

Please sign in to comment.