diff --git a/Project.toml b/Project.toml index 8841eca18..63df3592a 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -55,6 +56,7 @@ NonlinearSolveNLSolversExt = "NLSolvers" NonlinearSolveNLsolveExt = ["NLsolve", "LineSearches"] NonlinearSolveSIAMFANLEquationsExt = "SIAMFANLEquations" NonlinearSolveSpeedMappingExt = "SpeedMapping" +NonlinearSolveSundialsExt = "Sundials" [compat] ADTypes = "1.9" diff --git a/ext/NonlinearSolveSundialsExt.jl b/ext/NonlinearSolveSundialsExt.jl new file mode 100644 index 000000000..edea3a49b --- /dev/null +++ b/ext/NonlinearSolveSundialsExt.jl @@ -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