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 kwargs.has_key('pot') or kwargs['pot'] is None: try: pot= self._pot except AttributeError: raise AttributeError("Integrate orbit or specify pot=") if kwargs.has_key('pot') and kwargs['pot'] is None: kwargs.pop('pot') else: pot= kwargs['pot'] kwargs.pop('pot') if isinstance(pot,Potential): thispot= RZToplanarPotential(pot) elif isinstance(pot,list): thispot= [] for p in pot: if isinstance(p,Potential): thispot.append(RZToplanarPotential(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(thiso[0],thispot, phi=thiso[3],t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([evaluateplanarPotentials(thiso[0,ii],thispot, 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: t - (optional) time at which to get the radius pot= potential instance or list of such instances OUTPUT: energy HISTORY: 2010-09-15 - Written - Bovy (NYU) 2011-04-18 - Added t - 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= RZToplanarPotential(pot) elif isinstance(pot,list): thispot= [] for p in pot: if isinstance(p,Potential): thispot.append(RZToplanarPotential(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], t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([_evaluateplanarPotentials(thispot,thiso[0,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: error message number (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 = RZToplanarPotential(pot) self.t = nu.array(t) self._pot = thispot self.orbit, msg = _integrateROrbit(self.vxvv, thispot, t, method, dt) return msg
def integrate_dxdv(self, dxdv, t, pot, method='dopr54_c'): """ 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, 'leapfrog' for a simple leapfrog implementation, 'leapfrog_c' for a simple leapfrog implemenation in C (if possible) OUTPUT: (none) (get the actual orbit using getOrbit_dxdv() HISTORY: 2010-10-17 - Written - Bovy (IAS) """ thispot = RZToplanarPotential(pot) self.t = nu.array(t) self._pot_dxdv = thispot if isinstance(pot, list): c_possible = True for p in pot: if not p.hasC: c_possible = False break else: c_possible = pot.hasC if '_c' in method and not c_possible: method = 'odeint' self.orbit_dxdv, msg = _integrateOrbit_dxdv(self.vxvv, dxdv, thispot, t, method) return msg
def integrate(self, t, pot, method='leapfrog_c'): """ 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 implemenation in C (if possible) 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 = RZToplanarPotential(pot) self.t = nu.array(t) self._pot = thispot if isinstance(pot, list): c_possible = True for p in pot: if not p.hasC: c_possible = False break else: c_possible = pot.hasC if '_c' in method and not c_possible: method = 'odeint' self.orbit, msg = _integrateOrbit(self.vxvv, thispot, t, method) return msg
def _setupaA(self, pot=None): """ NAME: _setupaA PURPOSE: set up an actionAngle module for this Orbit INPUT: pot - potential OUTPUT: HISTORY: 2010-11-30 - Written - Bovy (NYU) """ if pot is None: try: pot = self._pot except AttributeError: raise AttributeError("Integrate orbit or specify pot=") if isinstance(pot, Potential) or isinstance(pot, list): thispot = RZToplanarPotential(pot) else: thispot = pot if isinstance(thispot,LogarithmicHaloPotential) or \ (isinstance(thispot,planarPotentialFromRZPotential) and \ isinstance(thispot._RZPot,LogarithmicHaloPotential)): self._aA = actionAngle.actionAngleFlat(self.vxvv[0], self.vxvv[1], self.vxvv[2]) elif isinstance(thispot,KeplerPotential) or \ (isinstance(thispot,planarPotentialFromRZPotential) and \ isinstance(thispot._RZPot,KeplerPotential)): self._aA = actionAngle.actionAnglePower(self.vxvv[0], self.vxvv[1], self.vxvv[2], beta=-0.5) elif isinstance(thispot,PowerSphericalPotential) or \ (isinstance(thispot,planarPotentialFromRZPotential) and \ isinstance(thispot._RZPot,PowerSphericalPotential)): if isinstance(thispot,planarPotentialFromRZPotential) and \ isinstance(thispot._RZPot,PowerSphericalPotential): thispot = thispot._RZPot if thispot.alpha == 2.: self._aA = actionAngle.actionAngleFlat(self.vxvv[0], self.vxvv[1], self.vxvv[2]) else: self._aA = actionAngle.actionAnglePower(self.vxvv[0], self.vxvv[1], self.vxvv[2], beta=1. - thispot.alpha / 2.) else: self._aA = actionAngle.actionAngleAxi(self.vxvv[0], self.vxvv[1], self.vxvv[2], pot=thispot)
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 kwargs.has_key('pot') or kwargs['pot'] is None: try: pot = self._pot except AttributeError: raise AttributeError("Integrate orbit or specify pot=") if kwargs.has_key('pot') and kwargs['pot'] is None: kwargs.pop('pot') else: pot = kwargs['pot'] kwargs.pop('pot') if isinstance(pot, Potential): thispot = RZToplanarPotential(pot) elif isinstance(pot, list): thispot = [] for p in pot: if isinstance(p, Potential): thispot.append(RZToplanarPotential(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(thiso[0],thispot, phi=thiso[3],t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([evaluateplanarPotentials(thiso[0,ii],thispot, 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: t - (optional) time at which to get the radius pot= potential instance or list of such instances OUTPUT: energy HISTORY: 2010-09-15 - Written - Bovy (NYU) 2011-04-18 - Added t - 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 = RZToplanarPotential(pot) elif isinstance(pot, list): thispot = [] for p in pot: if isinstance(p, Potential): thispot.append(RZToplanarPotential(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], t=t)\ +thiso[1]**2./2.\ +thiso[2]**2./2. else: return nu.array([_evaluateplanarPotentials(thispot,thiso[0,ii], t=t[ii])\ +thiso[1,ii]**2./2.\ +thiso[2,ii]**2./2. for ii in range(len(t))])
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 = RZToplanarPotential(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