1   /* Copyright 2002-2021 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.analytical.tle;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.util.FastMath;
21  import org.hipparchus.util.FieldSinCos;
22  import org.orekit.annotation.DefaultDataContext;
23  import org.orekit.attitudes.AttitudeProvider;
24  import org.orekit.data.DataContext;
25  import org.orekit.frames.Frame;
26  
27  /** This class contains methods to compute propagated coordinates with the SGP4 model.
28   * <p>
29   * The user should not bother in this class since it is handled internaly by the
30   * {@link TLEPropagator}.
31   * </p>
32   * <p>This implementation is largely inspired from the paper and source code <a
33   * href="https://www.celestrak.com/publications/AIAA/2006-6753/">Revisiting Spacetrack
34   * Report #3</a> and is fully compliant with its results and tests cases.</p>
35   * @author Felix R. Hoots, Ronald L. Roehrich, December 1980 (original fortran)
36   * @author David A. Vallado, Paul Crawford, Richard Hujsak, T.S. Kelso (C++ translation and improvements)
37   * @author Fabien Maussion (java translation)
38   * @author Thomas Paulet (field translation)
39   * @since 11.0
40   */
41  public class FieldSGP4<T extends CalculusFieldElement<T>> extends FieldTLEPropagator<T> {
42  
43      /** If perige is less than 220 km, some calculus are avoided. */
44      private boolean lessThan220;
45  
46      /** (1 + eta * cos(M0))³. */
47      private T delM0;
48  
49      // CHECKSTYLE: stop JavadocVariable check
50      private T d2;
51      private T d3;
52      private T d4;
53      private T t3cof;
54      private T t4cof;
55      private T t5cof;
56      private T sinM0;
57      private T omgcof;
58      private T xmcof;
59      private T c5;
60      // CHECKSTYLE: resume JavadocVariable check
61  
62      /** Constructor for a unique initial TLE.
63       *
64       * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
65       *
66       * @param initialTLE the TLE to propagate.
67       * @param attitudeProvider provider for attitude computation
68       * @param mass spacecraft mass (kg)
69       * @param parameters SGP4 and SDP4 model parameters
70       * @see #FieldSGP4(FieldTLE, AttitudeProvider, CalculusFieldElement, Frame, CalculusFieldElement[])
71       */
72      @DefaultDataContext
73      public FieldSGP4(final FieldTLE<T> initialTLE, final AttitudeProvider attitudeProvider,
74                  final T mass, final T[] parameters) {
75          this(initialTLE, attitudeProvider, mass,
76                  DataContext.getDefault().getFrames().getTEME(), parameters);
77      }
78  
79      /** Constructor for a unique initial TLE.
80       * @param initialTLE the TLE to propagate.
81       * @param attitudeProvider provider for attitude computation
82       * @param mass spacecraft mass (kg)
83       * @param teme the TEME frame to use for propagation.
84       * @param parameters SGP4 and SDP4 model parameters
85       */
86      public FieldSGP4(final FieldTLE<T> initialTLE,
87                  final AttitudeProvider attitudeProvider,
88                  final T mass,
89                  final Frame teme,
90                  final T[] parameters) {
91          super(initialTLE, attitudeProvider, mass, teme, parameters);
92      }
93  
94      /** Initialization proper to each propagator (SGP or SDP).
95       * @param parameters model parameters
96       */
97      protected void sxpInitialize(final T[] parameters) {
98  
99          final T bStar = parameters[0];
100         // For perigee less than 220 kilometers, the equations are truncated to
101         // linear variation in sqrt a and quadratic variation in mean anomaly.
102         // Also, the c3 term, the delta omega term, and the delta m term are dropped.
103         lessThan220 = perige.getReal() < 220;
104         if (!lessThan220) {
105             final FieldSinCos<T> scM0 = FastMath.sinCos(tle.getMeanAnomaly());
106             final T c1sq = c1.multiply(c1);
107             delM0 = eta.multiply(scM0.cos()).add(1.0);
108             delM0 = delM0.multiply(delM0).multiply(delM0);
109             d2 = a0dp.multiply(tsi).multiply(c1sq).multiply(4.0);
110             final T temp = d2.multiply(tsi).multiply(c1).divide(3.0);
111             d3 = a0dp.multiply(17.0).add(s4).multiply(temp);
112             d4 = temp.multiply(0.5).multiply(a0dp).multiply(tsi).multiply(a0dp.multiply(221.0).add(s4.multiply(31.0))).multiply(c1);
113             t3cof = d2.add(c1sq.multiply(2));
114             t4cof = d3.multiply(3.0).add(c1.multiply(d2.multiply(12.0).add(c1sq.multiply(10)))).multiply(0.25);
115             t5cof = d4.multiply(3.0).add(c1.multiply(12.0).multiply(d3)).add(
116                     d2.multiply(d2).multiply(6.0)).add(c1sq.multiply(15.0).multiply(d2.multiply(2).add(c1sq))).multiply(0.2);
117             sinM0 = scM0.sin();
118             if (tle.getE().getReal() < 1e-4) {
119                 omgcof = c1sq.getField().getZero();
120                 xmcof = c1sq.getField().getZero();
121             } else  {
122                 final T c3 = coef.multiply(tsi).multiply(xn0dp).multiply(TLEConstants.A3OVK2 * TLEConstants.NORMALIZED_EQUATORIAL_RADIUS).multiply(sini0.divide(tle.getE()));
123                 xmcof = coef.multiply(bStar).divide(eeta).multiply(-TLEConstants.TWO_THIRD * TLEConstants.NORMALIZED_EQUATORIAL_RADIUS);
124                 omgcof = bStar.multiply(c3).multiply(FastMath.cos(tle.getPerigeeArgument()));
125             }
126         }
127 
128         c5 = coef1.multiply(2).multiply(a0dp).multiply(beta02).multiply(etasq.add(eeta).multiply(2.75).add(eeta.multiply(etasq)).add(1));
129         // initialized
130     }
131 
132     /** Propagation proper to each propagator (SGP or SDP).
133      * @param tSince the offset from initial epoch (min)
134      * @param parameters model parameters
135      */
136     protected void sxpPropagate(final T tSince, final T[] parameters) {
137 
138         // Update for secular gravity and atmospheric drag.
139         final T bStar = parameters[0];
140         final T xmdf = tle.getMeanAnomaly().add(xmdot.multiply(tSince));
141         final T omgadf = tle.getPerigeeArgument().add(omgdot.multiply(tSince));
142         final T xn0ddf = tle.getRaan().add(xnodot.multiply(tSince));
143         omega = omgadf;
144         T xmp = xmdf;
145         final T tsq = tSince.multiply(tSince);
146         xnode = xn0ddf.add(xnodcf.multiply(tsq));
147         T tempa = c1.multiply(tSince).negate().add(1.0);
148         T tempe = bStar.multiply(c4).multiply(tSince);
149         T templ = t2cof.multiply(tsq);
150 
151         if (!lessThan220) {
152             final T delomg = omgcof.multiply(tSince);
153             T delm = eta.multiply(FastMath.cos(xmdf)).add(1.0);
154             delm = xmcof.multiply(delm.multiply(delm).multiply(delm).subtract(delM0));
155             final T temp = delomg.add(delm);
156             xmp = xmdf.add(temp);
157             omega = omgadf.subtract(temp);
158             final T tcube = tsq.multiply(tSince);
159             final T tfour = tSince.multiply(tcube);
160             tempa = tempa.subtract(d2.multiply(tsq)).subtract(d3.multiply(tcube)).subtract(d4.multiply(tfour));
161             tempe = tempe.add(bStar.multiply(c5).multiply(FastMath.sin(xmp).subtract(sinM0)));
162             templ = templ.add(t3cof.multiply(tcube)).add(tfour.multiply(t4cof.add(tSince.multiply(t5cof))));
163         }
164 
165         a = a0dp.multiply(tempa).multiply(tempa);
166         e = tle.getE().subtract(tempe);
167 
168         // A highly arbitrary lower limit on e,  of 1e-6:
169         if (e.getReal() < 1e-6) {
170             e = e.getField().getZero().add(1e-6);
171         }
172 
173         xl = xmp.add(omega).add(xnode).add(xn0dp.multiply(templ));
174 
175         i = tle.getI();
176 
177     }
178 
179 }