Skip to content

Commit b5d6fbf

Browse files
Hotfix and add tests for default linear solver issues found in ODE
Tested locally
1 parent 65a6222 commit b5d6fbf

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LinearSolve"
22
uuid = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
33
authors = ["SciML"]
4-
version = "2.1.2"
4+
version = "2.1.3"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/default.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ defaultalg(A, b) = defaultalg(A, b, OperatorAssumptions(true))
2525

2626
function defaultalg(A::Union{DiffEqArrayOperator, MatrixOperator}, b,
2727
assump::OperatorAssumptions)
28-
DefaultLinearSolver(defaultalg(A.A, b, assump))
28+
defaultalg(A.A, b, assump)
2929
end
3030

3131
function defaultalg(A, b, assump::OperatorAssumptions{Nothing})
3232
issq = issquare(A)
33-
DefaultLinearSolver(defaultalg(A, b, OperatorAssumptions(issq, assump.condition)))
33+
defaultalg(A, b, OperatorAssumptions(issq, assump.condition))
3434
end
3535

3636
function defaultalg(A::Tridiagonal, b, assump::OperatorAssumptions)

src/iterative_wrappers.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ function get_KrylovJL_solver(KrylovAlg)
161161
Krylov.GpmrSolver
162162
elseif (KrylovAlg === Krylov.fom!)
163163
Krylov.FomSolver
164+
else
165+
error("Invalid Krylov method detected")
164166
end
165167

166168
return KS
@@ -241,7 +243,7 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
241243
itmax = cache.maxiters
242244
verbose = cache.verbose ? 1 : 0
243245

244-
args = (cache.cacheval, cache.A, cache.b)
246+
args = (@get_cacheval(cache, :KrylovJL_GMRES), cache.A, cache.b)
245247
kwargs = (atol = atol, rtol = rtol, itmax = itmax, verbose = verbose,
246248
ldiv = true, history = true, alg.kwargs...)
247249

test/basictests.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ end
403403
end
404404

405405
@testset "DirectLdiv!" begin
406-
function get_operator(A, u)
406+
function get_operator(A, u; add_inverse = true)
407407
function f(du, u, p, t)
408408
println("using FunctionOperator mul!")
409409
mul!(du, A, u)
@@ -414,22 +414,35 @@ end
414414
ldiv!(du, A, u)
415415
end
416416

417-
FunctionOperator(f, u, u; isinplace = true, op_inverse = fi)
417+
if add_inverse
418+
FunctionOperator(f, u, u; isinplace = true, op_inverse = fi)
419+
else
420+
FunctionOperator(f, u, u; isinplace = true)
421+
end
418422
end
419423

420424
op1 = get_operator(A1, x1 * 0)
421425
op2 = get_operator(A2, x2 * 0)
426+
op3 = get_operator(A1, x1 * 0; add_inverse = false)
427+
op4 = get_operator(A2, x2 * 0; add_inverse = false)
422428

423429
prob1 = LinearProblem(op1, b1; u0 = x1)
424430
prob2 = LinearProblem(op2, b2; u0 = x2)
431+
prob3 = LinearProblem(op1, b1; u0 = x1)
432+
prob4 = LinearProblem(op2, b2; u0 = x2)
425433

426434
@test LinearSolve.defaultalg(op1, x1).alg ===
427435
LinearSolve.DefaultAlgorithmChoice.DirectLdiv!
428436
@test LinearSolve.defaultalg(op2, x2).alg ===
429437
LinearSolve.DefaultAlgorithmChoice.DirectLdiv!
430-
438+
@test LinearSolve.defaultalg(op3, x1).alg ===
439+
LinearSolve.DefaultAlgorithmChoice.KrylovJL_GMRES
440+
@test LinearSolve.defaultalg(op4, x2).alg ===
441+
LinearSolve.DefaultAlgorithmChoice.KrylovJL_GMRES
431442
test_interface(DirectLdiv!(), prob1, prob2)
432443
test_interface(nothing, prob1, prob2)
444+
test_interface(KrylovJL_GMRES(), prob3, prob4)
445+
test_interface(nothing, prob3, prob4)
433446
end
434447
end
435448
end # testset

0 commit comments

Comments
 (0)