Skip to content

Commit cf8e6af

Browse files
committed
Review and revise API
1 parent 5e25911 commit cf8e6af

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

src/AMG.jl

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

33
include("strength.jl")
4-
export classical
4+
export strength_of_connection, Classical
55

66
include("splitting.jl")
7-
export RS
7+
export split_nodes, RS
88

99
include("gallery.jl")
1010
export poisson

src/classical.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
struct Solver{S,T,P,PS}
2+
strength::S
3+
CF::T
4+
presmoother::P
5+
postsmoother::PS
6+
max_levels::Int64
7+
max_coarse::Int64
8+
end
9+
10+
function ruge_stuben(A::SparseMatrixCSC;
11+
strength = Classical(),
12+
CF = RS(),
13+
presmoother = GaussSiedel(),
14+
postsmoother = GaussSiedel(),
15+
max_levels = 10,
16+
max_coarse = 500)
17+
18+
s = Solver(strength, CF, presmoother,
19+
postsmoother, max_levels, max_levels)
20+
21+
levels = [Level(A)]
22+
23+
while length(levels) < max_levels && size(levels[end].A, 1)
24+
extend_heirarchy!(levels, strength, CF, A)
25+
end
26+
end
27+
28+
function extend_heirarchy!(levels::Vector{Level}, strength, CF, A)
29+
30+
S = strength_of_connection(strength, A)
31+
splitting = split_nodes(CF, S)
32+
P = direct_interpolation(A, S, splitting)
33+
end

src/multilevel.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct Level{Ti,Tv}
2+
A::SparseMatrixCSC{Ti,Tv}
3+
end

src/splitting.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const F_NODE = 0
22
const C_NODE = 1
33
const U_NODE = 2
44

5-
function RS(S::SparseMatrixCSC)
5+
struct RS
6+
end
7+
8+
split_nodes(::RS, S::SparseMatrixCSC) = RS_CF_splitting(S - spdiagm(diag(S)))
9+
function RS_CF_splitting(S::SparseMatrixCSC)
610

711
m,n = size(S)
812

src/strength.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
function classical(A::SparseMatrixCSC, θ::Float64)
1+
abstract type Strength end
2+
struct Classical{T} <: Strength
3+
θ::T
4+
end
5+
6+
function strength_of_connection{T}(c::Classical{T}, A::SparseMatrixCSC)
27

8+
θ = c.θ
39
I = Int[]
410
J = Int[]
511
V = Float64[]

test/runtests.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ using Base.Test
33

44
# classical strength of connection
55
A = poisson(5)
6-
@test full(classical(A, 0.2)) == [ 1.0 0.5 0.0 0.0 0.0
7-
0.5 1.0 0.5 0.0 0.0
8-
0.0 0.5 1.0 0.5 0.0
9-
0.0 0.0 0.5 1.0 0.5
10-
0.0 0.0 0.0 0.5 1.0 ]
6+
X = strength_of_connection(Classical(0.2), A)
7+
@test full(X) == [ 1.0 0.5 0.0 0.0 0.0
8+
0.5 1.0 0.5 0.0 0.0
9+
0.0 0.5 1.0 0.5 0.0
10+
0.0 0.0 0.5 1.0 0.5
11+
0.0 0.0 0.0 0.5 1.0 ]
1112

1213
# Ruge-Stuben splitting
1314
S = poisson(7)
14-
S = S - spdiagm(diag(S)) #FIXME
15-
@test RS(S) == [0, 1, 0, 1, 0, 1, 0]
15+
# S = S - spdiagm(diag(S)) #FIXME
16+
@test split_nodes(RS(), S) == [0, 1, 0, 1, 0, 1, 0]
1617

1718
srand(0)
1819
S = sprand(10,10,0.1); S = S + S'
19-
S = S - spdiagm(diag(S))
20-
@test RS(S) == [0, 1, 1, 0, 0, 0, 0, 0, 1, 1]
20+
@test split_nodes(RS(), S) == [0, 1, 1, 0, 0, 0, 0, 0, 1, 1]

0 commit comments

Comments
 (0)