def poincare_step(z, t): " Integrate until the poincare section is reached again, in the right direction" # Integrate just a tiny step to make sure we don't stop at the # same point (y, tout, t_root, y_root, i_root, info_dict) = lsodar.odeintr( f, copy(z), linspace(t, t + t_small, np2), rtol=rtol, atol=atol, full_output=1, root_func=event, root_term=array([0]), ) ynew = copy(y[-1, :]) tnew = copy(tout[-1]) print tnew # Main integration (y, tout, t_root, y_root, i_root, info_dict) = lsodar.odeintr( f, copy(ynew), linspace(tnew, tnew + max_t, np), rtol=rtol, atol=atol, full_output=1, root_func=event, root_term=array([1]), ) ynew = copy(y[-1, :]) if tout[-1] == tnew + max_t: raise RuntimeError, ("Never reached the Poincare section again. Oh noes!", ynew) tnew = copy(tout[-1]) print tnew # Must check that the trajectory is going the right way if dot(f(ynew, tnew), n) < 0: print "Reached wrong side of the hyperplane, continuing..." # The solution cannot pass the hyperplane in the same direction two # times in a row, so just integrate one more time (y, tout, t_root, y_root, i_root, info_dict) = lsodar.odeintr( f, copy(ynew), linspace(tnew, tnew + max_t, np), rtol=rtol, atol=atol, full_output=1, root_func=event, root_term=array([1]), ) ynew = copy(y[-1, :]) tnew = copy(tout[-1]) print tnew if len(t_root) == 0: raise RuntimeError, ("Never reached the Poincare section again. Oh noes!", ynew) else: print "Reached Poincare section again at", ynew return (ynew, tnew)
y0[5*i] = (b0+c0)/2 # r y0[5*i+1] = 2*pi*i/n # theta y0[5*i+2] = 0 # rdot y0[5*i+3] = b0/(b0+c0)*w0 # thetadot y0[5*i+4] = b0/2/a0*w0 # phidot - note that phi is not a state variable since it does not matter here #numsteps = 2000 numsteps = 1000 start = 0 end = 0.03 T = linspace(start,end,numsteps) (Y, info) = lsodar.odeintr(oderhs, copy(y0), T, atol = 1e-8, rtol = 1e-8, full_output=1) print Y[-1,:] for j in xrange(0,n): subplot(n+1,5,5*j+1) plot(T, Y[:,5*j+0]) #r subplot(n+1,5,5*j+2) plot(T, Y[:,5*j+1]) #th subplot(n+1,5,5*j+3) plot(T, Y[:,5*j+2]) # rdot subplot(n+1,5,5*j+4) plot(T, Y[:,5*j+3]) # thdot