ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
CalcXdotGravityJ2J3.hpp
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16
17#ifndef CALC_XDOT_GRAVITY_J2_J3_HPP
18#define CALC_XDOT_GRAVITY_J2_J3_HPP
19
20#include "utils/Rates.hpp"
21
22#define XDOT_GRAVITY_J2_J3_STATES 6
23
24namespace clockwerk {
25
26 template <typename T>
27 class CalcXdotGravityJ2J3 : public clockwerk::Rates<T, XDOT_GRAVITY_J2_J3_STATES> {
28 public:
29 /// @brief Function to calculate rate of change in 6-element orbit position with J2, J3
30 /// @param time The reference time
31 /// @param state The state vector for the system as [x, y, z, xDot, yDot, zDot]
32 /// @param out_rates Implicit return of rates based on time, state as [xDot, yDot, zDot, xDDot, yDDot, zDDot]
33 int calculateRates(T time, const std::array<T, XDOT_GRAVITY_J2_J3_STATES> &state,
34 std::array<T, XDOT_GRAVITY_J2_J3_STATES> &out_rates);
35
36 /// @brief The gravitational parameter for the planet. Must be set prior to calculation
37 T mu;
38
39 /// @brief The J2 parameter for the planet. Must be set prior to calculation.
40 T J2;
41
42 /// @brief The J3 parameter for the planet. Must be set prior to calculation.
43 T J3;
44
45 /// @brief The reference radius for the planet. Must be set prior to calculation.
46 T R;
47 private:
48
49 };
50
51 template <typename T>
52 int CalcXdotGravityJ2J3<T>::calculateRates(T time, const std::array<T, XDOT_GRAVITY_J2_J3_STATES> &state,
53 std::array<T, XDOT_GRAVITY_J2_J3_STATES> &out_rates) {
54 // Precalculate some parameters
55 T muRR = mu*R*R;
56 T pc_j2 = muRR*J2;
57 T pc_j3 = muRR*J3*R;
58 T r = std::sqrt(state[0]*state[0] + state[1]*state[1] + state[2]*state[2]);
59 T r3 = r*r*r;
60 T r5 = r3*r*r;
61 T r7 = r5*r*r;
62 T r9 = r7*r*r;
63 T z2 = state[2]*state[2];
64
65 // Now precalc divided parameters
66 T mu_over_r3, pc_15_2_r7, pc_3_2_r5, pc_35_2_r9;
67 int err = clockwerk::safeDivide(-mu, r3, mu_over_r3); if(err) {return err;}
68 err = clockwerk::safeDivide(7.5*state[2], r7, pc_15_2_r7); if(err) {return err;}
69 err = clockwerk::safeDivide(1.5, r5, pc_3_2_r5); if(err) {return err;}
70 err = clockwerk::safeDivide(17.5*z2*state[2], r9, pc_35_2_r9); if(err) {return err;}
71
72 // Finally, actually calculate gravity
73 out_rates[0] = state[3];
74 out_rates[1] = state[4];
75 out_rates[2] = state[5];
76 // mu; J2; J3
77 out_rates[3] = mu_over_r3*state[0] +
78 pc_j2*(pc_15_2_r7*state[0]*state[2] - pc_3_2_r5*state[0]) +
79 pc_j3*(-pc_15_2_r7*state[0] + pc_35_2_r9*state[0]);
80 out_rates[4] = mu_over_r3*state[1] +
81 pc_j2*(pc_15_2_r7*state[1]*state[2] - pc_3_2_r5*state[1]) +
82 pc_j3*(-pc_15_2_r7*state[1] + pc_35_2_r9*state[1]);
83 out_rates[5] = mu_over_r3*state[2] +
84 pc_j2*(pc_15_2_r7*z2 - 3.0*pc_3_2_r5*state[2]) +
85 pc_j3*(-2.0*pc_15_2_r7*state[2] + pc_35_2_r9*state[2] + pc_3_2_r5);
86
87 return NO_ERROR;
88 }
89
90}
91
92#endif
#define XDOT_GRAVITY_J2_J3_STATES
Definition CalcXdotGravityJ2J3.hpp:22
Definition CalcXdotGravityJ2J3.hpp:27
T J2
The J2 parameter for the planet. Must be set prior to calculation.
Definition CalcXdotGravityJ2J3.hpp:40
int calculateRates(T time, const std::array< T, 6 > &state, std::array< T, 6 > &out_rates)
Function to calculate rate of change in 6-element orbit position with J2, J3.
Definition CalcXdotGravityJ2J3.hpp:52
T mu
The gravitational parameter for the planet. Must be set prior to calculation.
Definition CalcXdotGravityJ2J3.hpp:37
T R
The reference radius for the planet. Must be set prior to calculation.
Definition CalcXdotGravityJ2J3.hpp:46
T J3
The J3 parameter for the planet. Must be set prior to calculation.
Definition CalcXdotGravityJ2J3.hpp:43
Definition Rates.hpp:27
#define NO_ERROR
Definition clockwerkerrors.h:31