1- # Integration with LinearSolve.jl
1+ # Linear System solution
22
3- Starting with version 0.9.6, ExtendableSparse is compatible
4- with [ LinearSolve.jl] ( https://github.com/SciML/LinearSolve.jl ) .
5- Since version 0.9.7, this is facilitated via the
6- AbstractSparseMatrixCSC interface. Since version 1.6,
7- preconditioner constructors can be passed to iterative solvers via the [ ` precs `
8- keyword argument] ( https://docs.sciml.ai/LinearSolve/stable/basics/Preconditioners/#prec ) .
9-
10- We can create a test problem and solve it with the ` \ ` operator.
3+ ## The ` \ ` operator
4+ The packages overloads ` \ ` for the ExtendableSparseMatrix type.
5+ The following example uses [ ` fdrand ` ] ( @ref ) to create a test matrix and solve
6+ the corresponding linear system of equations.
117
128``` @example
13- using ExtendableSparse # hide
9+ using ExtendableSparse
1410A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
1511x = ones(1000)
1612b = A * x
1713y = A \ b
1814sum(y)
1915```
2016
17+ This works as well for number types besides ` Float64 ` and related, in this case,
18+ by default a LU factorization based on Sparspak ist used.
19+
20+ ``` @example
21+ using ExtendableSparse
22+ using MultiFloats
23+ A = fdrand(Float64x2, 10, 10, 10; matrixtype = ExtendableSparseMatrix)
24+ x = ones(Float64x2,1000)
25+ b = A * x
26+ y = A \ b
27+ sum(y)
28+ ```
29+
30+ ## Solving with LinearSolve.jl
31+
32+ Starting with version 0.9.6, ExtendableSparse is compatible
33+ with [ LinearSolve.jl] ( https://github.com/SciML/LinearSolve.jl ) .
34+ Since version 0.9.7, this is facilitated via the
35+ AbstractSparseMatrixCSC interface.
36+
37+
2138The same problem can be solved via ` LinearSolve.jl ` :
2239
2340``` @example
24- using ExtendableSparse # hide
25- using LinearSolve # hide
41+ using ExtendableSparse
42+ using LinearSolve
2643A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
2744x = ones(1000)
2845b = A * x
29- y = solve(LinearProblem(A, b), SparspakFactorization() ).u
46+ y = solve(LinearProblem(A, b)).u
3047sum(y)
3148```
3249
50+ ``` @example
51+ using ExtendableSparse
52+ using LinearSolve
53+ using MultiFloats
54+ A = fdrand(Float64x2, 10, 10, 10; matrixtype = ExtendableSparseMatrix)
55+ x = ones(Float64x2,1000)
56+ b = A * x
57+ y = solve(LinearProblem(A, b), SparspakFactorization()).u
58+ sum(y)
59+ ```
3360
34- ## Preconditioning
61+ ## Preconditioned Krylov solvers with LinearSolve.jl
3562
36- LinearSolve allows to pass preconditioner constructors via the ` precs ` keyword
63+ Since version 1.6, preconditioner constructors can be passed to iterative solvers via the [ ` precs `
64+ keyword argument] ( https://docs.sciml.ai/LinearSolve/stable/basics/Preconditioners/#prec )
3765to the iterative solver specification.
3866
3967``` @example
40- using ExtendableSparse # hide
41- using LinearSolve # hide
68+ using ExtendableSparse
69+ using LinearSolve
4270using ExtendableSparse: ILUZeroPreconBuilder
4371A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
4472x = ones(1000)
@@ -48,6 +76,7 @@ y = LinearSolve.solve(LinearProblem(A, b),
4876sum(y)
4977```
5078
79+ ## Available preconditioners
5180ExtendableSparse provides constructors for preconditioners wich can be used as ` precs ` .
5281These generally return a tuple ` (Pl,I) ` of a left preconditioner and a trivial right preconditioner.
5382
@@ -75,11 +104,32 @@ which wraps sparse LU factorizations supported by LinearSolve.jl
75104ExtendableSparse.LinearSolvePreconBuilder
76105```
77106
107+
78108Block preconditioner constructors are provided as well
79109``` @docs; canonical=false
80110ExtendableSparse.BlockPreconBuilder
81111```
82112
113+
114+ The example beloww shows how to create a block Jacobi preconditioner where the blocks are defined by even and odd
115+ degrees of freedom, and the diagonal blocks are solved using UMFPACK.
116+ ``` @example
117+ using ExtendableSparse
118+ using LinearSolve
119+ using ExtendableSparse: LinearSolvePreconBuilder, BlockPreconBuilder
120+ A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
121+ x = ones(1000)
122+ b = A * x
123+ partitioning=A->[1:2:size(A,1), 2:2:size(A,1)]
124+ umfpackprecs=LinearSolvePreconBuilder(UMFPACKFactorization())
125+ blockprecs=BlockPreconBuilder(;precs=umfpackprecs, partitioning)
126+ y = LinearSolve.solve(LinearProblem(A, b), KrylovJL_CG(; precs=blockprecs)).u
127+ sum(y)
128+ ```
129+ ` umpfackpreconbuilder ` e.g. could be replaced by ` SmoothedAggregationPreconBuilder() ` . Moreover, this approach
130+ works for any ` AbstractSparseMatrixCSC ` .
131+
132+
83133## Deprecated API
84134Passing a preconditioner via the ` Pl ` or ` Pr ` keyword arguments
85135will be deprecated in LinearSolve. ExtendableSparse used to
@@ -88,9 +138,9 @@ for this purpose. This approach is deprecated as of v1.6 and will be removed
88138with v2.0.
89139
90140``` @example
91- using ExtendableSparse # hide
92- using LinearSolve # hide
93- using SparseArrays # hide
141+ using ExtendableSparse
142+ using LinearSolve
143+ using SparseArray
94144using ILUZero
95145A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
96146x = ones(1000)
0 commit comments