Skip to content

Commit 3ded2fa

Browse files
committed
feat: forwarddiff support for sundials
1 parent f5a06cb commit 3ded2fa

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ NLSolvers = "337daf1e-9722-11e9-073e-8b9effe078ba"
4444
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
4545
SIAMFANLEquations = "084e46ad-d928-497d-ad5e-07fa361a48c4"
4646
SpeedMapping = "f1835b91-879b-4a3f-a438-e4baacf14412"
47+
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
4748

4849
[extensions]
4950
NonlinearSolveBandedMatricesExt = "BandedMatrices"
@@ -55,6 +56,7 @@ NonlinearSolveNLSolversExt = "NLSolvers"
5556
NonlinearSolveNLsolveExt = ["NLsolve", "LineSearches"]
5657
NonlinearSolveSIAMFANLEquationsExt = "SIAMFANLEquations"
5758
NonlinearSolveSpeedMappingExt = "SpeedMapping"
59+
NonlinearSolveSundialsExt = "Sundials"
5860

5961
[compat]
6062
ADTypes = "1.9"

ext/NonlinearSolveSundialsExt.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module NonlinearSolveSundialsExt
2+
3+
using NonlinearSolveBase: NonlinearSolveBase, nonlinearsolve_forwarddiff_solve,
4+
nonlinearsolve_dual_solution
5+
using NonlinearSolve: DualNonlinearProblem
6+
using SciMLBase: SciMLBase
7+
using Sundials: KINSOL
8+
9+
function SciMLBase.__solve(prob::DualNonlinearProblem, alg::KINSOL, args...; kwargs...)
10+
sol, partials = nonlinearsolve_forwarddiff_solve(prob, alg, args...; kwargs...)
11+
dual_soln = nonlinearsolve_dual_solution(sol.u, partials, prob.p)
12+
return SciMLBase.build_solution(
13+
prob, alg, dual_soln, sol.resid; sol.retcode, sol.stats, sol.original)
14+
end
15+
16+
end

0 commit comments

Comments
 (0)