Skip to content

Commit 397f719

Browse files
committed
added more tests, version bump
- added simple iteration scheme - fixed fdrand (boundray terms) - added tests for fdrand, preconditioners
1 parent 70981a3 commit 397f719

File tree

7 files changed

+210
-136
lines changed

7 files changed

+210
-136
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.3.6"
4+
version = "0.3.7"
55

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

src/ExtendableSparse.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ using LinearAlgebra
66
include("sparsematrixcsc.jl")
77
include("sparsematrixlnk.jl")
88
include("extendable.jl")
9+
export SparseMatrixLNK,ExtendableSparseMatrix,flush!,nnz, updateindex, colptrs
10+
911
include("preconditioners.jl")
10-
include("sprand.jl")
12+
export JacobiPreconditioner, ILU0Preconditioner, ParallelJacobiPreconditioner
1113

12-
export SparseMatrixLNK,ExtendableSparseMatrix,flush!,nnz, sprand!,sprand_sdd!, fdrand,fdrand!
13-
export JacobiPreconditioner, ILU0Preconditioner, ParallelJacobiPreconditioner, updateindex!
14+
include("simple_iteration.jl")
15+
export simple,simple!
1416

15-
export colptrs
17+
include("sprand.jl")
18+
export sprand!,sprand_sdd!, fdrand,fdrand!
1619
end # module

src/preconditioners.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ timestamp!(precon::AbstractExtendablePreconditioner)= precon.pattern_timestamp=t
2525

2626
include("jacobi.jl")
2727
include("ilu0.jl")
28-
2928
include("parallel_jacobi.jl")
3029

src/simple_iteration.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
````
3+
simple!(u,A,b;
4+
abstol::Real = zero(real(eltype(b))),
5+
reltol::Real = sqrt(eps(real(eltype(b)))),
6+
log=false,
7+
maxiter=100,
8+
P=nothing
9+
) -> soution, [history]
10+
````
11+
12+
Simple iteration scheme ``u_{i+1}= u_i - P^{-1} (A u_i -b)`` with similar API as the methods in IterativeSolvers.jl.
13+
14+
"""
15+
function simple!(u,A,b;
16+
abstol::Real = zero(real(eltype(b))),
17+
reltol::Real = sqrt(eps(real(eltype(b)))),
18+
log=false,
19+
maxiter=100,
20+
Pl=nothing
21+
)
22+
res=A*u-b # initial residual
23+
upd=similar(res)
24+
r0=norm(res) # residual norm
25+
history=[r0] # intialize history recording
26+
for i=1:maxiter
27+
ldiv!(upd,Pl,res)
28+
u.-=upd # solve preconditioning system and update solution
29+
mul!(res,A,u) # calculate residual
30+
res.-=b
31+
r=norm(res) # residual norm
32+
push!(history,r) # record in history
33+
if (r/r0)<reltol || r<abstol # check for tolerance
34+
break
35+
end
36+
end
37+
if log
38+
return u,Dict( :resnorm =>history )
39+
else
40+
return u
41+
end
42+
end
43+
44+
simple(A,b;kwargs...)=simple!(zeros(eltype(b),length(b)),A,b;kwargs...)

src/sprand.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ function fdrand!(A::AbstractMatrix,
101101
update_pair(A,rand()*hy*hz/hx,l,l+1)
102102
end
103103
if i==1|| i==nx
104-
update(A,rand(),l,l)
104+
update(A,rand()*hy*hz,l,l)
105105
end
106106
if j<ny
107107
update_pair(A,rand()*hx*hz/hy,l,l+nx)
108108
end
109109
if ny>2&&(j==1|| j==ny)
110-
update(A,rand(),l,l)
110+
update(A,rand()*hx*hz,l,l)
111111
end
112112
if k<nz
113113
update_pair(A,rand()*hx*hy/hz,l,l+nxy)
114114
end
115115
if nz>2&&(k==1|| k==nz)
116-
update(A,rand(),l,l)
116+
update(A,rand()*hx*hy,l,l)
117117
end
118118
l=l+1
119119
end
@@ -162,7 +162,7 @@ Tested for Matrix, SparseMatrixCSC and ExtendableSparseMatrix.
162162
function fdrand(nx,ny,nz;
163163
matrixtype::Type{Tv}=SparseMatrixCSC,
164164
update = (A,v,i,j)-> A[i,j]+=v,
165-
rand=()-> rand()) where Tv
165+
rand= ()-> 0.1+rand()) where Tv
166166
N=nx*ny*nz
167167
if matrixtype==ExtendableSparseMatrix
168168
A=ExtendableSparseMatrix(N,N)

test/ExtendableSparseTest.jl

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)