Skip to content

Commit 883d752

Browse files
avik-palChrisRackauckas
authored andcommitted
Properly support scalars
1 parent b71dc6b commit 883d752

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Sundials"
22
uuid = "c3572dad-4567-51f8-b174-8c6c989267f4"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "4.23.0"
4+
version = "4.23.1"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"

src/common_interface/algorithms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Abstract Types
44
abstract type SundialsODEAlgorithm{Method, LinearSolver} <: DiffEqBase.AbstractODEAlgorithm end
55
abstract type SundialsDAEAlgorithm{LinearSolver} <: DiffEqBase.AbstractDAEAlgorithm end
6-
abstract type SundialsNonlinearSolveAlgorithm{LinearSolver} end
6+
abstract type SundialsNonlinearSolveAlgorithm{LinearSolver} <: SciMLBase.AbstractNonlinearAlgorithm end
77

88
SciMLBase.alg_order(alg::Union{SundialsODEAlgorithm, SundialsDAEAlgorithm}) = alg.max_order
99

src/common_interface/solve.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ function DiffEqBase.__solve(prob::Union{
8080

8181
f!(resid, u)
8282
retcode = interpret_sundials_retcode(flag)
83-
DiffEqBase.build_solution(prob, alg, u, resid; retcode = retcode)
83+
if prob.u0 isa Number
84+
DiffEqBase.build_solution(prob, alg, u[1], resid[1]; retcode = retcode)
85+
else
86+
DiffEqBase.build_solution(prob, alg, u, resid; retcode = retcode)
87+
end
8488
end
8589

8690
function DiffEqBase.__init(prob::DiffEqBase.AbstractODEProblem{uType, tupType, isinplace},

test/kinsol_nonlinear_solve.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,20 @@ prob_oop = NonlinearProblem{false}(f_oop, u0)
3737
f_oop(sol.u, nothing)
3838
@test maximum(abs, du) < 1e-6
3939
end
40+
41+
# Scalar
42+
f_scalar(u, p) = 2 - 2u
43+
u0 = 0.0
44+
prob_scalar = NonlinearProblem{false}(f_scalar, u0)
45+
46+
@testset "linear_solver = $(linear_solver) | globalization_strategy = $(globalization_strategy)" for linear_solver in (:Dense,
47+
:LapackDense, :GMRES, :FGMRES, :PCG, :TFQMR), globalization_strategy in (:LineSearch, :None)
48+
local sol
49+
alg = KINSOL(; linear_solver, globalization_strategy)
50+
sol = solve(prob_scalar, alg; abstol)
51+
@test SciMLBase.successful_retcode(sol.retcode)
52+
@test sol.u isa Number
53+
54+
resid = f_scalar(sol.u, nothing)
55+
@test abs(resid) < 1e-6
56+
end

0 commit comments

Comments
 (0)