1   /* Copyright 2002-2025 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.propagation.semianalytical.dsst.forces;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.bodies.CelestialBody;
23  import org.orekit.propagation.semianalytical.dsst.utilities.FieldAuxiliaryElements;
24  
25  /**
26   * This class is a container for the common "field" parameters used in {@link DSSTThirdBody}.
27   * <p>
28   * It performs parameters initialization at each integration step for the third
29   * body attraction perturbation. These parameters change for each integration
30   * step.
31   * </p>
32   * @author Bryan Cazabonne
33   * @since 12.0
34   * @param <T> type of the field elements
35   */
36  public class FieldDSSTThirdBodyDynamicContext<T extends CalculusFieldElement<T>> extends FieldForceModelContext<T> {
37  
38      /** Standard gravitational parameter μ for the body in m³/s². */
39      private T gm;
40  
41      /** Distance from center of mass of the central body to the 3rd body. */
42      private T R3;
43  
44      /** A = sqrt(μ * a). */
45      private T A;
46  
47      /** α. */
48      private T alpha;
49  
50      /** β. */
51      private T beta;
52  
53      /** γ. */
54      private T gamma;
55  
56      /** B². */
57      private T BB;
58  
59      /** B³. */
60      private T BBB;
61  
62      /** &Chi; = 1 / sqrt(1 - e²) = 1 / B. */
63      private T X;
64  
65      /** &Chi;². */
66      private T XX;
67  
68      /** &Chi;³. */
69      private T XXX;
70  
71      /** -2 * a / A. */
72      private T m2aoA;
73  
74      /** B / A. */
75      private T BoA;
76  
77      /** 1 / (A * B). */
78      private T ooAB;
79  
80      /** -C / (2 * A * B). */
81      private T mCo2AB;
82  
83      /** B / A(1 + B). */
84      private T BoABpo;
85  
86      /** mu3 / R3. */
87      private T muoR3;
88  
89      /** b = 1 / (1 + sqrt(1 - e²)) = 1 / (1 + B).*/
90      private T b;
91  
92      /** h * &Chi;³. */
93      private T hXXX;
94  
95      /** k * &Chi;³. */
96      private T kXXX;
97  
98      /** Keplerian mean motion. */
99      private T motion;
100 
101     /** Constructor.
102      * @param aux auxiliary elements related to the current orbit
103      * @param body body the 3rd body to consider
104      * @param parameters values of the force model parameters
105      */
106     public FieldDSSTThirdBodyDynamicContext(final FieldAuxiliaryElements<T> aux,
107                                             final CelestialBody body,
108                                             final T[] parameters) {
109 
110         super(aux);
111 
112         // Parameters related to force model drivers
113         final T mu = parameters[1];
114         A = FastMath.sqrt(mu.multiply(aux.getSma()));
115         this.gm = parameters[0];
116         final T absA = FastMath.abs(aux.getSma());
117         motion = FastMath.sqrt(mu.divide(absA)).divide(absA);
118 
119         // Distance from center of mass of the central body to the 3rd body
120         final FieldVector3D<T> bodyPos = body.getPVCoordinates(aux.getDate(), aux.getFrame()).getPosition();
121         R3 = bodyPos.getNorm();
122 
123         // Direction cosines
124         final FieldVector3D<T> bodyDir = bodyPos.normalize();
125         alpha = bodyDir.dotProduct(aux.getVectorF());
126         beta  = bodyDir.dotProduct(aux.getVectorG());
127         gamma = bodyDir.dotProduct(aux.getVectorW());
128 
129         // &Chi;<sup>-2</sup>.
130         BB = aux.getB().multiply(aux.getB());
131         // &Chi;<sup>-3</sup>.
132         BBB = BB.multiply(aux.getB());
133 
134         // b = 1 / (1 + B)
135         b = aux.getB().add(1.).reciprocal();
136 
137         // &Chi;
138         X = aux.getB().reciprocal();
139         XX = X.square();
140         XXX = X.multiply(XX);
141         // -2 * a / A
142         m2aoA = aux.getSma().multiply(-2.).divide(A);
143         // B / A
144         BoA = aux.getB().divide(A);
145         // 1 / AB
146         ooAB = (A.multiply(aux.getB())).reciprocal();
147         // -C / 2AB
148         mCo2AB = aux.getC().multiply(ooAB).divide(2.).negate();
149         // B / A(1 + B)
150         BoABpo = BoA.divide(aux.getB().add(1.));
151 
152         // mu3 / R3
153         muoR3 = R3.divide(gm).reciprocal();
154 
155         // h * &Chi;³
156         hXXX = XXX.multiply(aux.getH());
157         // k * &Chi;³
158         kXXX = XXX.multiply(aux.getK());
159 
160     }
161 
162     /** Get A = sqrt(μ * a).
163      * @return A
164      */
165     public T getA() {
166         return A;
167     }
168 
169     /** Get the distance from center of mass of the central body to the 3rd body.
170      * @return the distance from center of mass of the central body to the 3rd body
171      */
172     public T getR3() {
173         return R3;
174     }
175 
176     /** Get direction cosine α for central body.
177      * @return α
178      */
179     public T getAlpha() {
180         return alpha;
181     }
182 
183     /** Get direction cosine β for central body.
184      * @return β
185      */
186     public T getBeta() {
187         return beta;
188     }
189 
190     /** Get direction cosine γ for central body.
191      * @return γ
192      */
193     public T getGamma() {
194         return gamma;
195     }
196 
197     /** Get B².
198      * @return B²
199      */
200     public T getBB() {
201         return BB;
202     }
203 
204     /** Get B³.
205      * @return B³
206      */
207     public T getBBB() {
208         return BBB;
209     }
210 
211     /** Get b = 1 / (1 + sqrt(1 - e²)) = 1 / (1 + B).
212      * @return b
213      */
214     public T getb() {
215         return b;
216     }
217 
218     /** Get &Chi; = 1 / sqrt(1 - e²) = 1 / B.
219      * @return &Chi;
220      */
221     public T getX() {
222         return X;
223     }
224 
225     /** Get &Chi;².
226      * @return &Chi;²
227      */
228     public T getXX() {
229         return XX;
230     }
231 
232     /** Get m2aoA = -2 * a / A.
233      * @return m2aoA
234      */
235     public T getM2aoA() {
236         return m2aoA;
237     }
238 
239     /** Get B / A.
240      * @return BoA
241      */
242     public T getBoA() {
243         return BoA;
244     }
245 
246     /** Get ooAB = 1 / (A * B).
247      * @return ooAB
248      */
249     public T getOoAB() {
250         return ooAB;
251     }
252 
253     /** Get mCo2AB = -C / 2AB.
254      * @return mCo2AB
255      */
256     public T getMCo2AB() {
257         return mCo2AB;
258     }
259 
260     /** Get BoABpo = B / A(1 + B).
261      * @return BoABpo
262      */
263     public T getBoABpo() {
264         return BoABpo;
265     }
266 
267     /** Get muoR3 = mu3 / R3.
268      * @return muoR3
269      */
270     public T getMuoR3() {
271         return muoR3;
272     }
273 
274     /** Get hXXX = h * &Chi;³.
275      * @return hXXX
276      */
277     public T getHXXX() {
278         return hXXX;
279     }
280 
281     /** Get kXXX = h * &Chi;³.
282      * @return kXXX
283      */
284     public T getKXXX() {
285         return kXXX;
286     }
287 
288     /** Get the Keplerian mean motion.
289      * <p>The Keplerian mean motion is computed directly from semi major axis
290      * and central acceleration constant.</p>
291      * @return Keplerian mean motion in radians per second
292      */
293     public T getMeanMotion() {
294         return motion;
295     }
296 
297 }