Skip to content

Commit 07b586a

Browse files
authored
Merge pull request #43 from mohamed82008/v0.7_and_bugfixes
v0.7 upgrade, comments, bugfixes and cleanup
2 parents 061a541 + 94bd0df commit 07b586a

28 files changed

+640
-398
lines changed

.travis.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ os:
44
- linux
55
julia:
66
- 0.6
7+
- 0.7
8+
- 1.0
79
- nightly
810
notifications:
911
email: false
@@ -14,7 +16,7 @@ git:
1416
## (tests will run but not make your overall status red)
1517
matrix:
1618
allow_failures:
17-
- julia: nightly
19+
- julia: nightly
1820

1921
## uncomment and modify the following lines to manually install system packages
2022
addons:
@@ -25,10 +27,10 @@ addons:
2527
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi
2628

2729
## uncomment the following lines to override the default test script
28-
#script:
29-
# - julia -e 'Pkg.clone(pwd()); Pkg.build("AMG"); Pkg.test("AMG"; coverage=true)'
30+
script:
31+
- julia -e 'VERSION >= v"0.7-" && using Pkg; Pkg.clone(pwd()); Pkg.build("AlgebraicMultigrid"); Pkg.test("AlgebraicMultigrid"; coverage=true)'
3032
after_success:
3133
# push coverage results to Coveralls
32-
- julia -e 'cd(Pkg.dir("AMG")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
34+
- julia -e 'cd(Pkg.dir("AlgebraicMultigrid")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
3335
# push coverage results to Codecov
34-
- julia -e 'cd(Pkg.dir("AMG")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
36+
- julia -e 'cd(Pkg.dir("AlgebraicMultigrid")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

REQUIRE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
julia 0.6
2-
IterativeSolvers 0.4.1
2+
IterativeSolvers 0.6.0
3+
Compat 1.0.0

src/AMG.jl renamed to src/AlgebraicMultigrid.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
module AMG
1+
module AlgebraicMultigrid
22

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

8+
using Compat: rmul!
9+
10+
if VERSION < v"0.7-"
11+
const mul! = A_mul_B!
12+
end
13+
614
const MT = false
15+
const AMG = AlgebraicMultigrid
716

817
include("utils.jl")
918
export approximate_spectral_radius
1019

1120
include("strength.jl")
12-
export strength_of_connection, Classical, SymmetricStrength
21+
export Classical, SymmetricStrength
1322

1423
include("splitting.jl")
15-
export split_nodes, RS
24+
export RS
1625

1726
include("gallery.jl")
1827
export poisson
1928

2029
include("smoother.jl")
2130
export GaussSeidel, SymmetricSweep, ForwardSweep, BackwardSweep,
22-
smooth_prolongator, JacobiProlongation
31+
JacobiProlongation
2332

2433
include("multilevel.jl")
2534
export solve
@@ -28,7 +37,7 @@ include("classical.jl")
2837
export ruge_stuben
2938

3039
include("aggregate.jl")
31-
export aggregation, StandardAggregation
40+
export StandardAggregation
3241

3342
include("aggregation.jl")
3443
export fit_candidates, smoothed_aggregation

src/aggregate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct StandardAggregation
22
end
33

4-
function aggregation(::StandardAggregation, S::SparseMatrixCSC{T,R}) where {T,R}
4+
function (::StandardAggregation)(S::SparseMatrixCSC{T,R}) where {T,R}
55

66
n = size(S, 1)
77
x = zeros(R, n)
@@ -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: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
function smoothed_aggregation(A::SparseMatrixCSC{T,V},
1+
function smoothed_aggregation(A::TA,
2+
::Type{Val{bs}}=Val{1},
23
symmetry = HermitianSymmetry(),
34
strength = SymmetricStrength(),
45
aggregate = StandardAggregation(),
56
smooth = JacobiProlongation(4.0/3.0),
67
presmoother = GaussSeidel(),
78
postsmoother = GaussSeidel(),
8-
improve_candidates = GaussSeidel(4),
9+
improve_candidates = GaussSeidel(iter=4),
910
max_levels = 10,
1011
max_coarse = 10,
1112
diagonal_dominance = false,
1213
keep = false,
13-
coarse_solver = Pinv()) where {T,V}
14-
14+
coarse_solver = Pinv) where {T,V,bs,TA<:SparseMatrixCSC{T,V}}
1515

1616
n = size(A, 1)
1717
# B = kron(ones(n, 1), eye(1))
@@ -28,21 +28,29 @@ function smoothed_aggregation(A::SparseMatrixCSC{T,V},
2828
# agg = [aggregate for _ in 1:max_levels - 1]
2929
# sm = [smooth for _ in 1:max_levels]
3030

31-
levels = Vector{Level{T,V}}()
31+
@static if VERSION < v"0.7-"
32+
levels = Vector{Level{TA, TA, TA}}()
33+
else
34+
levels = Vector{Level{TA, TA, Adjoint{T, TA}}}()
35+
end
3236
bsr_flag = false
37+
w = MultiLevelWorkspace(Val{bs}, eltype(A))
3338

3439
while length(levels) + 1 < max_levels && size(A, 1) > max_coarse
40+
residual!(w, size(A, 1))
3541
A, B, bsr_flag = extend_hierarchy!(levels, strength, aggregate, smooth,
3642
improve_candidates, diagonal_dominance,
3743
keep, A, B, symmetry, bsr_flag)
44+
coarse_x!(w, size(A, 1))
45+
coarse_b!(w, size(A, 1))
3846
#=if size(A, 1) <= max_coarse
3947
break
4048
end=#
4149
end
4250
#=A, B = extend_hierarchy!(levels, strength, aggregate, smooth,
4351
improve_candidates, diagonal_dominance,
4452
keep, A, B, symmetry)=#
45-
MultiLevel(levels, A, presmoother, postsmoother)
53+
MultiLevel(levels, A, coarse_solver(A), presmoother, postsmoother, w)
4654
end
4755

4856
struct HermitianSymmetry
@@ -54,18 +62,22 @@ function extend_hierarchy!(levels, strength, aggregate, smooth,
5462
symmetry, bsr_flag)
5563

5664
# Calculate strength of connection matrix
57-
S = strength_of_connection(strength, A, bsr_flag)
65+
if symmetry isa HermitianSymmetry
66+
S, _T = strength(A, bsr_flag)
67+
else
68+
S, _T = strength(adjoint(A), bsr_flag)
69+
end
5870

5971
# Aggregation operator
60-
AggOp = aggregation(aggregate, S)
72+
AggOp = aggregate(S)
6173
# b = zeros(eltype(A), size(A, 1))
6274

6375
# Improve candidates
6476
b = zeros(size(A,1))
65-
relax!(improve_candidates, A, B, b)
77+
improve_candidates(A, B, b)
6678
T, B = fit_candidates(AggOp, B)
6779

68-
P = smooth_prolongator(smooth, A, T, S, B)
80+
P = smooth(A, T, S, B)
6981
R = construct_R(symmetry, P)
7082
push!(levels, Level(A, P, R))
7183

@@ -81,7 +93,7 @@ construct_R(::HermitianSymmetry, P) = P'
8193

8294
function fit_candidates(AggOp, B, tol = 1e-10)
8395

84-
A = AggOp.'
96+
A = adjoint(AggOp)
8597
n_fine, n_coarse = size(A)
8698
n_col = n_coarse
8799

0 commit comments

Comments
 (0)