Skip to content

Commit

Permalink
Linear solver cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
moyner committed Nov 20, 2024
1 parent 5ed66b0 commit ef43d1b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/linsolve/krylov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ function Base.show(io::IO, krylov::GenericKrylov)
print(io, "Generic Krylov using $(krylov.solver) (ϵₐ=$atol, ϵ=$rtol) with prec = $(typeof(krylov.preconditioner))")
end

function preconditioner(krylov::AbstractKrylov, sys, context, model, storage, recorder, side, arg...)
function preconditioner(krylov::AbstractKrylov, sys, context, model, storage, recorder)
M = krylov.preconditioner
Ft = float_type(context)
if isnothing(M)
op = I
else
linop = linear_operator(M, side, Ft, sys, context, model, storage, recorder, arg...)
linop = linear_operator(M, Ft, sys, context, model, storage, recorder)
op = PrecondWrapper(linop)
end
return op
Expand Down Expand Up @@ -95,8 +95,7 @@ function linear_solve!(sys::LSystem,
t_prep = @elapsed @tic "prepare" prepare_linear_solve!(sys)
op = linear_operator(sys)
t_prec = @elapsed @tic "precond" update_preconditioner!(prec, sys, context, model, storage, recorder, executor)
prec_op = preconditioner(krylov, sys, context, model, storage, recorder, :left)
# R = preconditioner(krylov, sys, model, storage, recorder, :right, Ft)
prec_op = preconditioner(krylov, sys, context, model, storage, recorder)
v = Int64(cfg.verbose)
max_it = cfg.max_iterations
min_it = cfg.min_iterations
Expand Down
10 changes: 5 additions & 5 deletions src/linsolve/precond/ilu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ function update_preconditioner!(ilu::ILUZeroPreconditioner, A::StaticSparsityMat
end
end

function apply!(x, ilu::ILUZeroPreconditioner, y, type, arg...)
function apply!(x, ilu::ILUZeroPreconditioner, y)
factor = get_factorization(ilu)
ilu_apply!(x, factor, y, arg...)
ilu_apply!(x, factor, y)
end

function ilu_apply!(x::AbstractArray{F}, f::AbstractILUFactorization, y::AbstractArray{F}, args...) where {F<:Real}
function ilu_apply!(x::AbstractArray{F}, f::AbstractILUFactorization, y::AbstractArray{F}) where {F<:Real}
T = eltype(f)
if T == Float64
ldiv!(x, f, y)
Expand All @@ -78,11 +78,11 @@ function ilu_apply!(x, f::AbstractILUFactorization, y)
ldiv!(x, f, y)
end

function ilu_apply!(x::AbstractArray{F}, f::ILU0Precon{F}, y::AbstractArray{F}, args...) where {F<:Real}
function ilu_apply!(x::AbstractArray{F}, f::ILU0Precon{F}, y::AbstractArray{F}) where {F<:Real}
ldiv!(x, f, y)
end

function ilu_apply!(x, ilu::ILU0Precon, y,args...)
function ilu_apply!(x, ilu::ILU0Precon, y)
T = eltype(ilu.l_nzval)
N = size(T, 1)
T = eltype(T)
Expand Down
16 changes: 7 additions & 9 deletions src/linsolve/precond/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ end
is_left_preconditioner(::JutulPreconditioner) = true
is_right_preconditioner(::JutulPreconditioner) = false

function linear_operator(precond::JutulPreconditioner, side::Symbol = :left, float_t = Float64)
function linear_operator(precond::JutulPreconditioner)
return linear_operator(precond, Float64, nothing, nothing, nothing, nothing, nothing)
end

function linear_operator(precond::JutulPreconditioner, float_t, sys, context, model, storage, recorder)
n = operator_nrows(precond)
function precond_apply!(res, x, α, β::T) where T
if β == zero(T)
Expand All @@ -35,13 +39,7 @@ function linear_operator(precond::JutulPreconditioner, side::Symbol = :left, flo
end

#nead to be spesilized on type not all JutulPreconditioners has get_factor
function apply!(x, p::JutulPreconditioner, y, arg...)
function apply!(x, p::JutulPreconditioner, y)
factor = get_factorization(p)
if is_left_preconditioner(p)
ldiv!(x, factor, y)
elseif is_right_preconditioner(p)
error("Not supported.")
else
error("Neither left or right preconditioner?")
end
ldiv!(x, factor, y)
end
4 changes: 3 additions & 1 deletion src/linsolve/precond/various.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ function update_preconditioner!(tp::TrivialPreconditioner, lsys, model, storage,
b = residual(lsys)
tp.dim = size(A).*length(b[1])
end

export linear_operator
function linear_operator(id::TrivialPreconditioner, ::Symbol, args...)

function linear_operator(id::TrivialPreconditioner, args...)
return opEye(id.dim...)
end

Expand Down

0 comments on commit ef43d1b

Please sign in to comment.