@@ -52,6 +52,12 @@ function coarse_b!(m::MultiLevelWorkspace{TX, bs}, n) where {TX, bs}
5252end
5353
5454abstract type CoarseSolver end
55+
56+ """
57+ Pinv{T} <: CoarseSolver
58+
59+ Moore-Penrose pseudo inverse coarse solver. Calls `pinv`
60+ """
5561struct Pinv{T} <: CoarseSolver
5662 pinvA:: Matrix{T}
5763 Pinv {T} (A) where T = new {T} (pinv (Matrix (A)))
@@ -61,6 +67,43 @@ Base.show(io::IO, p::Pinv) = print(io, "Pinv")
6167
6268(p:: Pinv )(x, b) = mul! (x, p. pinvA, b)
6369
70+ # This one is used internally.
71+ """
72+ LinearSolveWrapperInternal <: CoarseSolver
73+
74+ Helper to allow the usage of LinearSolve.jl solvers for the coarse-level solve. Constructed via `LinearSolveWrapper`.
75+ """
76+ struct LinearSolveWrapperInternal{LC <: LinearSolve.LinearCache } <: CoarseSolver
77+ linsolve:: LC
78+ function LinearSolveWrapperInternal (A, alg:: LinearSolve.SciMLLinearSolveAlgorithm )
79+ rhs_tmp = zeros (eltype (A), size (A,1 ))
80+ u_tmp = zeros (eltype (A), size (A,2 ))
81+ linprob = LinearProblem (A, rhs_tmp; u0 = u_tmp, alias_A = false , alias_b = false )
82+ linsolve = init (linprob, alg)
83+ new {typeof(linsolve)} (linsolve)
84+ end
85+ end
86+
87+ function (p:: LinearSolveWrapperInternal{LC} )(x, b) where {LC <: LinearSolve.LinearCache }
88+ for i ∈ 1 : size (b, 2 )
89+ # Update right hand side
90+ p. linsolve. b = b[:, i]
91+ # Solve for x and update
92+ x[:, i] = solve! (p. linsolve). u
93+ end
94+ end
95+
96+ # This one simplifies passing of LinearSolve.jl algorithms into AlgebraicMultigrid.jl as coarse solvers.
97+ """
98+ LinearSolveWrapper <: CoarseSolver
99+
100+ Helper to allow the usage of LinearSolve.jl solvers for the coarse-level solve.
101+ """
102+ struct LinearSolveWrapper <: CoarseSolver
103+ alg:: LinearSolve.SciMLLinearSolveAlgorithm
104+ end
105+ (p:: LinearSolveWrapper )(A:: AbstractMatrix ) = LinearSolveWrapperInternal (A, p. alg)
106+
64107Base. length (ml:: MultiLevel ) = length (ml. levels) + 1
65108
66109function Base. show (io:: IO , ml:: MultiLevel )
0 commit comments