4.11.8. Branch switching
Arclength continuation follows one branch of solutions. At a bifurcation, however, another branch passes through the very same point, and the continuation will just walk past it without ever noticing that there was a turn-off. Stepping over onto that second branch is called branch switching and is done by switch_branch().
Not all bifurcations have a second branch, though. At a fold, the single branch merely turns around, and the arclength continuation gets around it by itself. At a transcritical and at a pitchfork bifurcation, however, there is, so we consider these with a specifically made-up ODE system
with the single parameter \(r\). Its stationary solutions can be written down by hand, which is what makes it a good test case. Since \(\partial_t x\) does not involve \(y\) at all, the \(x\)-equation can be solved on its own. It is easy to see that \(x\) has the trivial solution \(x=0\) and a nontrivial one, \(x^2-x-r=0\). This gives a transcritical bifurcation at \(r=0\) and a fold at \(r=-1/4\). For the \(y\)-equation, the parameter \(r\) does not enter, but \(x\) does, and it forms a pitchfork normal form, where \(x\) takes the function of a parameter (shifted by \(x=3/2\)), i.e. we expect a pitchfork bifurcation once \(x\) passes \(3/2\).
The numerical implementation is straightforward:
class BranchSwitchODE(ODEEquations):
def __init__(self,r):
super(BranchSwitchODE, self).__init__()
self.r=r
def define_fields(self):
self.define_ode_variable("x","y")
def define_residuals(self):
x,x_test=var_and_test("x")
y,y_test=var_and_test("y")
self.add_weak(partial_t(x)-(self.r*x+x**2-x**3),x_test)
self.add_weak(partial_t(y)-((x-rational_num(3,2))*y-y**3),y_test)
class BranchSwitchProblem(Problem):
def __init__(self):
super(BranchSwitchProblem, self).__init__()
self.r=self.define_global_parameter(r=-1)
def define_problem(self):
eqs=BranchSwitchODE(self.r)
eqs+=InitialCondition(x=0,y=0)
eqs+=ODEFileOutput()
self.add_equations(eqs@"ode")
Branch switching requires the analytically derived Hessian, since the normal form of the bifurcation, from which the position of the second branch is predicted, is built from it. It is therefore mandatory to call setup_for_stability_analysis() with analytic_hessian=True. We furthermore let the state files also store the arclength tangent, which we will need further below:
# Branch switching needs the analytically derived Hessian: the normal form is built from it
problem.setup_for_stability_analysis(analytic_hessian=True)
# Store the arclength tangent in the state files as well. Without it, a state reloaded in the
# middle of a continuation cannot tell which way along the branch it was going.
problem.continuation_data_in_states=True
Then, a few helper functions are defined, in particular one that performs arclength continuation until the largest eigenvalue changes sign, i.e. until we have just stepped over a bifurcation, and one that simply carries on along a branch:
def continue_to_bifurcation(ds,max_ds=0.05,maxsteps=500):
"""Arclength continuation until the largest eigenvalue changes sign. Returns the step size to carry on with."""
sign=numpy.sign(write_state())
for _ in range(maxsteps):
ds=problem.arclength_continuation(problem.r,ds,max_ds=max_ds)
if numpy.sign(write_state())!=sign:
return ds
raise RuntimeError("no bifurcation found along this branch")
def continue_further(ds,until_r,max_ds=0.05,maxsteps=500):
for _ in range(maxsteps):
if problem.r.value>=until_r:
return
ds=problem.arclength_continuation(problem.r,ds,max_ds=max_ds)
write_state()
We start on the trivial branch \(x=y=0\) at \(r=-1\), where it is stable, and continue upwards until the sign change announces the bifurcation at \(r=0\). The trivial branch does not stop there, though - it merely becomes unstable. For a complete diagram, we therefore scan it out first and only then turn to the bifurcation. To be able to return to it, the state is stored before continuing, which is what continuation_data_in_states=True above was set for: a reloaded state must also know in which direction along the branch it was travelling, or the resumed continuation picks the wrong one and might drop off the branch. The very same pattern will be used at the fold and at the pitchfork below:
# Start on the trivial branch x=y=0 at r=-1, where it is stable, and increase r
problem.r.value=-1
problem.solve()
start_branch("branch_trivial")
ds=continue_to_bifurcation(0.047)
# We have just stepped over the bifurcation, i.e. the trivial branch has become unstable here.
# Before turning to the bifurcation itself, scan out the rest of the trivial branch.
near_transcritical=problem.backup_state() # Store the state
continue_further(ds,2) # scan the unstable branch
problem.load_state(near_transcritical,quiet=False) # go back to the bifurcation
Back at the bifurcation, we converge exactly onto it with activate_bifurcation_tracking(), as discussed in Section 4.11.7. What is new here is classify_bifurcation(), which calculates the normal form of the bifurcation we are sitting on and thereby tells us which kind it is:
# Converge exactly onto the bifurcation and ask what it is
problem.activate_bifurcation_tracking("r")
problem.solve()
normal_form=problem.classify_bifurcation("r")
print("Found a",normal_form["type"],"at r,x,y =",get_state())
It reports transcritical, so there is a second branch, and switch_branch() steps onto it. It deactivates the bifurcation tracking by itself, since the switch needs the plain, unaugmented system, and it returns a step size to carry on the continuation with:
# It is a transcritical, so there is a second branch through it. Step onto it and follow it
# towards decreasing r until the fold at r=-1/4. The step size returned by switch_branch is
# small on purpose and grows again by itself during the continuation.
start_branch("branch_nontrivial")
write_bifurcation()
ds=problem.switch_branch("r",normal_form=normal_form,direction=-1)
print("Switched onto the second branch at r,x,y =",get_state())
ds=continue_to_bifurcation(ds)
The direction argument selects which of the two sides of the bifurcation is taken, here the one towards decreasing \(r\). The returned step size is deliberately small: right next to a bifurcation the branch is still badly conditioned, and arclength_continuation() will grow it again by itself. The bifurcation point itself is written to the output file before switching, so that the new branch is connected to it when it is plotted.
The next sign change along the new branch is the fold at \(r=-1/4\). Before converging onto it, we store the current state again, so that the continuation can be resumed exactly here afterwards:
# We are just past the fold. Remember where, so that we can come back after inspecting it
state_past_fold=problem.backup_state(quiet=True)
problem.activate_bifurcation_tracking("r")
problem.solve()
normal_form=problem.classify_bifurcation("r")
print("Found a",normal_form["type"],"at r,x,y =",get_state())
# We cannot switch branches here, of course, since it is a fold
problem.deactivate_bifurcation_tracking()
This time, classify_bifurcation() reports fold and switch_branch() refuses to do anything, since there simply is no second branch to go to. We hence just return to the stored state and let the arclength continuation pass around the fold on its own:
# Back to just past the fold and carry on
problem.load_state(state_past_fold,quiet=True)
ds=continue_to_bifurcation(ds)
Beyond the fold, the branch runs upwards in \(x\) again and the next sign change is the pitchfork at \(r=3/4\), \(x=3/2\). As on the trivial branch, we first scan out the part of \(y=0\) beyond it, which has just become unstable, and then come back:
# Beyond the pitchfork, y=0 has become unstable. Again, scan out that part of the branch first
# and then come back to the bifurcation.
near_pitchfork=problem.backup_state(quiet=True)
continue_further(ds,2)
problem.load_state(near_pitchfork,quiet=True)
Two things then have to be done differently from the transcritical bifurcation:
The bifurcation must be located with the pitchfork tracker, i.e. by passing
"pitchfork"toactivate_bifurcation_tracking(). The fold tracker used above augments the system by \(\mathbf{J}\vec{v}=0\), which is itself singular at a symmetry-breaking bifurcation, and the Newton solve would fail with a singular matrix.The bifurcation should be classified with
assume="pitchfork". The distinction between a pitchfork and a transcritical is made by whether the quadratic coefficient of the normal form vanishes - and here it vanishes identically, by virtue of the symmetry \(y\to-y\), so all that is numerically left of it is round-off. Whenever the symmetry of the system already answers the question, it is better to say so than to let the numbers decide.
# The pitchfork. It must be located with the pitchfork tracker: the fold tracker used above
# augments the system in a way that is itself singular at a symmetry-breaking bifurcation.
problem.activate_bifurcation_tracking("r","pitchfork")
problem.solve()
# And it must be classified with assume="pitchfork": the y -> -y symmetry of the system makes
# the quadratic coefficient b2 vanish identically, so all that is left for the classification
# to measure is round-off, and the symmetry answers the question better than the numbers can.
normal_form=problem.classify_bifurcation("r",assume="pitchfork")
print("Found a",normal_form["type"],"at r,x,y =",get_state())
The two branches eqodebranchswitchpf emanating from a pitchfork lie at the same values of \(r\) and differ only in the sign of the amplitude, i.e. the direction argument is the only thing that tells them apart. We therefore store the state at the bifurcation, switch onto one of them, come back and switch onto the other:
# Both branches of the pitchfork sit at the same r and differ only in the sign of y, so the
# direction argument is the only thing that tells them apart
state_at_pitchfork=problem.backup_state(quiet=True)
for direction,name in [(1,"branch_pitchfork_plus"),(-1,"branch_pitchfork_minus")]:
problem.load_state(state_at_pitchfork,quiet=True)
start_branch(name)
write_bifurcation()
ds=problem.switch_branch("r",normal_form=normal_form,direction=direction)
print("Switched onto the branch with y =",get_state()[2])
write_state()
while problem.r.value<2:
ds=problem.arclength_continuation(problem.r,ds,max_ds=0.1)
r,x,y=get_state()
write_state()
print("r,x,y = {:.5f}, {:.5f}, {:.5f}, analytically y = {:+.5f}".format(r,x,y,direction*numpy.sqrt(x-1.5)))
The printed values agree with eqodebranchswitchpf to all digits shown. The complete diagram is depicted in Fig. 4.15.
Fig. 4.15 Bifurcation diagram of (4.17), obtained by branch switching. Solid lines are stable, dashed lines unstable. Since \(x\) does not depend on \(y\), the two branches emerging from the pitchfork coincide with the second branch in the left plot.
The very same three methods, classify_bifurcation(), switch_branch() and the state files that let one revisit a bifurcation, also work for spatio-temporal problems, where the branches are not known beforehand and the diagram must be explored step by step.