Skip to content

Commit f40ac89

Browse files
committed
v0.7 support, cleanup, comments and bug fixes
1 parent 061a541 commit f40ac89

File tree

14 files changed

+181
-182
lines changed

14 files changed

+181
-182
lines changed

REQUIRE

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
julia 0.6
2-
IterativeSolvers 0.4.1
1+
julia 0.7
2+
IterativeSolvers 0.7.0
3+
Compat 1.0.0

src/AMG.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module AMG
22

33
import IterativeSolvers: gauss_seidel!
4+
using Compat, Compat.LinearAlgebra
5+
using Compat.SparseArrays, Compat.Printf
46
using Base.Threads
57

68
const MT = false

src/aggregate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function aggregation(::StandardAggregation, S::SparseMatrixCSC{T,R}) where {T,R}
9797
if minimum(x) == -1
9898
mask = x .!= -1
9999
I = collect(R, 1:n)[mask]
100-
J = x[mask] + R(1)
100+
J = x[mask] .+ R(1)
101101
#J = x[mask] + 1
102102
V = ones(eltype(S), length(J))
103103
AggOp = sparse(J,I,V,N,M)

src/aggregation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ function extend_hierarchy!(levels, strength, aggregate, smooth,
7777

7878
A, B, bsr_flag
7979
end
80-
construct_R(::HermitianSymmetry, P) = P'
80+
construct_R(::HermitianSymmetry, P) = copy(P')
8181

8282
function fit_candidates(AggOp, B, tol = 1e-10)
8383

84-
A = AggOp.'
84+
A = copy(AggOp')
8585
n_fine, n_coarse = size(A)
8686
n_col = n_coarse
8787

src/classical.jl

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ struct Solver{S,T,P,PS}
77
max_coarse::Int64
88
end
99

10-
function ruge_stuben{Ti,Tv}(A::SparseMatrixCSC{Ti,Tv};
10+
function ruge_stuben(A::SparseMatrixCSC{Ti,Tv};
1111
strength = Classical(0.25),
1212
CF = RS(),
1313
presmoother = GaussSeidel(),
1414
postsmoother = GaussSeidel(),
1515
max_levels = 10,
16-
max_coarse = 10)
16+
max_coarse = 10) where {Ti,Tv}
1717

1818
s = Solver(strength, CF, presmoother,
1919
postsmoother, max_levels, max_levels)
@@ -29,7 +29,7 @@ function ruge_stuben{Ti,Tv}(A::SparseMatrixCSC{Ti,Tv};
2929
MultiLevel(levels, A, presmoother, postsmoother)
3030
end
3131

32-
function extend_heirarchy!{Ti,Tv}(levels::Vector{Level{Ti,Tv}}, strength, CF, A::SparseMatrixCSC{Ti,Tv})
32+
function extend_heirarchy!(levels::Vector{Level{Ti,Tv}}, strength, CF, A::SparseMatrixCSC{Ti,Tv}) where {Ti,Tv}
3333
S, T = strength_of_connection(strength, A)
3434
splitting = split_nodes(CF, S)
3535
P, R = direct_interpolation(A, T, splitting)
@@ -38,50 +38,43 @@ function extend_heirarchy!{Ti,Tv}(levels::Vector{Level{Ti,Tv}}, strength, CF, A:
3838
end
3939

4040
function direct_interpolation(A, T, splitting)
41-
42-
fill!(T.nzval, eltype(A)(1.))
41+
fill!(T.nzval, eltype(A)(1))
4342
T .= A .* T
44-
Pp = rs_direct_interpolation_pass1(T, A, splitting)
45-
Pp .= Pp .+ 1
46-
43+
Pp = rs_direct_interpolation_pass1(T, splitting)
4744
Px, Pj, Pp = rs_direct_interpolation_pass2(A, T, splitting, Pp)
4845

49-
Pj .= Pj .+ 1
50-
5146
R = SparseMatrixCSC(maximum(Pj), size(A, 1), Pp, Pj, Px)
52-
P = R'
47+
P = copy(R')
5348

5449
P, R
5550
end
5651

57-
58-
function rs_direct_interpolation_pass1(T, A, splitting)
59-
60-
Bp = zeros(Int, size(A.colptr))
61-
n = size(A, 1)
62-
nnz = 0
63-
for i = 1:n
64-
if splitting[i] == C_NODE
65-
nnz += 1
66-
else
67-
for j in nzrange(T, i)
68-
row = T.rowval[j]
69-
if splitting[row] == C_NODE && row != i
70-
nnz += 1
52+
# calculates the number of nonzeros in each column of the interpolation matrix
53+
function rs_direct_interpolation_pass1(T, splitting)
54+
n = size(T, 2)
55+
Bp = ones(Int, n+1)
56+
nnzplus1 = 1
57+
for i = 1:n
58+
if splitting[i] == C_NODE
59+
nnzplus1 += 1
60+
else
61+
for j in nzrange(T, i)
62+
row = T.rowval[j]
63+
if splitting[row] == C_NODE && row != i
64+
nnzplus1 += 1
7165
end
72-
end
66+
end
7367
end
74-
Bp[i+1] = nnz
75-
end
76-
Bp
68+
Bp[i+1] = nnzplus1
69+
end
70+
Bp
7771
end
7872

7973

80-
function rs_direct_interpolation_pass2(A::SparseMatrixCSC{Tv,Ti},
74+
function rs_direct_interpolation_pass2(A::SparseMatrixCSC{Tv,Ti},
8175
T::SparseMatrixCSC{Tv, Ti},
8276
splitting::Vector{Ti},
8377
Bp::Vector{Ti}) where {Tv,Ti}
84-
8578

8679
Bx = zeros(Tv, Bp[end] - 1)
8780
Bj = zeros(Ti, Bp[end] - 1)
@@ -157,7 +150,7 @@ function rs_direct_interpolation_pass1(T, A, splitting)
157150
m[i] = sum
158151
sum += splitting[i]
159152
end
160-
Bj .= m[Bj]
153+
Bj .= m[Bj] .+ 1
161154

162-
Bx, Bj, Bp
155+
Bx, Bj, Bp
163156
end

src/multilevel.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract type CoarseSolver end
1616
struct Pinv <: CoarseSolver
1717
end
1818

19-
MultiLevel{Ti,Tv}(l::Vector{Level{Ti,Tv}}, A::SparseMatrixCSC{Ti,Tv}, presmoother, postsmoother) =
19+
MultiLevel(l::Vector{Level{Ti,Tv}}, A::SparseMatrixCSC{Ti,Tv}, presmoother, postsmoother) where {Ti,Tv} =
2020
MultiLevel(l, A, Pinv(), presmoother, postsmoother)
2121
Base.length(ml) = length(ml.levels) + 1
2222

@@ -92,12 +92,12 @@ Keyword Arguments
9292
* log::Bool - return vector of residuals along with solution
9393
9494
"""
95-
function solve{T}(ml::MultiLevel, b::Vector{T},
95+
function solve(ml::MultiLevel, b::Vector{T},
9696
cycle::Cycle = V();
9797
maxiter::Int = 100,
9898
tol::Float64 = 1e-5,
9999
verbose::Bool = false,
100-
log::Bool = false)
100+
log::Bool = false) where {T}
101101

102102
A = length(ml) == 1 ? ml.final_A : ml.levels[1].A
103103
V = promote_type(eltype(A), eltype(b))
@@ -149,4 +149,4 @@ function __solve(v::V, ml, x, b, lvl)
149149
x
150150
end
151151

152-
coarse_solver(::Pinv, A, b) = pinv(full(A)) * b
152+
coarse_solver(::Pinv, A, b) = pinv(Matrix(A)) * b

src/preconditioner.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Base: \, *, A_ldiv_B!, A_mul_B!
1+
import LinearAlgebra: \, *, ldiv!, mul!
22

33
struct Preconditioner
44
ml::MultiLevel
@@ -9,5 +9,5 @@ aspreconditioner(ml::MultiLevel) = Preconditioner(ml)
99
\(p::Preconditioner, b) = solve(p.ml, b, maxiter = 1, tol = 1e-12)
1010
*(p::Preconditioner, b) = p.ml.levels[1].A * x
1111

12-
A_ldiv_B!(x, p::Preconditioner, b) = copy!(x, p \ b)
13-
A_mul_B!(b, p::Preconditioner, x) = A_mul_B!(b, p.ml.levels[1].A, x)
12+
ldiv!(x, p::Preconditioner, b) = copyto!(x, p \ b)
13+
mul!(b, p::Preconditioner, x) = mul!(b, p.ml.levels[1].A, x)

src/smoother.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function weight(::LocalWeighting, S, ω)
143143
end
144144
D_inv_S = scale_rows(S, D)
145145
# eltype(S)(ω) * D_inv_S
146-
scale!(D_inv_S, eltype(S)(ω))
146+
rmul!(D_inv_S, eltype(S)(ω))
147147
end
148148

149149
#approximate_spectral_radius(A) =

0 commit comments

Comments
 (0)