From ef43d1bded7dc95e4d3537f7fba6102231d66d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Wed, 20 Nov 2024 14:05:49 +0100 Subject: [PATCH] Linear solver cleanup --- src/linsolve/krylov.jl | 7 +++---- src/linsolve/precond/ilu.jl | 10 +++++----- src/linsolve/precond/utils.jl | 16 +++++++--------- src/linsolve/precond/various.jl | 4 +++- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/linsolve/krylov.jl b/src/linsolve/krylov.jl index 86ee33cd..95a65c60 100644 --- a/src/linsolve/krylov.jl +++ b/src/linsolve/krylov.jl @@ -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 @@ -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 diff --git a/src/linsolve/precond/ilu.jl b/src/linsolve/precond/ilu.jl index d96a9326..b244a88b 100644 --- a/src/linsolve/precond/ilu.jl +++ b/src/linsolve/precond/ilu.jl @@ -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) @@ -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) diff --git a/src/linsolve/precond/utils.jl b/src/linsolve/precond/utils.jl index ad3db115..4bb569f9 100644 --- a/src/linsolve/precond/utils.jl +++ b/src/linsolve/precond/utils.jl @@ -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) @@ -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 diff --git a/src/linsolve/precond/various.jl b/src/linsolve/precond/various.jl index d91232df..bb965c59 100644 --- a/src/linsolve/precond/various.jl +++ b/src/linsolve/precond/various.jl @@ -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