def integrateFullOrbit_c(pot, yo, t, int_method, rtol=None, atol=None): """ NAME: integrateFullOrbit_c PURPOSE: C integrate an ode for a FullOrbit INPUT: pot - Potential or list of such instances yo - initial condition [q,p] t - set of times at which one wants the result int_method= 'leapfrog_c', 'rk4_c', 'rk6_c', 'symplec4_c' rtol, atol OUTPUT: (y,err) y : array, shape (len(y0), len(t)) Array containing the value of y for each desired time in t, \ with the initial value y0 in the first row. err: error message, if not zero: 1 means maximum step reduction happened for adaptive integrators HISTORY: 2011-11-13 - Written - Bovy (IAS) """ rtol, atol = _parse_tol(rtol, atol) npot, pot_type, pot_args = _parse_pot(pot) int_method_c = _parse_integrator(int_method) #Set up result array result = nu.empty((len(t), 6)) err = ctypes.c_int(0) #Set up the C code ndarrayFlags = ('C_CONTIGUOUS', 'WRITEABLE') integrationFunc = _lib.integrateFullOrbit integrationFunc.argtypes = [ ndpointer(dtype=nu.float64, flags=ndarrayFlags), ctypes.c_int, ndpointer(dtype=nu.float64, flags=ndarrayFlags), ctypes.c_int, ndpointer(dtype=nu.int32, flags=ndarrayFlags), ndpointer(dtype=nu.float64, flags=ndarrayFlags), ctypes.c_double, ctypes.c_double, ndpointer(dtype=nu.float64, flags=ndarrayFlags), ctypes.POINTER(ctypes.c_int), ctypes.c_int ] #Array requirements, first store old order f_cont = [yo.flags['F_CONTIGUOUS'], t.flags['F_CONTIGUOUS']] yo = nu.require(yo, dtype=nu.float64, requirements=['C', 'W']) t = nu.require(t, dtype=nu.float64, requirements=['C', 'W']) result = nu.require(result, dtype=nu.float64, requirements=['C', 'W']) #Run the C code integrationFunc(yo, ctypes.c_int(len(t)), t, ctypes.c_int(npot), pot_type, pot_args, ctypes.c_double(rtol), ctypes.c_double(atol), result, ctypes.byref(err), ctypes.c_int(int_method_c)) #Reset input arrays if f_cont[0]: yo = nu.asfortranarray(yo) if f_cont[1]: t = nu.asfortranarray(t) return (result, err.value)
def integrateFullOrbit_dxdv_c(pot,yo,dyo,t,int_method,rtol=None,atol=None): #pragma: no cover because not included in v1, uncover when included """ NAME: integrateFullOrbit_dxdv_c PURPOSE: C integrate an ode for a planarOrbit+phase space volume dxdv INPUT: pot - Potential or list of such instances yo - initial condition [q,p] dyo - initial condition [dq,dp] t - set of times at which one wants the result int_method= 'leapfrog_c', 'rk4_c', 'rk6_c', 'symplec4_c' rtol, atol OUTPUT: (y,err) y : array, shape (len(y0), len(t)) Array containing the value of y for each desired time in t, \ with the initial value y0 in the first row. err: error message if not zero, 1: maximum step reduction happened for adaptive integrators HISTORY: 2011-11-13 - Written - Bovy (IAS) """ rtol, atol= _parse_tol(rtol,atol) npot, pot_type, pot_args= _parse_pot(pot) int_method_c= _parse_integrator(int_method) yo= nu.concatenate((yo,dyo)) #Set up result array result= nu.empty((len(t),12)) err= ctypes.c_int(0) #Set up the C code ndarrayFlags= ('C_CONTIGUOUS','WRITEABLE') integrationFunc= _lib.integrateFullOrbit_dxdv integrationFunc.argtypes= [ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.c_int, ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.c_int, ndpointer(dtype=nu.int32,flags=ndarrayFlags), ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.c_double, ctypes.c_double, ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.POINTER(ctypes.c_int), ctypes.c_int] #Array requirements, first store old order f_cont= [yo.flags['F_CONTIGUOUS'], t.flags['F_CONTIGUOUS']] yo= nu.require(yo,dtype=nu.float64,requirements=['C','W']) t= nu.require(t,dtype=nu.float64,requirements=['C','W']) result= nu.require(result,dtype=nu.float64,requirements=['C','W']) #Run the C code integrationFunc(yo, ctypes.c_int(len(t)), t, ctypes.c_int(npot), pot_type, pot_args, ctypes.c_double(rtol),ctypes.c_double(atol), result, ctypes.byref(err), ctypes.c_int(int_method_c)) #Reset input arrays if f_cont[0]: yo= nu.asfortranarray(yo) if f_cont[1]: t= nu.asfortranarray(t) return (result,err.value)
def integrateFullOrbit_c(pot,yo,t,int_method,rtol=None,atol=None,dt=None): """ NAME: integrateFullOrbit_c PURPOSE: C integrate an ode for a FullOrbit INPUT: pot - Potential or list of such instances yo - initial condition [q,p] t - set of times at which one wants the result int_method= 'leapfrog_c', 'rk4_c', 'rk6_c', 'symplec4_c' rtol, atol dt= (None) force integrator to use this stepsize (default is to automatically determine one)) OUTPUT: (y,err) y : array, shape (len(y0), len(t)) Array containing the value of y for each desired time in t, \ with the initial value y0 in the first row. err: error message, if not zero: 1 means maximum step reduction happened for adaptive integrators HISTORY: 2011-11-13 - Written - Bovy (IAS) """ rtol, atol= _parse_tol(rtol,atol) npot, pot_type, pot_args= _parse_pot(pot) int_method_c= _parse_integrator(int_method) if dt is None: dt= -9999.99 #Set up result array result= nu.empty((len(t),6)) err= ctypes.c_int(0) #Set up the C code ndarrayFlags= ('C_CONTIGUOUS','WRITEABLE') integrationFunc= _lib.integrateFullOrbit integrationFunc.argtypes= [ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.c_int, ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.c_int, ndpointer(dtype=nu.int32,flags=ndarrayFlags), ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.c_double, ctypes.c_double, ctypes.c_double, ndpointer(dtype=nu.float64,flags=ndarrayFlags), ctypes.POINTER(ctypes.c_int), ctypes.c_int] #Array requirements, first store old order f_cont= [yo.flags['F_CONTIGUOUS'], t.flags['F_CONTIGUOUS']] yo= nu.require(yo,dtype=nu.float64,requirements=['C','W']) t= nu.require(t,dtype=nu.float64,requirements=['C','W']) result= nu.require(result,dtype=nu.float64,requirements=['C','W']) #Run the C code integrationFunc(yo, ctypes.c_int(len(t)), t, ctypes.c_int(npot), pot_type, pot_args, ctypes.c_double(dt), ctypes.c_double(rtol),ctypes.c_double(atol), result, ctypes.byref(err), ctypes.c_int(int_method_c)) #Reset input arrays if f_cont[0]: yo= nu.asfortranarray(yo) if f_cont[1]: t= nu.asfortranarray(t) return (result,err.value)