Skip to content

Commit 90e9825

Browse files
Use QR as the default solver
1 parent 251c0d5 commit 90e9825

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/coarse_solver.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@ struct LinearSolveWrapper{A <: LinearSolve.SciMLLinearSolveAlgorithm} <: CoarseS
5757
end
5858
(p::LinearSolveWrapper)(A::AbstractMatrix) = LinearSolveWrapperInternal(A, p.alg)
5959

60+
61+
"""
62+
QRSolver{F} <: CoarseSolver
63+
64+
Coarse solver using Julia's built-in factorizations via `qr()`.
65+
"""
66+
struct QRSolver{F} <: CoarseSolver
67+
factorization::F
68+
function QRSolver(A)
69+
fact = qr(A)
70+
new{typeof(fact)}(fact)
71+
end
72+
end
73+
Base.show(io::IO, p::QRSolver) = print(io, "QRSolver")
74+
75+
function (solver::QRSolver)(x, b)
76+
# Handle multiple RHS efficiently
77+
for i 1:size(b, 2)
78+
# Use backslash - Julia's factorizations are optimized for this
79+
x[:, i] = solver.factorization \ b[:, i]
80+
end
81+
end
82+
6083
# Guess the best coarse solver based on the matrix type
61-
_default_coarse_solver(A) = Pinv
62-
_default_coarse_solver(A::AbstractSparseMatrix{<:Float64}) = LinearSolveWrapper(LinearSolve.UMFPACKFactorization())
84+
_default_coarse_solver(A) = QRSolver

0 commit comments

Comments
 (0)