Skip to content

Commit db32186

Browse files
authored
Merge pull request #28 from ranjanan/relax
Relax B, add a test for symmetric sweep
2 parents 037e074 + ec0a4d9 commit db32186

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/aggregation.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function extend_hierarchy!(levels, strength, aggregate, smooth,
6161
# b = zeros(eltype(A), size(A, 1))
6262

6363
# Improve candidates
64-
# relax!(improve_candidates, A, B, b)
64+
b = zeros(size(A,1))
65+
relax!(improve_candidates, A, B, b)
6566
T, B = fit_candidates(AggOp, B)
6667

6768
P = smooth_prolongator(smooth, A, T, S, B)
@@ -86,7 +87,6 @@ function fit_candidates(AggOp, B, tol = 1e-10)
8687

8788
R = zeros(eltype(B), n_coarse)
8889
Qx = zeros(eltype(B), nnz(A))
89-
9090
# copy!(Qx, B)
9191
for i = 1:size(Qx, 1)
9292
Qx[i] = B[i]
@@ -125,7 +125,11 @@ end
125125
function norm_col(A, Qx, i)
126126
s = zero(eltype(A))
127127
for j in nzrange(A, i)
128-
val = Qx[A.rowval[j]]
128+
if A.rowval[j] > length(Qx)
129+
val = 1
130+
else
131+
val = Qx[A.rowval[j]]
132+
end
129133
# val = A.nzval[A.rowval[j]]
130134
s += val*val
131135
end

src/smoother.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ end
1313
GaussSeidel(iter = 1) = GaussSeidel(SymmetricSweep(), iter)
1414
GaussSeidel(f::ForwardSweep) = GaussSeidel(f, 1)
1515
GaussSeidel(b::BackwardSweep) = GaussSeidel(b, 1)
16+
GaussSeidel(s::SymmetricSweep) = GaussSeidel(s, 1)
1617

1718
presmoother!(s, A, x, b) = smoother!(s, s.sweep, A, x, b)
1819
postsmoother!(s, A, x, b) = smoother!(s, s.sweep, A, x, b)
@@ -26,8 +27,8 @@ end
2627

2728
function smoother!(s::GaussSeidel, ::SymmetricSweep, A, x, b)
2829
for i in 1:s.iter
29-
smoother!(s, ForwardSweep(), A, x, b)
30-
smoother!(s, BackwardSweep(), A, x, b)
30+
gs!(A, b, x, 1, 1, size(A, 1))
31+
gs!(A, b, x, size(A,1), -1, 1)
3132
end
3233
end
3334

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,7 @@ end
268268

269269
# Issue #24
270270
nodes_not_agg()
271+
272+
# Issue 26
273+
test_symmetric_sweep()
271274
end

test/sa_tests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,18 @@ function nodes_not_agg()
320320
@test size(ml.levels[2].A) == (11,11)
321321
@test size(ml.final_A) == (2,2)
322322
end
323+
324+
# Issue 26
325+
import AMG: relax!
326+
function test_symmetric_sweep()
327+
A = poisson(10)
328+
s = GaussSeidel(SymmetricSweep(), 4)
329+
x = ones(size(A,1))
330+
b = zeros(size(A,1))
331+
relax!(s, A, x, b)
332+
@test sum(abs2, x - [0.176765; 0.353529; 0.497517; 0.598914;
333+
0.653311; 0.659104; 0.615597; 0.52275;
334+
0.382787; 0.203251]) < 1e-6
335+
336+
end
337+

0 commit comments

Comments
 (0)