|
| 1 | +# Integration with LinearSolve.jl |
| 2 | + |
| 3 | +Starting with version 0.7, ExtendableSparse tries to become compatible |
| 4 | +with [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl). |
| 5 | +For this purpose, it extends the `LinearProblem` constructor and the |
| 6 | +`set_A` function by methods specific for `ExtendableSparseMatrix`. |
| 7 | + |
| 8 | +```@docs |
| 9 | +LinearSolve.LinearProblem(::ExtendableSparseMatrix,x,p;kwargs...) |
| 10 | +LinearSolve.set_A(::LinearSolve.LinearCache,::ExtendableSparseMatrix) |
| 11 | +``` |
| 12 | + |
| 13 | +We can create a test problem and solve it with the `\` operator. |
| 14 | +```@example |
| 15 | +using ExtendableSparse # hide |
| 16 | +A=fdrand(10,10,10,matrixtype=ExtendableSparseMatrix) |
| 17 | +x=ones(1000) |
| 18 | +b=A*x |
| 19 | +y=A\b |
| 20 | +sum(y) |
| 21 | +``` |
| 22 | + |
| 23 | +The same problem can be solved by the tools available via `LinearSolve.jl`: |
| 24 | +```@example |
| 25 | +using ExtendableSparse # hide |
| 26 | +using LinearSolve # hide |
| 27 | +A=fdrand(10,10,10,matrixtype=ExtendableSparseMatrix) |
| 28 | +x=ones(1000) |
| 29 | +b=A*x |
| 30 | +y=solve(LinearProblem(A,b),KLUFactorization()).u |
| 31 | +sum(y) |
| 32 | +``` |
| 33 | + |
| 34 | + |
| 35 | +Also, the iterative method interface works with the preconditioners defined in this package. |
| 36 | +```@example |
| 37 | +using ExtendableSparse # hide |
| 38 | +using LinearSolve # hide |
| 39 | +A=fdrand(10,10,10,matrixtype=ExtendableSparseMatrix) |
| 40 | +x=ones(1000) |
| 41 | +b=A*x |
| 42 | +y=LinearSolve.solve(LinearProblem(A,b),IterativeSolversJL_CG(),Pl=ILU0Preconditioner(A)).u |
| 43 | +sum(y) |
| 44 | +``` |
0 commit comments