def pulseC(x, re=1., om=1., px=1.): h = x[-1] / 2 mu = sqrt(om * re / 2.) * h nu = sqrt(om * re / 2.) * (x - h) d = px / (om * (cos(mu)**2 * cosh(mu)**2 + sin(mu)**2 * sinh(mu)**2)) return (d * (cos(nu) * cosh(nu) * sin(mu) * sinh(mu) - sin(nu) * sinh(nu) * cos(mu) * cosh(mu)))
def diffRtc(self,z): Dh = self.cH Dc = self.rc(z) sqOmR = M.sqrt(abs(self.k0)) diff = Dh/self.E(z) if self.k0 > 0: diff = diff * M.cosh(sqOmR*Dc/Dh) elif self.k0 < 0: diff = diff * M.cos (sqOmR*Dc/Dh); return diff
def f(self,xarr,t): temp = 0.0 for i in range(2): temp+=pl.sin(self.k*xarr[2]-i*pl.pi)*pl.cos(self.w*t-i*pl.pi)/(pl.cosh(self.k*xarr[3])-pl.cos(self.k*xarr[2]-i*pl.pi)) temp = temp*self.coef temp -= self.drg*xarr[0] x1dot = temp x2dot = 0.0 x3dot = xarr[0] x4dot = 0.0 return [x1dot,x2dot,x3dot,x4dot]
def J(self,which_M,t): # to get the solution at a particular time we need the index that is assosiated witht that # time. we get this by taking the time value wanted and deviding by dt. In order for this to # work with single (non array values) of time we need a self,dt to be defined. x1 = self.sol[int(t/self.dt+.5),2] y = self.sol[int(t/self.dt+.5),3] #print(t/self.dt) # define the matrix elements of the time dependent jacobian M11 = 0.0 M12 = 1.0 #M21 = self.coef*pl.cos(x1)*pl.cosh(y)*pl.cos(t)*(pl.cos(2.0*x1)+pl.cosh(2.0*y)-2.0)/(pl.cos(x1)**2-pl.cosh(y)**2)**2 M21 = -2.0*self.coef*pl.cos(x1)*pl.cosh(y)*pl.cos(t)*(pl.cos(x1)**2-pl.cosh(y)**2+2.0*pl.sin(x1)**2)/(pl.cos(x1)**2-pl.cosh(y)**2)**2 M22 = -self.drg if (which_M == "M11"): return M11 if (which_M == "M12"): return M12 if (which_M == "M21"): return M21 if (which_M == "M22"): return M22
def phiPrime2(self,t): return 0.5*M.pi*t*M.cosh(t)/M.cosh(0.5*M.pi*M.sinh(t))**2+M.tanh(0.5*M.pi*M.sinh(t))
def eph2D(self,epoch): if self.ref == None: return ([0,0,0],[0,0,0]) dt = epoch-self.epoch #print "dT",dt # Step 1 - Determine mean anomaly at epoch if self.e == 0: M = self.M0 + dt * sqrt(self.ref.mu / self.a**3) M %= PI2 E = M ta = E r3 = (self.h**2/self.ref.mu) rv = r3 * array([cos(ta),sin(ta),0]) v3 = self.ref.mu / self.h vv = v3 * array([-sin(ta),self.e+cos(ta),0]) return (rv,vv) if self.e < 1: if epoch == self.epoch: M = self.M0 else: M = self.M0 + dt * sqrt(self.ref.mu / self.a**3) M %= PI2 # Step 2a - Eccentric anomaly try: E = so.newton(lambda x: x-self.e * sin(x) - M,M) except RuntimeError: # Debugging a bug here, disregard print "Eccentric anomaly failed for",self.obj.name print "On epoch",epoch print "Made error available at self.ERROR" self.ERROR = [lambda x: x-self.e * sin(x) - M,M] raise # Step 3a - True anomaly, method 1 ta = 2 * arctan2(sqrt(1+self.e)*sin(E/2.0), sqrt(1-self.e)*cos(E/2.0)) #print "Ta:",ta # Method b is faster cosE = cos(E) ta2 = arccos((cosE - self.e) / (1-self.e*cosE)) #print "e",self.e #print "M",M #print "E",E #print "TA:",ta #print "T2:",ta2 # Step 4a - distance to central body (eccentric anomaly). r = self.a*(1-self.e * cos(E)) # Alternative (true anomaly) r2 = (self.a*(1-self.e**2) / (1.0 + self.e * cos(ta))) # Things get crazy #h = sqrt(self.a*self.ref.mu*(1-self.e**2)) r3 = (self.h**2/self.ref.mu)*(1.0/(1.0+self.e*cos(ta))) #print "R1:",r #print "R2:",r2 #print "R3:",r3 rv = r3 * array([cos(ta),sin(ta),0]) #v1 = sqrt(self.ref.mu * (2.0/r - 1.0/self.a)) #v2 = sqrt(self.ref.mu * self.a) / r v3 = self.ref.mu / self.h #meanmotion = sqrt(self.ref.mu / self.a**3) #v2 = sqrt(self.ref.mu * self.a)/r #print "v1",v1 #print "v2",v2 #print "v3",v3 #print "mm",meanmotion # Velocity can be calculated from the eccentric anomaly #vv = v1 * array([-sin(E),sqrt(1-self.e**2) * cos(E),0]) # Or from the true anomaly (this one has an error..) #vv = sqrt(self.ref.mu * self.a)/r * array([-sin(ta),self.e+cos(ta),0]) vv = v3 * array([-sin(ta),self.e+cos(ta),0]) #print "rv",rv #print "vv",vv #print "check",E,-sin(E),v1*-sin(E) #print "V1:",vv #print "V2:",vv2 return (rv,vv) elif self.e > 1: # Hyperbolic orbits # Reference: Stephen Kemble: Interplanetary Mission Analysis and Design, Pg 220-221 M = self.M0 + dt * sqrt(-(self.ref.mu / self.a**3)) #print "M0",self.M0 #print "M",M #print "M",M #print "M0",self.M0 # Step 2b - Hyperbolic eccentric anomaly #print "Hyperbolic mean anomaly:",M F = so.newton(lambda x: self.e * sinh(x) - x - M,M,maxiter=1000) #F = -F H = M / (self.e-1) #print "AAAA"*10 #print "F:",F #print "H:",H #F=H #print "Hyperbolic eccentric anomaly:",F # Step 3b - Hyperbolic true anomaly? # This is wrong prooobably #hta = arccos((cosh(F) - self.e) / (1-self.e*cosh(F))) #hta = arccos((self.e-cosh(F)) / (self.e*cosh(F) - 1)) # TÄSSÄ ON BUGI hta = arccos((cosh(F) - self.e) / (1 - self.e*cosh(F))) hta2 = 2 * arctan2(sqrt(self.e+1)*sinh(F/2.0),sqrt(self.e-1)*cosh(F/2.0)) hta3 = 2 * arctan2(sqrt(1+self.e)*sinh(F/2.0),sqrt(self.e-1)*cosh(F/2.0)) hta4 = 2 * arctan2(sqrt(self.e-1)*cosh(F/2.0),sqrt(1+self.e)*sinh(F/2.0)) #print "Hyperbolic true anomaly:",degrees(hta) # This is wrong too #hta2 = 2 * arctan2(sqrt(1+self.e)*sin(F/2.0), sqrt(1-self.e)*cos(F/2.0)) if M == self.M0: print "HTA1:",degrees(hta) print "HTA2:",degrees(hta2) print "HTA3:",degrees(hta3) print "HTA4:",degrees(hta4) # According to http://mmae.iit.edu/~mpeet/Classes/MMAE441/Spacecraft/441Lecture17.pdf # this is right.. hta = hta2 #print cos(hta) #print cosh(hta) #####hta = arctan(sqrt((self.e-1.0)/self.e+1.0) * tanh(F/2.0)) / 2.0 #print "Mean anomaly:",M #print "Hyperbolic eccentric anomaly:",F #print "HTA:",hta #raise # Step 4b - Distance from central body? # Can calculate it from hyperbolic true anomaly.. #p = self.a*(1-self.e**2) #r = p / (1+self.e * cos(hta)) r3 = (self.h**2/self.ref.mu)*(1.0/(1.0+self.e*cos(hta))) v3 = self.ref.mu / self.h # But it's faster to calculate from eccentric anomaly #r = self.a*(1-self.e * cos(F)) #print "Hyper r1:",r #print "Hyper r2:",r2 rv = r3 * array([cos(hta),sin(hta),0]) #http://en.wikipedia.org/wiki/Hyperbola #rv = array([ r * sin(hta),-self.a*self.e + r * cos(hta), 0]) #sinhta = sin(hta) #coshta = cos(hta) #print self.ref.mu,r,self.a,hta #vv = sqrt(self.ref.mu *(2.0/r - 1.0/self.a)) * array([-sin(hta),self.e+cos(hta),0]) vv = v3 * array([-sin(hta),self.e+cos(hta),0]) return (rv,vv)
def cc(x): return cos(x) * cosh(x)