Skip to content

Commit

Permalink
improve testing of codim2 jacobians
Browse files Browse the repository at this point in the history
  • Loading branch information
rveltz committed Dec 1, 2024
1 parent 9cd358e commit a9cbe42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
23 changes: 12 additions & 11 deletions src/Results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ $(TYPEDFIELDS)
# Associated methods
- `length(br)` number of the continuation steps
- `show(br)` display information about the branch
- `propertynames(br)` give the propertynames of a result
- `eigenvals(br, ind)` returns the eigenvalues for the ind-th continuation step
- `eigenvec(br, ind, indev)` returns the indev-th eigenvector for the ind-th continuation step
- `get_normal_form(br, ind)` compute the normal form of the ind-th points in `br.specialpoint`
- `getlens(br)` return the parameter axis used for the branch
- `getlenses(br)` return the parameter two axis used for the branch when 2 parameters continuation is used (Fold, Hopf, NS, PD)
- `get_solx(br, k)` returns the k-th solution on the branch
- `get_solp(br, k)` returns the parameter value associated with k-th solution on the branch
- `getparams(br)` Parameters passed to continuation and used in the equation `F(x, par) = 0`.
- `getparams(br, ind)` Parameters passed to continuation and used in the equation `F(x, par) = 0` for the ind-th continuation step.
- `setparam(br, p0)` set the parameter value `p0` according to `::Lens` for the parameters of the problem `br.prob`
- `getlens(br)` get the lens used for the computation of the branch
- `eigenvals(br, ind)` give the eigenvalues at continuation step `ind`
- `eigenvalsfrombif(br, ind)` give the eigenvalues at bifurcation point index `ind`
- `type(br, ind)` returns the type of the ind-th bifurcation point
- `br[k+1]` gives information about the k-th step. A typical run yields the following
```
julia> br[1]
Expand All @@ -49,18 +59,9 @@ julia> br.param
-0.4618417402609767
-0.5
```
- `get_solx(br, k)` returns the k-th solution on the branch
- `get_solp(br, k)` returns the parameter value associated with k-th solution on the branch
- `getparams(br)` Parameters passed to continuation and used in the equation `F(x, par) = 0`.
- `getparams(br, ind)` Parameters passed to continuation and used in the equation `F(x, par) = 0` for the ind-th continuation step.
- `setparam(br, p0)` set the parameter value `p0` according to `::Lens` for the parameters of the problem `br.prob`
- `getlens(br)` get the lens used for the computation of the branch
- `continuation(br, ind)` performs automatic branch switching (aBS) from ind-th bifurcation point. Typically branching from equilibrium to equilibrium, or periodic orbit to periodic orbit.
- `continuation(br, ind, lens2)` performs two parameters `(getLens(br), lens2)` continuation of the ind-th bifurcation point.
- `continuation(br, ind, lens2)` performs two parameters `(getlens(br), lens2)` continuation of the ind-th bifurcation point.
- `continuation(br, ind, probPO::AbstractPeriodicOrbitProblem)` performs aBS from ind-th bifurcation point (which must be a Hopf bifurcation point) to branch of periodic orbits.
- `eigenvals(br, ind)` give the eigenvalues at continuation step `ind`
- `eigenvalsfrombif(br, ind)` give the eigenvalues at bifurcation point index `ind`
- `type(br, ind)` returns the type of the ind-th bifurcation point
"""
@with_kw_noshow struct ContResult{Tkind <: AbstractContinuationKind, Tbr, Teigvals, Teigvec, Biftype, Tsol, Tparc, Tprob, Talg} <: AbstractResult{Tkind, Tprob}
"holds the low-dimensional information about the branch. More precisely, `branch[i+1]` contains the following information `(record_from_solution(u, param), param, itnewton, itlinear, ds, θ, n_unstable, n_imag, stable, step)` for each continuation step `i`.\n
Expand All @@ -87,7 +88,7 @@ julia> br.param
"Bifurcation problem used to compute the branch, useful for branch switching. For example, when computing periodic orbits, the functional `PeriodicOrbitTrapProblem`, `ShootingProblem`... will be saved here."
prob::Tprob = nothing

"A vector holding the set of detected bifurcation points. See [`SpecialPoint`](@ref) for a list of special points."
"A vector holding the list of detected bifurcation points. See [`SpecialPoint`](@ref) for a list of special points."
specialpoint::Vector{Biftype}

"Continuation algorithm used for the computation of the branch"
Expand Down
17 changes: 11 additions & 6 deletions test/codim2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,24 @@ sn = newton(br, 3; options = opts_br.newton_options, bdlinsolver = MatrixBLS())
sn = newton(br, 3; options = opts_br.newton_options, bdlinsolver = MatrixBLS(), start_with_eigen = true)
@test BK.converged(sn) && sn.itlineartot == 8

for eigen_start in (true, false)
for eigen_start in (true, false), _jac in (:autodiff, :finiteDifferences, :MinAugMatrixBased, :minaug)
# @info "" eigen_start _jac
sn_br = continuation(br, 3, (@optic _.k), ContinuationPar(opts_br, p_max = 1., p_min = 0., detect_bifurcation = 1, max_steps = 50, save_sol_every_step = 1, detect_event = 2),
bdlinsolver = MatrixBLS(),
start_with_eigen = eigen_start,
update_minaug_every_step = 1,
jacobian_ma = :minaug)
update_minaug_every_step = 1,
detect_codim2_bifurcation = 2,
jacobian_ma = _jac
)
@test sn_br.kind isa BK.FoldCont
@test sn_br.specialpoint[1].type == :bt
@test sn_br.specialpoint[1].param 0.9716038596420551 rtol = 1e-5
@test ~isnothing(sn_br.eig)

# we test the jacobian and problem update
par_sn = BK.setparam(br, sn_br.sol[end].x.p)
par_sn = BK.setparam(br, BK.getp(sn_br.sol[end].x))
par_sn = BK.set(par_sn, BK.getlens(sn_br), sn_br.sol[end].p)
_J = BK.jacobian(prob, sn_br.sol[end].x.u, par_sn)
_J = BK.jacobian(prob, BK.getvec(sn_br.sol[end].x), par_sn)
_eigvals, eigvec, = eigen(_J)
ind = argmin(abs.(_eigvals))
@test _eigvals[ind] 0 atol = 1e-10
Expand Down Expand Up @@ -135,13 +138,15 @@ hp = newton(br, 2;

hp = newton(br, 2; options = NewtonPar( opts_br.newton_options; max_iterations = 10),start_with_eigen=true)

for eigen_start in (true, false)
for eigen_start in (true, false), _jac in (:autodiff, :MinAugMatrixBased, :minaug)
# @info "" eigen_start _jac
hp_br = continuation(br, 2, (@optic _.k),
ContinuationPar(opts_br, ds = -0.001, p_max = 1., p_min = 0., detect_bifurcation = 1, max_steps = 50, save_sol_every_step = 1, detect_event = 2), bdlinsolver = MatrixBLS(),
start_with_eigen = eigen_start,
update_minaug_every_step = 1,
verbosity = 0,
detect_codim2_bifurcation = 2,
jacobian_ma = _jac,
plot=false)
@test hp_br.kind isa BK.HopfCont
@test hp_br.specialpoint[1].type == :gh
Expand Down

0 comments on commit a9cbe42

Please sign in to comment.