Skip to content

Commit

Permalink
Properly support scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal authored and ChrisRackauckas committed Dec 24, 2023
1 parent b71dc6b commit 883d752
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Sundials"
uuid = "c3572dad-4567-51f8-b174-8c6c989267f4"
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
version = "4.23.0"
version = "4.23.1"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
2 changes: 1 addition & 1 deletion src/common_interface/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Abstract Types
abstract type SundialsODEAlgorithm{Method, LinearSolver} <: DiffEqBase.AbstractODEAlgorithm end
abstract type SundialsDAEAlgorithm{LinearSolver} <: DiffEqBase.AbstractDAEAlgorithm end
abstract type SundialsNonlinearSolveAlgorithm{LinearSolver} end
abstract type SundialsNonlinearSolveAlgorithm{LinearSolver} <: SciMLBase.AbstractNonlinearAlgorithm end

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

Expand Down
6 changes: 5 additions & 1 deletion src/common_interface/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function DiffEqBase.__solve(prob::Union{

f!(resid, u)
retcode = interpret_sundials_retcode(flag)
DiffEqBase.build_solution(prob, alg, u, resid; retcode = retcode)
if prob.u0 isa Number
DiffEqBase.build_solution(prob, alg, u[1], resid[1]; retcode = retcode)
else
DiffEqBase.build_solution(prob, alg, u, resid; retcode = retcode)
end
end

function DiffEqBase.__init(prob::DiffEqBase.AbstractODEProblem{uType, tupType, isinplace},
Expand Down
17 changes: 17 additions & 0 deletions test/kinsol_nonlinear_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ prob_oop = NonlinearProblem{false}(f_oop, u0)
f_oop(sol.u, nothing)
@test maximum(abs, du) < 1e-6
end

# Scalar
f_scalar(u, p) = 2 - 2u
u0 = 0.0
prob_scalar = NonlinearProblem{false}(f_scalar, u0)

@testset "linear_solver = $(linear_solver) | globalization_strategy = $(globalization_strategy)" for linear_solver in (:Dense,
:LapackDense, :GMRES, :FGMRES, :PCG, :TFQMR), globalization_strategy in (:LineSearch, :None)
local sol
alg = KINSOL(; linear_solver, globalization_strategy)
sol = solve(prob_scalar, alg; abstol)
@test SciMLBase.successful_retcode(sol.retcode)
@test sol.u isa Number

resid = f_scalar(sol.u, nothing)
@test abs(resid) < 1e-6
end

2 comments on commit 883d752

@avik-pal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/97703

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v4.23.1 -m "<description of version>" 883d752bd07754d259d0e447a0f9ed52c30cf4c3
git push origin v4.23.1

Please sign in to comment.