Skip to content

Commit c83c21b

Browse files
authored
Merge pull request #34 from ranjanan/kw
Clean up `solve` API
2 parents c72c8bb + 58b1bb7 commit c83c21b

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/multilevel.jl

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,31 @@ abstract type Cycle end
6060
struct V <: Cycle
6161
end
6262

63+
"""
64+
solve(ml::MultiLevel, b::Vector, cycle, kwargs...)
65+
66+
Execute multigrid cycling.
67+
68+
Arguments
69+
=========
70+
* ml::MultiLevel - the multigrid hierarchy
71+
* b::Vector - the right hand side
72+
* cycle - multigird cycle to execute at each iteration. Defaults to AMG.V()
73+
74+
Keyword Arguments
75+
=================
76+
* tol::Float64 - tolerance criteria for convergence
77+
* maxiter::Int64 - maximum number of iterations to execute
78+
* verbose::Bool - display residual at each iteration
79+
* log::Bool - return vector of residuals along with solution
80+
81+
"""
6382
function solve{T}(ml::MultiLevel, b::Vector{T},
64-
maxiter = 100,
65-
cycle = V(),
66-
tol = 1e-5;
67-
verbose = false,
68-
log = false)
83+
cycle::Cycle = V();
84+
maxiter::Int = 100,
85+
tol::Float64 = 1e-5,
86+
verbose::Bool = false,
87+
log::Bool = false)
6988

7089
A = length(ml) == 1 ? ml.final_A : ml.levels[1].A
7190
V = promote_type(eltype(A), eltype(b))

src/preconditioner.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ end
66

77
aspreconditioner(ml::MultiLevel) = Preconditioner(ml)
88

9-
\(p::Preconditioner, b) = solve(p.ml, b, 1, V(), 1e-12)
9+
\(p::Preconditioner, b) = solve(p.ml, b, maxiter = 1, tol = 1e-12)
1010
*(p::Preconditioner, b) = p.ml.levels[1].A * x
1111

1212
A_ldiv_B!(x, p::Preconditioner, b) = copy!(x, p \ b)

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ p = aspreconditioner(ml)
146146
b = zeros(n)
147147
b[1] = 1
148148
b[2] = -1
149-
x = solve(p.ml, A * ones(n), 1, V(), 1e-12)
149+
x = solve(p.ml, A * ones(n), maxiter = 1, tol = 1e-12)
150150
diff = x - [ 1.88664780e-16, 2.34982727e-16, 2.33917697e-16,
151151
8.77869044e-17, 7.16783490e-17, 1.43415460e-16,
152152
3.69199021e-17, 9.70950385e-17, 4.77034895e-17,
@@ -164,7 +164,7 @@ diff = x - [ 1.88664780e-16, 2.34982727e-16, 2.33917697e-16,
164164
-6.76965535e-16, -7.00643227e-16, -6.23581397e-16,
165165
-7.03016682e-16]
166166
@test sum(abs2, diff) < 1e-8
167-
x = solve(p.ml, b, 1, V(), 1e-12)
167+
x = solve(p.ml, b, maxiter = 1, tol = 1e-12)
168168
diff = x - [ 0.76347046, -0.5498286 , -0.2705487 , -0.15047352, -0.10248021,
169169
0.60292674, -0.11497073, -0.08460548, -0.06931461, 0.38230708,
170170
-0.055664 , -0.04854558, -0.04577031, 0.09964325, 0.01825624,
@@ -205,7 +205,7 @@ diff = x - [0.823762, -0.537478, -0.306212, -0.19359, -0.147621, 0.685002,
205205
0.0511691, 0.0502043, 0.0498349, 0.0498134]
206206
@test sum(abs2, diff) < 1e-8
207207

208-
x = solve(ml, b, 1, V(), 1e-12)
208+
x = solve(ml, b, maxiter = 1, tol = 1e-12)
209209
diff = x - [0.775725, -0.571202, -0.290989, -0.157001, -0.106981, 0.622652,
210210
-0.122318, -0.0891874, -0.0709834, 0.392621, -0.055544, -0.0507485,
211211
-0.0466376, 0.107175, 0.0267468, -0.0200843, -0.0282827, -0.0299929,

0 commit comments

Comments
 (0)