I’m playing around with https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl and would like to write my own smoother, or even just use the Jacobi smoother which is in the package, but not the default. Unfortunately, I am still very new to Julia and I still don’t understand how or why they’ve set up the smoothers the way they have. Here’s how they have defined the Jacobi smoother
abstract type Smoother end
struct Jacobi{T,TX} <: Smoother
ω::T
temp::TX
iter::Int
end
Jacobi(ω, x::TX; iter=1) where {T, TX<:AbstractArray{T}} = Jacobi{T,TX}(ω, similar(x), iter)
Jacobi(x::TX, ω=0.5; iter=1) where {T, TX<:AbstractArray{T}} = Jacobi{T,TX}(ω, similar(x), iter)
function (jacobi::Jacobi)(A, x, b)
...
end
What is the advantage of defining a Smoother
type instead of allowing any function?
When I tried to use Jacobi as the smoother
ruge_stuben(A,
presmoother = Jacobi(1, Array{Float64,1}, 1),
postsmoother = Jacobi(1, Array{Float64,1}, 1))
I get an error, MethodError: no method matching setindex!(::Type{Array{Float64,1}}, ::Float64, ::Int64, ::Int64)
.
Some assistance and background explaining why this is a good way to set up functions in Julia would be helpful!