def a_d(t0, state, k, perturbations: Dict): """ Custom perturbation function that is passed directly to poliastro to be executed in their code, hence the need for summation() to be included within. Current structure allows user to pick and chose which perturbations they would like to include, requiring that the desired perturbation objects are created, filled, and passed. Note: To improve upon existing perturbation functions or to add more, everything must be self-contained within the function. :param t0: Required by poliastro :param state: Required by poliastro :param k: Required by poliastro (gravitational parameter-mu) :param perturbations: Dictionary of perturbations desired by the user. Keys correspond to the perturbations Enum class in Enum.py, while values correspond to objects in the dto.py class. :return: Returns a force that describes the impact of all desired perturbations """ fun = [] if Perturbations.J2 in perturbations: perturbation = perturbations.get(Perturbations.J2) fun.append(J2_perturbation(t0, state, k, perturbation.J2, perturbation.R)) if Perturbations.Drag in perturbations: perturbation = perturbations.get(Perturbations.Drag) fun.append(atmospheric_drag(t0, state, k, perturbation.R, perturbation.C_D, perturbation.A, perturbation.m, perturbation.H0, perturbation.rho0)) if Perturbations.J3 in perturbations: perturbation = perturbations.get(Perturbations.J3) fun.append(J3_perturbation(t0, state, k, perturbation.J3, perturbation.R)) if Perturbations.SRP in perturbations: perturbation = perturbations.get(Perturbations.SRP) fun.append(radiation_pressure(t0, state, k, perturbation.R, perturbation.C_R, perturbation.A, perturbation.m, perturbation.Wdivc_s, perturbation.star)) if Perturbations.Moon in perturbations: perturbation = perturbations.get(Perturbations.Moon) fun.append(third_body(t0, state, k, perturbation.k_third, perturbation.third_body)) if Perturbations.Sun in perturbations: perturbation = perturbations.get(Perturbations.Sun) fun.append(third_body(t0, state, k, perturbation.k_third, perturbation.third_body)) def summation(arr): if len(arr) == 0: return np.zeros(3) output = arr[0] for i in range(1, len(arr)): output += arr[i] return output return summation(fun)
def f(t0, u_, k): du_kep = func_twobody(t0, u_, k) ax, ay, az = third_body( t0, u_, k, k_third=body.k.to(u.km**3 / u.s**2).value, perturbation_body=body_r, ) du_ad = np.array([0, 0, 0, ax, ay, az]) return du_kep + du_ad