@@ -304,6 +304,7 @@ function potrap_functional_jac!(pb::AbstractPOFDProblem, out, u, par, du)
304
304
end
305
305
306
306
(pb:: PeriodicOrbitTrapProblem )(u:: AbstractVector , par) = potrap_functional! (pb, similar (u), u, par)
307
+ residual (pb:: PeriodicOrbitTrapProblem , u:: AbstractVector , par) = pb (u, par)
307
308
(pb:: PeriodicOrbitTrapProblem )(u:: AbstractVector , par, du) = potrap_functional_jac! (pb, similar (du), u, par, du)
308
309
309
310
# ###################################################################################################
@@ -436,7 +437,7 @@ function (pb::PeriodicOrbitTrapProblem)(::Val{:JacFullSparse}, u0::AbstractVecto
436
437
AγBlock = jacobian_potrap_block (pb, u0, par; γ = γ)
437
438
438
439
# we now set up the last line / column
439
- @views ∂TGpo = (pb ( vcat (u0[begin : end - 1 ], T + δ), par) .- pb ( u0, par)) ./ δ
440
+ @views ∂TGpo = (residual (pb, vcat (u0[begin : end - 1 ], T + δ), par) .- residual (pb, u0, par)) ./ δ
440
441
441
442
# this is "bad" for performance. Get converted to SparseMatrix at the next line
442
443
Aγ = block_to_sparse (AγBlock) # most of the computing time is here!!
@@ -493,7 +494,7 @@ This method returns the jacobian of the functional G encoded in PeriodicOrbitTra
493
494
# J0[(M-1)*N+1:(M)*N, (M-1)*N+1:(M)*N] .= In
494
495
495
496
# we now set up the last line / column
496
- ∂TGpo = (pb ( vcat (u0[1 : end - 1 ], T + δ), par) .- pb ( u0, par)) ./ δ
497
+ ∂TGpo = (residual (pb, vcat (u0[1 : end - 1 ], T + δ), par) .- residual (pb, u0, par)) ./ δ
497
498
J0[:, end ] .= ∂TGpo
498
499
499
500
# this following does not depend on u0, so it does not change. However we update it in case the caller updated the section somewhere else
547
548
548
549
if updateborder
549
550
# we now set up the last line / column
550
- ∂TGpo = (pb ( vcat (u0[1 : end - 1 ], T + δ), par) .- pb ( u0, par)) ./ δ
551
+ ∂TGpo = (residual (pb, vcat (u0[1 : end - 1 ], T + δ), par) .- residual (pb, u0, par)) ./ δ
551
552
J0[:, end ] .= ∂TGpo
552
553
553
554
# this following does not depend on u0, so it does not change. However we update it in case the caller updated the section somewhere else
@@ -776,7 +777,7 @@ function (J::POTrapJacobianBordered)(u0::AbstractVector, par; δ = convert(eltyp
776
777
T = extract_period_fdtrap (J. Aγ. prob, u0)
777
778
# we compute the derivative of the problem w.r.t. the period TODO : remove this or improve!!
778
779
# TODO REMOVE CE vcat!
779
- @views J.∂TGpo .= (J. Aγ. prob ( vcat (u0[begin : end - 1 ], T + δ), par) .- J. Aγ. prob ( u0, par)) ./ δ
780
+ @views J.∂TGpo .= (residual ( J. Aγ. prob, vcat (u0[begin : end - 1 ], T + δ), par) .- residual ( J. Aγ. prob, u0, par)) ./ δ
780
781
781
782
J. Aγ (u0, par) # update Aγ
782
783
@@ -848,10 +849,10 @@ function _newton_trap(probPO::PeriodicOrbitTrapProblem,
848
849
_J = probPO (Val (:JacFullSparse ), orbitguess, getparams (probPO. prob_vf)) |> Array
849
850
jac = (x, p) -> probPO (Val (:JacFullSparseInplace ), _J, x, p)
850
851
elseif jacobianPO == :DenseAD
851
- jac = (x, p) -> ForwardDiff. jacobian (z -> probPO ( z, p), x)
852
+ jac = (x, p) -> ForwardDiff. jacobian (z -> residual (probPO, z, p), x)
852
853
elseif jacobianPO == :FullMatrixFreeAD
853
- jac = (x, p) -> dx -> ForwardDiff. derivative (t -> probPO ( x .+ t .* dx, p), 0 )
854
- else
854
+ jac = (x, p) -> dx -> ForwardDiff. derivative (t -> residual (probPO, x .+ t .* dx, p), 0 )
855
+ else
855
856
jac = (x, p) -> ( dx -> probPO (x, p, dx))
856
857
end
857
858
@@ -984,9 +985,9 @@ function continuation_potrap(prob::PeriodicOrbitTrapProblem,
984
985
_J = prob (Val (:JacFullSparse ), orbitguess, getparams (prob. prob_vf)) |> Array
985
986
jac = (x, p) -> (prob (Val (:JacFullSparseInplace ), _J, x, p); FloquetWrapper (prob, _J, x, p));
986
987
elseif jacobianPO == :DenseAD
987
- jac = (x, p) -> FloquetWrapper (prob, ForwardDiff. jacobian (z -> prob ( z, p), x), x, p)
988
+ jac = (x, p) -> FloquetWrapper (prob, ForwardDiff. jacobian (z -> residual (prob, z, p), x), x, p)
988
989
elseif jacobianPO == :FullMatrixFreeAD
989
- jac = (x, p) -> FloquetWrapper (prob, dx -> ForwardDiff. derivative (t-> prob ( x .+ t .* dx, p), 0 ), x, p)
990
+ jac = (x, p) -> FloquetWrapper (prob, dx -> ForwardDiff. derivative (t-> residual (prob, x .+ t .* dx, p), 0 ), x, p)
990
991
else
991
992
jac = (x, p) -> FloquetWrapper (prob, x, p)
992
993
end
0 commit comments