|
1 |
| -struct Preconditioner |
2 |
| - ml::MultiLevel |
| 1 | +struct Preconditioner{ML<:MultiLevel} |
| 2 | + ml::ML |
| 3 | + init::Symbol |
3 | 4 | end
|
| 5 | +Preconditioner(ml) = Preconditioner(ml, :zero) |
4 | 6 |
|
5 | 7 | aspreconditioner(ml::MultiLevel) = Preconditioner(ml)
|
6 | 8 |
|
7 | 9 | @static if VERSION < v"0.7-"
|
8 | 10 | import Base: \, *, A_ldiv_B!, A_mul_B!
|
9 |
| - A_ldiv_B!(x, p::Preconditioner, b) = copyto!(x, p \ b) |
| 11 | + function A_ldiv_B!(x, p::Preconditioner, b) |
| 12 | + if p.init == :zero |
| 13 | + x .= 0 |
| 14 | + else |
| 15 | + x .= b |
| 16 | + end |
| 17 | + solve!(x, p.ml, b, maxiter = 1, calculate_residual = false) |
| 18 | + end |
10 | 19 | A_mul_B!(b, p::Preconditioner, x) = A_mul_B!(b, p.ml.levels[1].A, x)
|
11 | 20 | else
|
12 | 21 | import Compat.LinearAlgebra: \, *, ldiv!, mul!
|
13 | 22 | ldiv!(p::Preconditioner, b) = copyto!(b, p \ b)
|
14 |
| - ldiv!(x, p::Preconditioner, b) = copyto!(x, p \ b) |
| 23 | + function ldiv!(x, p::Preconditioner, b) |
| 24 | + if p.init == :zero |
| 25 | + x .= 0 |
| 26 | + else |
| 27 | + x .= b |
| 28 | + end |
| 29 | + solve!(x, p.ml, b, maxiter = 1, calculate_residual = false) |
| 30 | + end |
15 | 31 | mul!(b, p::Preconditioner, x) = mul!(b, p.ml.levels[1].A, x)
|
16 | 32 | end
|
17 | 33 |
|
18 |
| -\(p::Preconditioner, b) = solve(p.ml, b, maxiter = 1, calculate_residual = false) |
| 34 | +function \(p::Preconditioner, b) |
| 35 | + if p.init == :zero |
| 36 | + x = zeros(b) |
| 37 | + else |
| 38 | + x = copy(b) |
| 39 | + end |
| 40 | + solve!(x, p.ml, b) |
| 41 | +end |
19 | 42 | *(p::Preconditioner, b) = p.ml.levels[1].A * x
|
0 commit comments