Skip to content

Commit d8c101d

Browse files
committed
Add NewtonRaphson in FdeSolver
1 parent f8bdf65 commit d8c101d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

ext/FractionalDiffEqFdeSolverExt.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function SciMLBase.__solve(prob::FODEProblem, alg::FdeSolverPECE; dt = 0.0, abst
88
(; f, order, tspan, u0, p) = prob
99

1010
iip = isinplace(prob)
11-
1211
tSpan = [first(tspan), last(tspan)]
1312
# FdeSolver only supports out-of-place computing
1413
newf = if iip
@@ -22,9 +21,26 @@ function SciMLBase.__solve(prob::FODEProblem, alg::FdeSolverPECE; dt = 0.0, abst
2221
return f.(y, par, t)
2322
end
2423
end
24+
25+
jacob_f = if !isnothing(prob.f.jac)
26+
if iip
27+
function (t, y, par)
28+
J = similar(y, length(y), length(y))
29+
prob.f.jac(J, u, par, t)
30+
return J
31+
end
32+
else
33+
function (t, y, par)
34+
prob.f.jac(y, par, t)
35+
end
36+
end
37+
else
38+
nothing
39+
end
40+
2541
par = p isa SciMLBase.NullParameters ? nothing : p
2642
length(u0) == 1 && (u0 = first(u0))
27-
t, y = FDEsolver(newf, tSpan, u0, order, par, JF = prob.f.jac, h = dt, tol = abstol)
43+
t, y = FDEsolver(newf, tSpan, u0, order, par, JF = jacob_f, h = dt, tol = abstol)
2844
u = collect(Vector{eltype(y)}, eachrow(y))
2945

3046
return DiffEqBase.build_solution(prob, alg, t, u)

0 commit comments

Comments
 (0)