def _rectForce(x, pot, t=0.): """ NAME: _rectForce PURPOSE: returns the force in the rectangular frame INPUT: x - current position t - current time pot - (list of) Potential instance(s) OUTPUT: force HISTORY: 2011-02-02 - Written - Bovy (NYU) """ #x is rectangular so calculate R and phi R = nu.sqrt(x[0]**2. + x[1]**2.) phi = nu.arccos(x[0] / R) sinphi = x[1] / R cosphi = x[0] / R if x[1] < 0.: phi = 2. * nu.pi - phi #calculate forces Rforce = _evaluateRforces(pot, R, x[2], phi=phi, t=t) phiforce = _evaluatephiforces(pot, R, x[2], phi=phi, t=t) return nu.array([ cosphi * Rforce - 1. / R * sinphi * phiforce, sinphi * Rforce + 1. / R * cosphi * phiforce, _evaluatezforces(pot, R, x[2], phi=phi, t=t) ])
def _FullEOM(y, t, pot): """ NAME: _FullEOM PURPOSE: implements the EOM, i.e., the right-hand side of the differential equation INPUT: y - current phase-space position t - current time pot - (list of) Potential instance(s) OUTPUT: dy/dt HISTORY: 2010-04-16 - Written - Bovy (NYU) """ l2 = (y[0]**2. * y[3])**2. return [ y[1], l2 / y[0]**3. + _evaluateRforces( pot, y[0], y[4], phi=y[2], t=t, v=[y[1], y[0] * y[3], y[5]]), y[3], 1. / y[0]**2. * (_evaluatephiforces( pot, y[0], y[4], phi=y[2], t=t, v=[y[1], y[0] * y[3], y[5]]) - 2. * y[0] * y[1] * y[3]), y[5], _evaluatezforces(pot, y[0], y[4], phi=y[2], t=t, v=[y[1], y[0] * y[3], y[5]]) ]
def estimateDeltaStaeckel(pot, R, z, no_median=False): """ NAME: estimateDeltaStaeckel PURPOSE: Estimate a good value for delta using eqn. (9) in Sanders (2012) INPUT: pot - Potential instance or list thereof R,z- coordinates (if these are arrays, the median estimated delta is returned, i.e., if this is an orbit) no_median - (False) if True, and input is array, return all calculated values of delta (useful for quickly estimating delta for many phase space points) OUTPUT: delta HISTORY: 2013-08-28 - Written - Bovy (IAS) 2016-02-20 - Changed input order to allow physical conversions - Bovy (UofT) """ if isinstance(R, nu.ndarray): delta2 = nu.array([ ( z[ii]**2. - R[ii]**2. #eqn. (9) has a sign error + (3. * R[ii] * _evaluatezforces(pot, R[ii], z[ii]) - 3. * z[ii] * _evaluateRforces(pot, R[ii], z[ii]) + R[ii] * z[ii] * (evaluateR2derivs(pot, R[ii], z[ii], use_physical=False) - evaluatez2derivs(pot, R[ii], z[ii], use_physical=False))) / evaluateRzderivs(pot, R[ii], z[ii], use_physical=False)) for ii in range(len(R)) ]) indx = (delta2 < 0.) * (delta2 > -10.**-10.) delta2[indx] = 0. if not no_median: delta2 = nu.median(delta2[True ^ nu.isnan(delta2)]) else: delta2 = ( z**2. - R**2. #eqn. (9) has a sign error + (3. * R * _evaluatezforces(pot, R, z) - 3. * z * _evaluateRforces(pot, R, z) + R * z * (evaluateR2derivs(pot, R, z, use_physical=False) - evaluatez2derivs(pot, R, z, use_physical=False))) / evaluateRzderivs(pot, R, z, use_physical=False)) if delta2 < 0. and delta2 > -10.**-10.: delta2 = 0. return nu.sqrt(delta2)
def estimateDeltaStaeckel(pot,R,z, no_median=False): """ NAME: estimateDeltaStaeckel PURPOSE: Estimate a good value for delta using eqn. (9) in Sanders (2012) INPUT: pot - Potential instance or list thereof R,z- coordinates (if these are arrays, the median estimated delta is returned, i.e., if this is an orbit) no_median - (False) if True, and input is array, return all calculated values of delta (useful for quickly estimating delta for many phase space points) OUTPUT: delta HISTORY: 2013-08-28 - Written - Bovy (IAS) 2016-02-20 - Changed input order to allow physical conversions - Bovy (UofT) """ if isinstance(R,nu.ndarray): delta2= nu.array([(z[ii]**2.-R[ii]**2. #eqn. (9) has a sign error +(3.*R[ii]*_evaluatezforces(pot,R[ii],z[ii]) -3.*z[ii]*_evaluateRforces(pot,R[ii],z[ii]) +R[ii]*z[ii]*(evaluateR2derivs(pot,R[ii],z[ii], use_physical=False) -evaluatez2derivs(pot,R[ii],z[ii], use_physical=False)))/evaluateRzderivs(pot,R[ii],z[ii],use_physical=False)) for ii in range(len(R))]) indx= (delta2 < 0.)*(delta2 > -10.**-10.) delta2[indx]= 0. if not no_median: delta2= nu.median(delta2[True^nu.isnan(delta2)]) else: delta2= (z**2.-R**2. #eqn. (9) has a sign error +(3.*R*_evaluatezforces(pot,R,z) -3.*z*_evaluateRforces(pot,R,z) +R*z*(evaluateR2derivs(pot,R,z,use_physical=False) -evaluatez2derivs(pot,R,z,use_physical=False)))/evaluateRzderivs(pot,R,z,use_physical=False)) if delta2 < 0. and delta2 > -10.**-10.: delta2= 0. return nu.sqrt(delta2)
def FRStaeckel(u, v, pot, delta): #pragma: no cover because unused """ NAME: FRStaeckel PURPOSE: return the radial force INPUT: u - confocal u v - confocal v pot - potential delta - focus OUTPUT: FR(u,v) HISTORY: 2012-11-30 - Written - Bovy (IAS) """ R, z = bovy_coords.uv_to_Rz(u, v, delta=delta) return _evaluateRforces(pot, R, z)
def FRStaeckel(u,v,pot,delta): #pragma: no cover because unused """ NAME: FRStaeckel PURPOSE: return the radial force INPUT: u - confocal u v - confocal v pot - potential delta - focus OUTPUT: FR(u,v) HISTORY: 2012-11-30 - Written - Bovy (IAS) """ R,z= bovy_coords.uv_to_Rz(u,v,delta=delta) return _evaluateRforces(pot,R,z)
def _RZEOM(y,t,pot,l2): """ NAME: _RZEOM PURPOSE: implements the EOM, i.e., the right-hand side of the differential equation INPUT: y - current phase-space position t - current time pot - (list of) Potential instance(s) l2 - angular momentum squared OUTPUT: dy/dt HISTORY: 2010-04-16 - Written - Bovy (NYU) """ return [y[1], l2/y[0]**3.+_evaluateRforces(pot,y[0],y[2],t=t), y[3], _evaluatezforces(pot,y[0],y[2],t=t)]
def _RZEOM(y, t, pot, l2): """ NAME: _RZEOM PURPOSE: implements the EOM, i.e., the right-hand side of the differential equation INPUT: y - current phase-space position t - current time pot - (list of) Potential instance(s) l2 - angular momentum squared OUTPUT: dy/dt HISTORY: 2010-04-16 - Written - Bovy (NYU) """ return [ y[1], l2 / y[0]**3. + _evaluateRforces(pot, y[0], y[2], t=t), y[3], _evaluatezforces(pot, y[0], y[2], t=t) ]