Skip to content

Commit

Permalink
Add after_correction! hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Aug 8, 2018
1 parent 88675ff commit 783d93e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/codim1lc/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using ..Continuations: AbstractContinuationProblem, AbstractContinuationSolver,
as, SweepSetup, ContinuationSweep, ContinuationSolution,
ContinuationCache, ContinuationOptions, ContinuationSolver,
residual_jacobian!
import ..Continuations: after_correction!

using ..BifurcationsBase: timekind, Continuous, Discrete
import ..BifurcationsBase: TimeKind
Expand Down Expand Up @@ -125,6 +126,10 @@ testfn(::Val{PointTypes.saddle_node}, ::Continuous, ::LimitCycleCont,
prob_cache, u, J, L, Q) =
det(@view J[:, 1:end-1])

function after_correction!(prob_cache::LimitCycleCache, u)
set_reference!(prob_cache, u)
end

function set_reference!(wrapper)
cache = as(wrapper, ContinuationCache)
prob_cache = as(cache.prob_cache, LimitCycleCache)
Expand Down
2 changes: 2 additions & 0 deletions src/continuations/euler_newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ function predictor_corrector_step!(cache::ContinuationCache,
cache.J = J
cache.h = h

after_correction!(cache.prob_cache, v)

tJv = tangent(L, Q)
if tJ tJv < 0
cache.direction *= -1
Expand Down
5 changes: 5 additions & 0 deletions src/continuations/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,10 @@ function get_prob_cache end
"""
function get_u0 end

"""
after_correction!(prob_cache, u)
"""
function after_correction!(::AbstractProblemCache, ::Any)
end

abstract type AbstractContinuationCache{PC <: AbstractProblemCache} end
6 changes: 6 additions & 0 deletions src/continuations/zero_point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ function find_zero!(cache, opts, f, u0, u1, direction)
rtol = opts.rtol
atol = opts.atol

after_correction!(prob_cache, u0)

H, J = residual_jacobian!(H, J, u1, prob_cache)
A = vcat(J, _zeros(J, 1, size(J, 2))) # TODO: improve
L, Q = lq!(Q, A)
f1 = f(u1, J, L, Q)

# after_correction!(prob_cache, u1) # TODO: fix?

H, J = residual_jacobian!(H, J, u0, prob_cache)
A = vcat(J, _zeros(J, 1, size(J, 2))) # TODO: improve
L, Q = lq!(Q, A)
Expand Down Expand Up @@ -98,6 +102,8 @@ function find_zero!(cache, opts, f, u0, u1, direction)
u = v
fu = fv

after_correction!(prob_cache, v)

if abs(h) < opts.h_zero
return v, tJv, L, Q, J
end
Expand Down

0 comments on commit 783d93e

Please sign in to comment.