Skip to content

Commit

Permalink
feat: forwarddiff support for sundials
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 22, 2024
1 parent f5a06cb commit 3ded2fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ NLSolvers = "337daf1e-9722-11e9-073e-8b9effe078ba"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
SIAMFANLEquations = "084e46ad-d928-497d-ad5e-07fa361a48c4"
SpeedMapping = "f1835b91-879b-4a3f-a438-e4baacf14412"
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"

[extensions]
NonlinearSolveBandedMatricesExt = "BandedMatrices"
Expand All @@ -55,6 +56,7 @@ NonlinearSolveNLSolversExt = "NLSolvers"
NonlinearSolveNLsolveExt = ["NLsolve", "LineSearches"]
NonlinearSolveSIAMFANLEquationsExt = "SIAMFANLEquations"
NonlinearSolveSpeedMappingExt = "SpeedMapping"
NonlinearSolveSundialsExt = "Sundials"

[compat]
ADTypes = "1.9"
Expand Down
16 changes: 16 additions & 0 deletions ext/NonlinearSolveSundialsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module NonlinearSolveSundialsExt

using NonlinearSolveBase: NonlinearSolveBase, nonlinearsolve_forwarddiff_solve,
nonlinearsolve_dual_solution
using NonlinearSolve: DualNonlinearProblem
using SciMLBase: SciMLBase
using Sundials: KINSOL

function SciMLBase.__solve(prob::DualNonlinearProblem, alg::KINSOL, args...; kwargs...)
sol, partials = nonlinearsolve_forwarddiff_solve(prob, alg, args...; kwargs...)
dual_soln = nonlinearsolve_dual_solution(sol.u, partials, prob.p)
return SciMLBase.build_solution(
prob, alg, dual_soln, sol.resid; sol.retcode, sol.stats, sol.original)
end

end

0 comments on commit 3ded2fa

Please sign in to comment.