Skip to content

Commit 47da9ea

Browse files
committed
inserting new jacobian back into tangent_rule
1 parent ad27eac commit 47da9ea

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

src/derived_systems/tangent_space.jl

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function TangentDynamicalSystem(ds::CoreDynamicalSystem{IIP};
113113
u0_correct = correct_state(Val{IIP}(), u0)
114114
Q0_correct = correct_matrix_type(Val{IIP}(), Q0)
115115
newstate = hcat(u0_correct, Q0_correct)
116+
J = isnothing(J) ? jacobian(ds) : J
116117
newrule = tangent_rule(f, J, J0, Val{IIP}(), Val{k}(), u0_correct)
117118

118119
# Pass everything to analytic system constructors
@@ -149,37 +150,12 @@ function tangent_rule(f::F, J::JAC, J0, ::Val{true}, ::Val{k}, u0) where {F, JAC
149150
end
150151
return tangentf
151152
end
152-
# for the case of autodiffed systems, a specialized version is created
153-
# so that f! is not called twice in ForwardDiff
154-
function tangent_rule(f::F, ::Nothing, J0, ::Val{true}, ::Val{k}, u0) where {F, k}
155-
let
156-
cfg = ForwardDiff.JacobianConfig(
157-
(du, u) -> f(du, u, p, p), deepcopy(u0), deepcopy(u0)
158-
)
159-
tangentf = (du, u, p, t) -> begin
160-
uv = @view u[:, 1]
161-
ForwardDiff.jacobian!(
162-
J0, (du, u) -> f(du, u, p, t), view(du, :, 1), uv, cfg, Val{false}()
163-
)
164-
mul!((@view du[:, 2:k+1]), J0, (@view u[:, 2:k+1]))
165-
nothing
166-
end
167-
return tangentf
168-
end
169-
end
170153

171154
# OOP Tangent space dynamics
172155
function tangent_rule(f::F, J::JAC, J0, ::Val{false}, ::Val{k}, u0) where {F, JAC, k}
173-
# out of place
174-
if JAC == Nothing
175-
# There is no config needed here
176-
Jf = (u, p, t) -> ForwardDiff.jacobian((x) -> f(x, p, t), u)
177-
else
178-
Jf = J
179-
end
180156
# Initial matrix `J0` is ignored
181157
ws_index = SVector{k, Int}(2:(k+1)...)
182-
tangentf = TangentOOP(f, Jf, ws_index)
158+
tangentf = TangentOOP(f, J, ws_index)
183159
return tangentf
184160
end
185161
struct TangentOOP{F, JAC, k} <: Function

0 commit comments

Comments
 (0)