def E(self, *args, **kwargs): """ NAME: E PURPOSE: calculate the energy INPUT: pot= t= time at which to evaluate E OUTPUT: energy HISTORY: 2010-09-15 - Written - Bovy (NYU) """ if not 'pot' in kwargs or kwargs['pot'] is None: try: pot = self._pot except AttributeError: raise AttributeError("Integrate orbit or specify pot=") if 'pot' in kwargs and kwargs['pot'] is None: kwargs.pop('pot') else: pot = kwargs.pop('pot') if isinstance(pot, Potential): thispot = toPlanarPotential(pot) elif isinstance(pot, list): thispot = [] for p in pot: if isinstance(p, Potential): thispot.append(toPlanarPotential(p)) else: thispot.append(p) else: thispot = pot if len(args) > 0: t = args[0] else: t = 0. #Get orbit thiso = self(*args, **kwargs) onet = (len(thiso.shape) == 1) if onet: return _evaluateplanarPotentials(thispot,thiso[0], phi=thiso[3],t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([_evaluateplanarPotentials(thispot,thiso[0,ii], phi=thiso[3,ii], t=t[ii])\ +thiso[1,ii]**2./2.\ +thiso[2,ii]**2./2. for ii in range(len(t))])
def E(self,*args,**kwargs): """ NAME: E PURPOSE: calculate the energy INPUT: pot= t= time at which to evaluate E OUTPUT: energy HISTORY: 2010-09-15 - Written - Bovy (NYU) """ if not 'pot' in kwargs or kwargs['pot'] is None: try: pot= self._pot except AttributeError: raise AttributeError("Integrate orbit or specify pot=") if 'pot' in kwargs and kwargs['pot'] is None: kwargs.pop('pot') else: pot= kwargs.pop('pot') if isinstance(pot,Potential): thispot= toPlanarPotential(pot) elif isinstance(pot,list): thispot= [] for p in pot: if isinstance(p,Potential): thispot.append(toPlanarPotential(p)) else: thispot.append(p) else: thispot= pot if len(args) > 0: t= args[0] else: t= 0. #Get orbit thiso= self(*args,**kwargs) onet= (len(thiso.shape) == 1) if onet: return _evaluateplanarPotentials(thispot,thiso[0], phi=thiso[3],t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([_evaluateplanarPotentials(thispot,thiso[0,ii], phi=thiso[3,ii], t=t[ii])\ +thiso[1,ii]**2./2.\ +thiso[2,ii]**2./2. for ii in range(len(t))])
def integrate(self, t, pot, method='symplec4_c', dt=None): """ NAME: integrate PURPOSE: integrate the orbit INPUT: t - list of times at which to output (0 has to be in this!) pot - potential instance or list of instances method= 'odeint' for scipy's odeint 'leapfrog' for a simple leapfrog implementation 'leapfrog_c' for a simple leapfrog implementation in C 'rk4_c' for a 4th-order Runge-Kutta integrator in C 'rk6_c' for a 6-th order Runge-Kutta integrator in C 'dopr54_c' for a Dormand-Prince integrator in C (generally the fastest) dt= (None) if set, force the integrator to use this basic stepsize; must be an integer divisor of output stepsize OUTPUT: (none) (get the actual orbit using getOrbit() HISTORY: 2010-07-20 """ if hasattr(self, '_orbInterp'): delattr(self, '_orbInterp') if hasattr(self, 'rs'): delattr(self, 'rs') thispot = toPlanarPotential(pot) self.t = nu.array(t) self._pot = thispot self.orbit, msg = _integrateOrbit(self.vxvv, thispot, t, method, dt) return msg
def integrate_dxdv(self,dxdv,t,pot,method='dopr54_c', rectIn=False,rectOut=False): """ NAME: integrate_dxdv PURPOSE: integrate the orbit and a small area of phase space INPUT: dxdv - [dR,dvR,dvT,dphi] t - list of times at which to output (0 has to be in this!) pot - potential instance or list of instances method= 'odeint' for scipy's odeint 'rk4_c' for a 4th-order Runge-Kutta integrator in C 'rk6_c' for a 6-th order Runge-Kutta integrator in C 'dopr54_c' for a Dormand-Prince integrator in C (generally the fastest) rectIn= (False) if True, input dxdv is in rectangular coordinates rectOut= (False) if True, output dxdv (that in orbit_dxdv) is in rectangular coordinates OUTPUT: (none) (get the actual orbit using getOrbit_dxdv() HISTORY: 2010-10-17 - Written - Bovy (IAS) 2014-06-29 - Added rectIn and rectOut - Bovy (IAS) """ if hasattr(self,'_orbInterp'): delattr(self,'_orbInterp') if hasattr(self,'rs'): delattr(self,'rs') thispot= toPlanarPotential(pot) self.t= nu.array(t) self._pot_dxdv= thispot self._pot= thispot self.orbit_dxdv, msg= _integrateOrbit_dxdv(self.vxvv,dxdv,thispot,t, method,rectIn,rectOut) self.orbit= self.orbit_dxdv[:,:4] return msg
def integrate(self,t,pot,method='symplec4_c',dt=None): """ NAME: integrate PURPOSE: integrate the orbit INPUT: t - list of times at which to output (0 has to be in this!) pot - potential instance or list of instances method= 'odeint' for scipy's odeint 'leapfrog' for a simple leapfrog implementation 'leapfrog_c' for a simple leapfrog implementation in C 'rk4_c' for a 4th-order Runge-Kutta integrator in C 'rk6_c' for a 6-th order Runge-Kutta integrator in C 'dopr54_c' for a Dormand-Prince integrator in C (generally the fastest) dt= (None) if set, force the integrator to use this basic stepsize; must be an integer divisor of output stepsize OUTPUT: (none) (get the actual orbit using getOrbit() HISTORY: 2010-07-20 """ if hasattr(self,'_orbInterp'): delattr(self,'_orbInterp') if hasattr(self,'rs'): delattr(self,'rs') thispot= toPlanarPotential(pot) self.t= nu.array(t) self._pot= thispot self.orbit, msg= _integrateOrbit(self.vxvv,thispot,t,method,dt) return msg
def integrate_dxdv(self, dxdv, t, pot, method='dopr54_c', rectIn=False, rectOut=False): """ NAME: integrate_dxdv PURPOSE: integrate the orbit and a small area of phase space INPUT: dxdv - [dR,dvR,dvT,dphi] t - list of times at which to output (0 has to be in this!) pot - potential instance or list of instances method= 'odeint' for scipy's odeint 'rk4_c' for a 4th-order Runge-Kutta integrator in C 'rk6_c' for a 6-th order Runge-Kutta integrator in C 'dopr54_c' for a Dormand-Prince integrator in C (generally the fastest) rectIn= (False) if True, input dxdv is in rectangular coordinates rectOut= (False) if True, output dxdv (that in orbit_dxdv) is in rectangular coordinates OUTPUT: (none) (get the actual orbit using getOrbit_dxdv() HISTORY: 2010-10-17 - Written - Bovy (IAS) 2014-06-29 - Added rectIn and rectOut - Bovy (IAS) """ if hasattr(self, '_orbInterp'): delattr(self, '_orbInterp') if hasattr(self, 'rs'): delattr(self, 'rs') thispot = toPlanarPotential(pot) self.t = nu.array(t) self._pot_dxdv = thispot self._pot = thispot self.orbit_dxdv, msg = _integrateOrbit_dxdv(self.vxvv, dxdv, thispot, t, method, rectIn, rectOut) self.orbit = self.orbit_dxdv[:, :4] return msg