Skip to content

Commit ad12ebe

Browse files
committed
Allow preconditioner creation directly from CSC Matrix
Rename AbstractPreconditioner to AbstractExtendablePreconditioner
1 parent 93c8890 commit ad12ebe

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExtendableSparse"
22
uuid = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
33
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"

src/ExtendableSparse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include("preconditioners.jl")
99
include("sprand.jl")
1010

1111
export SparseMatrixLNK,ExtendableSparseMatrix,flush!,nnz, sprand!,sprand_sdd!
12-
export JacobiPreconditioner, ILU0Preconditioner
12+
export JacobiPreconditioner, ILU0Preconditioner, update!
1313

1414
export colptrs
1515
end # module

src/ilu0.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mutable struct ILU0Preconditioner{Tv, Ti} <: AbstractPreconditioner{Tv,Ti}
1+
mutable struct ILU0Preconditioner{Tv, Ti} <: AbstractExtendablePreconditioner{Tv,Ti}
22
extmatrix::ExtendableSparseMatrix{Tv,Ti}
33
xdiag::Array{Tv,1}
44
idiag::Array{Ti,1}
@@ -16,6 +16,9 @@ function ILU0Preconditioner(extmatrix::ExtendableSparseMatrix{Tv,Ti}) where {Tv,
1616
update!(precon)
1717
end
1818

19+
ILU0Preconditioner(cscmatrix::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti}=ILU0Preconditioner(ExtendableSparseMatrix(cscmatrix))
20+
21+
1922
function update!(precon::ILU0Preconditioner{Tv,Ti}) where {Tv,Ti}
2023
cscmatrix=precon.extmatrix.cscmatrix
2124
colptr=cscmatrix.colptr

src/jacobi.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
struct JacobiPreconditioner{Tv, Ti} <: AbstractPreconditioner{Tv,Ti}
1+
struct JacobiPreconditioner{Tv, Ti} <: AbstractExtendablePreconditioner{Tv,Ti}
22
extmatrix::ExtendableSparseMatrix{Tv,Ti}
33
invdiag::Array{Tv,1}
44
end
@@ -21,6 +21,8 @@ function JacobiPreconditioner(extmatrix::ExtendableSparseMatrix{Tv,Ti}) where {T
2121
update!(precon)
2222
end
2323

24+
JacobiPreconditioner(cscmatrix::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti}=JacobiPreconditioner(ExtendableSparseMatrix(cscmatrix))
25+
2426

2527
function LinearAlgebra.ldiv!(u::AbstractArray{T,1} where T, precon::JacobiPreconditioner, v::AbstractArray{T,1} where T)
2628
invdiag=precon.invdiag

src/preconditioners.jl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
abstract type AbstractPreconditioner{Tv,Ti} end
1+
"""
2+
Abstract type for an extendabe preconditoioner working together
3+
with ExtandableSparseMatrix.
4+
Still beta, so not in the published documentation.
5+
6+
Any such preconditioner should have the following fields
7+
````
8+
extmatrix
9+
pattern_timestamp
10+
````
11+
and methods
12+
````
13+
update!(precon)
14+
````
15+
The idea is that, depending if the matrix pattern has changed,
16+
different steps are needed to update the preconditioner.
217
3-
need_symbolic_update(precon::AbstractPreconditioner)=precon.extmatrix.pattern_timestamp>precon.pattern_timestamp
4-
timestamp!(precon::AbstractPreconditioner)= precon.pattern_timestamp=time()
18+
Moreover, they have the ExtendableSparseMatrix as a field, ensuring
19+
consistency after construction.
20+
"""
21+
abstract type AbstractExtendablePreconditioner{Tv,Ti} end
22+
23+
need_symbolic_update(precon::AbstractExtendablePreconditioner)=precon.extmatrix.pattern_timestamp>precon.pattern_timestamp
24+
timestamp!(precon::AbstractExtendablePreconditioner)= precon.pattern_timestamp=time()
525

626
include("jacobi.jl")
727
include("ilu0.jl")
28+

0 commit comments

Comments
 (0)