Skip to content

Commit

Permalink
Merge pull request #43 from mohamed82008/v0.7_and_bugfixes
Browse files Browse the repository at this point in the history
v0.7 upgrade, comments, bugfixes and cleanup
  • Loading branch information
ranjanan authored Aug 27, 2018
2 parents 061a541 + 94bd0df commit 07b586a
Show file tree
Hide file tree
Showing 28 changed files with 640 additions and 398 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
Expand All @@ -14,7 +16,7 @@ git:
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia: nightly
- julia: nightly

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

## uncomment the following lines to override the default test script
#script:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("AMG"); Pkg.test("AMG"; coverage=true)'
script:
- julia -e 'VERSION >= v"0.7-" && using Pkg; Pkg.clone(pwd()); Pkg.build("AlgebraicMultigrid"); Pkg.test("AlgebraicMultigrid"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("AMG")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'cd(Pkg.dir("AlgebraicMultigrid")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("AMG")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'cd(Pkg.dir("AlgebraicMultigrid")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.6
IterativeSolvers 0.4.1
IterativeSolvers 0.6.0
Compat 1.0.0
19 changes: 14 additions & 5 deletions src/AMG.jl → src/AlgebraicMultigrid.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
module AMG
module AlgebraicMultigrid

import IterativeSolvers: gauss_seidel!
using Compat, Compat.LinearAlgebra
using Compat.SparseArrays, Compat.Printf
using Base.Threads

using Compat: rmul!

if VERSION < v"0.7-"
const mul! = A_mul_B!
end

const MT = false
const AMG = AlgebraicMultigrid

include("utils.jl")
export approximate_spectral_radius

include("strength.jl")
export strength_of_connection, Classical, SymmetricStrength
export Classical, SymmetricStrength

include("splitting.jl")
export split_nodes, RS
export RS

include("gallery.jl")
export poisson

include("smoother.jl")
export GaussSeidel, SymmetricSweep, ForwardSweep, BackwardSweep,
smooth_prolongator, JacobiProlongation
JacobiProlongation

include("multilevel.jl")
export solve
Expand All @@ -28,7 +37,7 @@ include("classical.jl")
export ruge_stuben

include("aggregate.jl")
export aggregation, StandardAggregation
export StandardAggregation

include("aggregation.jl")
export fit_candidates, smoothed_aggregation
Expand Down
4 changes: 2 additions & 2 deletions src/aggregate.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
struct StandardAggregation
end

function aggregation(::StandardAggregation, S::SparseMatrixCSC{T,R}) where {T,R}
function (::StandardAggregation)(S::SparseMatrixCSC{T,R}) where {T,R}

n = size(S, 1)
x = zeros(R, n)
Expand Down Expand Up @@ -97,7 +97,7 @@ function aggregation(::StandardAggregation, S::SparseMatrixCSC{T,R}) where {T,R}
if minimum(x) == -1
mask = x .!= -1
I = collect(R, 1:n)[mask]
J = x[mask] + R(1)
J = x[mask] .+ R(1)
#J = x[mask] + 1
V = ones(eltype(S), length(J))
AggOp = sparse(J,I,V,N,M)
Expand Down
34 changes: 23 additions & 11 deletions src/aggregation.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function smoothed_aggregation(A::SparseMatrixCSC{T,V},
function smoothed_aggregation(A::TA,
::Type{Val{bs}}=Val{1},
symmetry = HermitianSymmetry(),
strength = SymmetricStrength(),
aggregate = StandardAggregation(),
smooth = JacobiProlongation(4.0/3.0),
presmoother = GaussSeidel(),
postsmoother = GaussSeidel(),
improve_candidates = GaussSeidel(4),
improve_candidates = GaussSeidel(iter=4),
max_levels = 10,
max_coarse = 10,
diagonal_dominance = false,
keep = false,
coarse_solver = Pinv()) where {T,V}

coarse_solver = Pinv) where {T,V,bs,TA<:SparseMatrixCSC{T,V}}

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

levels = Vector{Level{T,V}}()
@static if VERSION < v"0.7-"
levels = Vector{Level{TA, TA, TA}}()
else
levels = Vector{Level{TA, TA, Adjoint{T, TA}}}()
end
bsr_flag = false
w = MultiLevelWorkspace(Val{bs}, eltype(A))

while length(levels) + 1 < max_levels && size(A, 1) > max_coarse
residual!(w, size(A, 1))
A, B, bsr_flag = extend_hierarchy!(levels, strength, aggregate, smooth,
improve_candidates, diagonal_dominance,
keep, A, B, symmetry, bsr_flag)
coarse_x!(w, size(A, 1))
coarse_b!(w, size(A, 1))
#=if size(A, 1) <= max_coarse
break
end=#
end
#=A, B = extend_hierarchy!(levels, strength, aggregate, smooth,
improve_candidates, diagonal_dominance,
keep, A, B, symmetry)=#
MultiLevel(levels, A, presmoother, postsmoother)
MultiLevel(levels, A, coarse_solver(A), presmoother, postsmoother, w)
end

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

# Calculate strength of connection matrix
S = strength_of_connection(strength, A, bsr_flag)
if symmetry isa HermitianSymmetry
S, _T = strength(A, bsr_flag)
else
S, _T = strength(adjoint(A), bsr_flag)
end

# Aggregation operator
AggOp = aggregation(aggregate, S)
AggOp = aggregate(S)
# b = zeros(eltype(A), size(A, 1))

# Improve candidates
b = zeros(size(A,1))
relax!(improve_candidates, A, B, b)
improve_candidates(A, B, b)
T, B = fit_candidates(AggOp, B)

P = smooth_prolongator(smooth, A, T, S, B)
P = smooth(A, T, S, B)
R = construct_R(symmetry, P)
push!(levels, Level(A, P, R))

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

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

A = AggOp.'
A = adjoint(AggOp)
n_fine, n_coarse = size(A)
n_col = n_coarse

Expand Down
Loading

0 comments on commit 07b586a

Please sign in to comment.