# Isolated_a_bifurcation
from numpy import *
from pylab import *
from ForgetfulIntegrator1D import *
from OneDimMap import *
import random
import time

time.clock()	# let's see how long this takes
dt = .001	# more precise?
nTransients = 50.0
#nTransients = 0.0
nIterates = 80.0
transienttimesteps = nTransients*2*pi/dt	# does this mess up
timesteps = nIterates*2*pi/dt # + nIterates	# add nIterates for now in case we lose a few timesteps...only length(theta_n) will count	# is int type okay? necessary?
t_0 = 0.0

def d_theta(a,b,gamma, theta,t):
	dTheta = -gamma/pi*theta + gamma*(a - b*cos(t))	# make sure this isn't returning a tuple!
	return dTheta

class SETJmap_a(OneDimMap):

	def __init__(self, ind_var = [-.5,2.5], param = [1.77,2.0,1./3.,-0.4]):	# ind_var: a, use random IC for theta_0
		#(self,theta_0): #,neighbors):
		#param = [1.77,2.0,1./3.]	# params = [a,b,gamma], could be ranges? maybe for specific applications?
		OneDimMap.__init__(self, ind_var = [-.5,2.5], param = [1.77,2.0,1./3.,-0.4])
		self.nTransients = nTransients 
		self.nIterates = nIterates
		#self.nIterates = 1.0
		self.independent_var = 'a'
		self.ylabel = 'theta(t = 2 pi n), n = 1,2,3,... '
		self.name = 'Bifurcation diagram for ' + self.ylabel + ' as we vary ' + self.independent_var
		#self.neighbors = neighbors	# ...

	def maptransients(self,r):
		self.current = random.uniform(-1.,1.)*pi	# this will carry over to the non-transient map, should draw out any variability across theta_0
		theta_last,theta_n_transient,t_last,tau_i_map = ForgetfulRK1DIntegrator(r,self.b,self.gamma,self.current,self.ThetaMax,d_theta,dt,transienttimesteps,self.t) # only differs by transienttimesteps
		# see that r replaces 'a'
		
		return theta_last,theta_n_transient,t_last,tau_i_map


	def map(self,r):
		theta_last,theta_n,t_last,tau_i_map = ForgetfulRK1DIntegrator(r,self.b,self.gamma,self.current,self.ThetaMax,d_theta,dt,timesteps,self.t)
		
		return theta_last,theta_n,t_last,tau_i_map

MyMap = SETJmap_a()
MyMap.show()
time.clock()
