| 1 |
# This is an example of an 'expert' AUTO CLUI script. |
| 2 |
# This scripts takes the Lagrange points computed |
| 3 |
# by the compute_lagrange_points_0.5.auto and |
| 4 |
# computes the periodic orbits emanating from them. |
| 5 |
|
| 6 |
# In expert scripts we need to explicitly import the |
| 7 |
# AUTOclui library |
| 8 |
from AUTOclui import * |
| 9 |
# There isn't a AUTO CLUI command for diagnostic |
| 10 |
# file parsing yet, but in a script such as |
| 11 |
# this we can just as easily import the parsing |
| 12 |
# class directly. |
| 13 |
import parseD |
| 14 |
|
| 15 |
# We also import a few general Python utility |
| 16 |
# libraries. |
| 17 |
import sys |
| 18 |
import math |
| 19 |
|
| 20 |
# We have divided the functionality if this |
| 21 |
# script into two functions, so that the |
| 22 |
# same ideas may be more easily used in |
| 23 |
# other contexts. |
| 24 |
def compute_periodic_family(starting_point,mu,compute_bifur_flag="no",npr=20): |
| 25 |
# We load the 3d.c, the starting point file, and |
| 26 |
# c.3d into the AUTO CLUI |
| 27 |
# And we parse the starting solution. This |
| 28 |
# is mainly to determine what label the |
| 29 |
# file contains. |
| 30 |
starting_solution=load(starting_point,e='3d',c='3d') |
| 31 |
|
| 32 |
# We setup the calculation by setting the |
| 33 |
# starting solution to be the appropriate label. |
| 34 |
# And setting the problem type. In this case |
| 35 |
# we want to compute a family of equilibria. |
| 36 |
|
| 37 |
# Our initial calculation it to go from 0.5 |
| 38 |
# to the desired mu value, so we put in a |
| 39 |
# stopping condition for the mu value we want. |
| 40 |
|
| 41 |
# Since we are starting at mu=0.5 we want to |
| 42 |
# go down if the desired value is less, and |
| 43 |
# go up if the desired value is more. |
| 44 |
ds = starting_solution.c["DS"] |
| 45 |
if mu < 0.5: |
| 46 |
ds = -ds |
| 47 |
# Run and get a parsed solution as well. |
| 48 |
hopf_bifurcation = run(starting_solution,IPS=1,UZR={-1:mu},DS=ds) |
| 49 |
|
| 50 |
# We save this solution |
| 51 |
save(hopf_bifurcation,'hopf_bifurcation') |
| 52 |
# Get just the solution |
| 53 |
hopf_bifurcation = hopf_bifurcation()[-1] |
| 54 |
|
| 55 |
# This will eventually become an AUTO2000 internal |
| 56 |
# NOTE: the interface to the parseD object is |
| 57 |
# under development and may change significantly |
| 58 |
# in the final version |
| 59 |
parseD_object=parseD.parseD('fort.9') |
| 60 |
|
| 61 |
# We print out the eigenvalues of the Jacobian. |
| 62 |
print parseD_object[-2]["Eigenvalues"] |
| 63 |
|
| 64 |
# In this loop we look for all eigenvalues |
| 65 |
# with "zero" (i.e. sufficiently small) real part. |
| 66 |
# We begin by defining an array in which the periods |
| 67 |
# of the Hopf bifurcations will be stored. |
| 68 |
periods = [] |
| 69 |
# The parseD_object is basically a Python list, |
| 70 |
# so we use standard Python syntax to iterate |
| 71 |
# over it. |
| 72 |
for eigenvalue in parseD_object[-2]["Eigenvalues"]: |
| 73 |
if math.fabs(eigenvalue[0]) < 1e-8: |
| 74 |
# If the real part in sufficiently small |
| 75 |
# we get the imaginary part |
| 76 |
imag = math.fabs(eigenvalue[1]) |
| 77 |
print "imaginary part: ",imag |
| 78 |
print "period : ",2*math.pi/imag |
| 79 |
# and compute the period. If is is not in our |
| 80 |
# list of periods (i.e. it is not a complex conjugate |
| 81 |
# to one we have already computed) we add it. |
| 82 |
if 2*math.pi/imag not in periods: |
| 83 |
periods.append(2*math.pi/imag) |
| 84 |
|
| 85 |
# Now we have an array which contains the initial periods of all of the |
| 86 |
# periodic orbits emanating from the Hopf bifurcation. |
| 87 |
# We iterate over them and calculate each family. |
| 88 |
for period in periods: |
| 89 |
# Since we have a parsed version of the initial solution |
| 90 |
# it is easy to modify it to include the period |
| 91 |
# we want. In AUTO, the 11th parameter is always |
| 92 |
# the period. |
| 93 |
# Now, when this point was computed we had Hopf |
| 94 |
# bifurcation detection turned off (since all |
| 95 |
# points were Hopf bifurcations). So, we manually |
| 96 |
# mark the point as a Hopf bifurcation. |
| 97 |
hopf_bifurcation = load(hopf_bifurcation,TY="HB",PAR={11:period}) |
| 98 |
|
| 99 |
# We set the problem type, in this case we want to |
| 100 |
# compute a family of periodic orbits. |
| 101 |
|
| 102 |
# We turn off torus bifurcation detection, since there are |
| 103 |
# lots of torus bifurcations. |
| 104 |
|
| 105 |
# We want additional solutions to be saved, so we set NPR to |
| 106 |
# a smaller value. |
| 107 |
|
| 108 |
# We want the period, the y value at t=0, and the Jacobi constant to |
| 109 |
# be printed out, so we add the appropriate parameters, |
| 110 |
|
| 111 |
# And we run the calculation. |
| 112 |
per = run(hopf_bifurcation, IPS=2, ISP=3, NPR=npr, ICP=[2,11,15,16]) |
| 113 |
|
| 114 |
# Finally, we save the solution. |
| 115 |
save(per,'%s_mu_%f_period_%f'%(starting_point,mu,period)) |
| 116 |
|
| 117 |
# Now, if there were any bifurcation points detected we want |
| 118 |
# to compute the branches emanating from them as well. |
| 119 |
# Since this is a very common task, we have put that functionality |
| 120 |
# into a subroutine. |
| 121 |
if compute_bifur_flag == "yes": |
| 122 |
compute_bifur(per,'%s_mu_%f_period_%f'%(starting_point,mu,period)) |
| 123 |
|
| 124 |
# This subroutine takes a bifurcation diagram objec and a solution file name, |
| 125 |
# and for every bifurcation point in the diagram it attempts to |
| 126 |
# compute a bifurcating branch. |
| 127 |
def compute_bifur(problem,solution_file): |
| 128 |
# Use problem('BP') to get a list of all branch points and |
| 129 |
# then we can use standard Python syntax to iterate |
| 130 |
# over it. |
| 131 |
for solution in problem('BP'): |
| 132 |
# ISW=-1 is the syntax for telling AUTO to switch branches |
| 133 |
# at the bifurcation |
| 134 |
# Compute forward |
| 135 |
fw=run(solution,ISW=-1) |
| 136 |
# Save the branch |
| 137 |
save(fw,solution_file+"_+_"+`solution["LAB"]`) |
| 138 |
# Compute backward by making the initial step-size negative |
| 139 |
bw=run(solution,ISW=-1,DS='-') |
| 140 |
# Save the branch |
| 141 |
save(bw,solution_file+"_-_"+`solution["LAB"]`) |
| 142 |
|
| 143 |
|
| 144 |
# This is the Python syntax for making a script runable |
| 145 |
if __name__ == '__main__': |
| 146 |
# We want to have the option of computing the bifurcating |
| 147 |
# branches or not, so we use the Python getopt |
| 148 |
# routines to process command line options. |
| 149 |
import getopt |
| 150 |
# This line process the command line options and |
| 151 |
# looks for a -b option |
| 152 |
opts_list,args=getopt.getopt(sys.argv[1:],"bn:") |
| 153 |
# We take the list of options generated by |
| 154 |
# getopt command and turn it into a dictionary. |
| 155 |
# This is not strictly necessary, but it makes |
| 156 |
# it easier to use. |
| 157 |
opts={} |
| 158 |
for x in opts_list: |
| 159 |
opts[x[0]]=x[1] |
| 160 |
|
| 161 |
# If you use the -b option then we want to compute the bifurcating |
| 162 |
# branches. |
| 163 |
if "-b" in opts: |
| 164 |
compute_bifur_flag="yes" |
| 165 |
else: |
| 166 |
compute_bifur_flag="no" |
| 167 |
|
| 168 |
npr = 20 |
| 169 |
if "-n" in opts: |
| 170 |
npr = int(opts["-n"]) |
| 171 |
|
| 172 |
# The first argument is the name of the file in |
| 173 |
# which you find the starting point |
| 174 |
starting_point = args[0] |
| 175 |
# The second argument is the desired mu value. |
| 176 |
mu = float(args[1]) |
| 177 |
compute_periodic_family(starting_point,mu,compute_bifur_flag,npr) |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|