1
- # Integration with LinearSolve.jl
1
+ # Linear System solution
2
2
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.
11
7
12
8
``` @example
13
- using ExtendableSparse # hide
9
+ using ExtendableSparse
14
10
A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
15
11
x = ones(1000)
16
12
b = A * x
17
13
y = A \ b
18
14
sum(y)
19
15
```
20
16
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
+
21
38
The same problem can be solved via ` LinearSolve.jl ` :
22
39
23
40
``` @example
24
- using ExtendableSparse # hide
25
- using LinearSolve # hide
41
+ using ExtendableSparse
42
+ using LinearSolve
26
43
A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
27
44
x = ones(1000)
28
45
b = A * x
29
- y = solve(LinearProblem(A, b), SparspakFactorization() ).u
46
+ y = solve(LinearProblem(A, b)).u
30
47
sum(y)
31
48
```
32
49
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
+ ```
33
60
34
- ## Preconditioning
61
+ ## Preconditioned Krylov solvers with LinearSolve.jl
35
62
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 )
37
65
to the iterative solver specification.
38
66
39
67
``` @example
40
- using ExtendableSparse # hide
41
- using LinearSolve # hide
68
+ using ExtendableSparse
69
+ using LinearSolve
42
70
using ExtendableSparse: ILUZeroPreconBuilder
43
71
A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
44
72
x = ones(1000)
@@ -48,6 +76,7 @@ y = LinearSolve.solve(LinearProblem(A, b),
48
76
sum(y)
49
77
```
50
78
79
+ ## Available preconditioners
51
80
ExtendableSparse provides constructors for preconditioners wich can be used as ` precs ` .
52
81
These generally return a tuple ` (Pl,I) ` of a left preconditioner and a trivial right preconditioner.
53
82
@@ -75,11 +104,32 @@ which wraps sparse LU factorizations supported by LinearSolve.jl
75
104
ExtendableSparse.LinearSolvePreconBuilder
76
105
```
77
106
107
+
78
108
Block preconditioner constructors are provided as well
79
109
``` @docs; canonical=false
80
110
ExtendableSparse.BlockPreconBuilder
81
111
```
82
112
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
+
83
133
## Deprecated API
84
134
Passing a preconditioner via the ` Pl ` or ` Pr ` keyword arguments
85
135
will 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
88
138
with v2.0.
89
139
90
140
``` @example
91
- using ExtendableSparse # hide
92
- using LinearSolve # hide
93
- using SparseArrays # hide
141
+ using ExtendableSparse
142
+ using LinearSolve
143
+ using SparseArray
94
144
using ILUZero
95
145
A = fdrand(10, 10, 10; matrixtype = ExtendableSparseMatrix)
96
146
x = ones(1000)
0 commit comments