Skip to content

Commit c6c86ca

Browse files
authored
Factorization types (#12)
Change factorization :symbols to factorization types. This is more in-line with DiffEq, and allows to pass preconditioner parameters with their constructors.
1 parent 271857b commit c6c86ca

File tree

14 files changed

+285
-351
lines changed

14 files changed

+285
-351
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ QUARRY
33
docs/build
44
*~
55
Manifest.toml
6+
.repl_history.jl
67

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.5.2"
4+
version = "0.6.0"
55

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

docs/src/iter.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
## Factorizations
44

5-
In this package, preconditioners and LU factorizations are subcategories are both seen
6-
as complete or approximate _factorizations_. Correspondingly there is a common API for
5+
In this package, preconditioners and LU factorizations are both seen
6+
as complete or approximate _factorizations_. Correspondingly we provide a common API for
77
their creation.
88

9-
Factorizations from these package know the matrices which have been factorized.
109

1110
```@autodocs
1211
Modules = [ExtendableSparse]
1312
Pages = ["factorizations.jl"]
13+
Order = [:function, :type]
14+
Private = false
1415
```
1516

1617
## LU Factorizations

src/ExtendableSparse.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ export SparseMatrixLNK,ExtendableSparseMatrix,flush!,nnz, updateindex!, rawupdat
1616

1717
include("factorizations.jl")
1818
export JacobiPreconditioner, ILU0Preconditioner, ParallelJacobiPreconditioner
19+
export AbstractFactorization,LUFactorization, CholeskyFactorization
1920
export issolver
20-
export factorize,factorize!, update!
21+
export factorize!, update!
2122
export ILUTPreconditioner, AMGPreconditioner
23+
export PardisoLU, MKLPardisoLU
2224

2325
include("simple_iteration.jl")
2426
export simple,simple!

src/amg.jl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1-
"""
2-
$(TYPEDEF)
3-
4-
"""
5-
mutable struct AMGPreconditioner{Tv, Ti} <: AbstractExtendableSparsePreconditioner{Tv,Ti}
1+
mutable struct AMGPreconditioner{Tv, Ti} <: AbstractPreconditioner{Tv,Ti}
62
A::ExtendableSparseMatrix{Tv,Ti}
73
fact
4+
max_levels::Int
5+
max_coarse::Int
6+
function AMGPreconditioner{Tv,Ti}(;max_levels=10, max_coarse=10) where {Tv,Ti}
7+
precon=new()
8+
precon.max_levels=max_levels
9+
precon.max_coarse=max_coarse
10+
precon
11+
end
812
end
913

1014
"""
1115
```
12-
AMGPreconditioner(extmatrix)
16+
AMGPreconditioner(;max_levels=10, max_coarse=10)
17+
AMGPreconditioner(matrix;max_levels=10, max_coarse=10)
1318
```
19+
20+
Create the [`AMGPreconditioner`](@ref) wrapping the Ruge-Stüben AMG preconditioner from [AlgebraicMultigrid.jl](https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl)
1421
"""
15-
function AMGPreconditioner(A::ExtendableSparseMatrix{Tv,Ti}) where {Tv,Ti}
16-
@inbounds flush!(A)
17-
p=AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(A.cscmatrix))
18-
AMGPreconditioner{Tv,Ti}(A,p)
22+
AMGPreconditioner(;kwargs...)=AMGPreconditioner{Float64,Int64}(;kwargs...)
23+
24+
@eval begin
25+
@makefrommatrix AMGPreconditioner
1926
end
2027

28+
29+
2130
function update!(precon::AMGPreconditioner{Tv,Ti}) where {Tv,Ti}
2231
@inbounds flush!(precon.A)
2332
precon.fact=AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(precon.A.cscmatrix))

src/cholmod_cholesky.jl

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
"""
2-
$(TYPEDEF)
3-
4-
Default Julia LU Factorization based on umfpack.
5-
"""
6-
mutable struct ExtendableSparseCholmodCholesky{Tv, Ti} <: AbstractExtendableSparseLU{Tv,Ti}
7-
A::ExtendableSparseMatrix{Tv,Ti}
8-
A64
9-
fact::SuiteSparse.CHOLMOD.Factor{Tv}
1+
mutable struct CholeskyFactorization{Tv, Ti} <: AbstractLUFactorization{Tv,Ti}
2+
A::Union{ExtendableSparseMatrix{Tv,Ti},Nothing}
3+
fact::Union{SuiteSparse.CHOLMOD.Factor{Tv},Nothing}
104
phash::UInt64
5+
A64
116
end
127

138
"""
14-
```
15-
ExtendableSparseCholmodCholesky(A)
16-
```
9+
CholeskyFactorization()
10+
CholeskyFactorization(matrix)
11+
12+
Default Cholesky factorization via cholmod.
1713
"""
18-
function ExtendableSparseCholmodCholesky(A::ExtendableSparseMatrix{Tv,Ti}) where {Tv,Ti}
19-
flush!(A)
20-
A64=Symmetric(SparseMatrixCSC{Float64,Int64}(A.cscmatrix))
21-
ExtendableSparseCholmodCholesky(A,A64,cholesky(A64),A.phash)
22-
end
14+
CholeskyFactorization()=CholeskyFactorization{Float64,Int64}(nothing,nothing,0,nothing)
2315

24-
function update!(cholfact::ExtendableSparseCholmodCholesky)
25-
flush!(cholfact.A)
26-
if cholfact.A.phash!=cholfact.phash
27-
cholfact.A64=Symmetric{SparseMatrixCSC{Float64,Int64}(A.cscmatrix)}
28-
cholfact.fact=cholesky(cholfact.fact,cholfact.A64)
29-
cholfact.phash=cholfact.A.phash
16+
17+
function update!(cholfact::CholeskyFactorization)
18+
A=cholfact.A
19+
flush!(A)
20+
if A.phash!=cholfact.phash
21+
cholfact.A64=Symmetric(SparseMatrixCSC{Float64,Int64}(A.cscmatrix))
22+
cholfact.fact=cholesky(cholfact.A64)
23+
cholfact.phash=A.phash
3024
else
31-
cholfact.A64.data.nzval.=cholfact.A.cscmatrix.nzval
25+
cholfact.A64.data.nzval.=A.cscmatrix.nzval
3226
cholfact.fact=cholesky!(cholfact.fact,cholfact.A64)
3327
end
3428
cholfact
3529
end
3630

3731

38-
LinearAlgebra.ldiv!(fact::ExtendableSparseCholmodCholesky, v)=fact.fact\v
39-
LinearAlgebra.ldiv!(u,fact::ExtendableSparseCholmodCholesky, v)=u.=fact.fact\v
32+
LinearAlgebra.ldiv!(fact::CholeskyFactorization, v)=fact.fact\v
33+
LinearAlgebra.ldiv!(u,fact::CholeskyFactorization, v)=u.=fact.fact\v
4034

0 commit comments

Comments
 (0)