1   /* Copyright 2002-2026 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 java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.hipparchus.geometry.euclidean.threed.Vector3D;
24  import org.hipparchus.linear.RealMatrix;
25  import org.hipparchus.util.FastMath;
26  import org.hipparchus.util.MathUtils;
27  import org.hipparchus.util.Pair;
28  import org.hipparchus.util.SinCos;
29  import org.orekit.annotation.DefaultDataContext;
30  import org.orekit.attitudes.Attitude;
31  import org.orekit.attitudes.AttitudeProvider;
32  import org.orekit.attitudes.FrameAlignedProvider;
33  import org.orekit.data.DataContext;
34  import org.orekit.errors.OrekitException;
35  import org.orekit.errors.OrekitMessages;
36  import org.orekit.frames.Frame;
37  import org.orekit.orbits.CartesianOrbit;
38  import org.orekit.orbits.Orbit;
39  import org.orekit.propagation.AbstractMatricesHarvester;
40  import org.orekit.propagation.MatricesHarvester;
41  import org.orekit.propagation.SpacecraftState;
42  import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
43  import org.orekit.propagation.analytical.tle.generation.FixedPointTleGenerationAlgorithm;
44  import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
45  import org.orekit.time.AbsoluteDate;
46  import org.orekit.time.TimeScale;
47  import org.orekit.utils.DoubleArrayDictionary;
48  import org.orekit.utils.PVCoordinates;
49  import org.orekit.utils.ParameterDriver;
50  import org.orekit.utils.TimeSpanMap;
51  import org.orekit.utils.TimeSpanMap.Span;
52  
53  /** This class provides elements to propagate TLE's.
54   * <p>
55   * The models used are SGP4 and SDP4, initially proposed by NORAD as the unique convenient
56   * propagator for TLE's. Inputs and outputs of this propagator are only suited for
57   * NORAD two lines elements sets, since it uses estimations and mean values appropriate
58   * for TLE's only.
59   * </p>
60   * <p>
61   * Deep- or near- space propagator is selected internally according to NORAD recommendations
62   * so that the user has not to worry about the used computation methods. One instance is created
63   * for each TLE (this instance can only be get using {@link #selectExtrapolator(TLE)} method,
64   * and can compute {@link PVCoordinates position and velocity coordinates} at any
65   * time. Maximum accuracy is guaranteed in a 24h range period before and after the provided
66   * TLE epoch (of course this accuracy is not really measurable nor predictable: according to
67   * <a href="https://www.celestrak.com/">CelesTrak</a>, the precision is close to one kilometer
68   * and error won't probably rise above 2 km).
69   * </p>
70   * <p>This implementation is largely inspired from the paper and source code <a
71   * href="https://www.celestrak.com/publications/AIAA/2006-6753/">Revisiting Spacetrack
72   * Report #3</a> and is fully compliant with its results and tests cases.</p>
73   * @author Felix R. Hoots, Ronald L. Roehrich, December 1980 (original fortran)
74   * @author David A. Vallado, Paul Crawford, Richard Hujsak, T.S. Kelso (C++ translation and improvements)
75   * @author Fabien Maussion (java translation)
76   * @see TLE
77   */
78  public abstract class TLEPropagator extends AbstractAnalyticalPropagator {
79  
80      // CHECKSTYLE: stop VisibilityModifier check
81  
82      /** Initial state. */
83      protected TLE tle;
84  
85      /** UTC time scale. */
86      protected final TimeScale utc;
87  
88      /** final RAAN. */
89      protected double xnode;
90  
91      /** final semi major axis. */
92      protected double a;
93  
94      /** final eccentricity. */
95      protected double e;
96  
97      /** final inclination. */
98      protected double i;
99  
100     /** final perigee argument. */
101     protected double omega;
102 
103     /** L from SPTRCK #3. */
104     protected double xl;
105 
106     /** original recovered semi major axis. */
107     protected double a0dp;
108 
109     /** original recovered mean motion. */
110     protected double xn0dp;
111 
112     /** cosinus original inclination. */
113     protected double cosi0;
114 
115     /** cos io squared. */
116     protected double theta2;
117 
118     /** sinus original inclination. */
119     protected double sini0;
120 
121     /** common parameter for mean anomaly (M) computation. */
122     protected double xmdot;
123 
124     /** common parameter for perigee argument (omega) computation. */
125     protected double omgdot;
126 
127     /** common parameter for raan (OMEGA) computation. */
128     protected double xnodot;
129 
130     /** original eccentricity squared. */
131     protected double e0sq;
132     /** 1 - e2. */
133     protected double beta02;
134 
135     /** sqrt (1 - e2). */
136     protected double beta0;
137 
138     /** perigee, expressed in KM and ALTITUDE. */
139     protected double perige;
140 
141     /** eta squared. */
142     protected double etasq;
143 
144     /** original eccentricity * eta. */
145     protected double eeta;
146 
147     /** s* new value for the contant s. */
148     protected double s4;
149 
150     /** tsi from SPTRCK #3. */
151     protected double tsi;
152 
153     /** eta from SPTRCK #3. */
154     protected double eta;
155 
156     /** coef for SGP C3 computation. */
157     protected double coef;
158 
159     /** coef for SGP C5 computation. */
160     protected double coef1;
161 
162     /** C1 from SPTRCK #3. */
163     protected double c1;
164 
165     /** C2 from SPTRCK #3. */
166     protected double c2;
167 
168     /** C4 from SPTRCK #3. */
169     protected double c4;
170 
171     /** common parameter for raan (OMEGA) computation. */
172     protected double xnodcf;
173 
174     /** 3/2 * C1. */
175     protected double t2cof;
176 
177     // CHECKSTYLE: resume VisibilityModifier check
178 
179     /** TLE frame. */
180     private final Frame teme;
181 
182     /** All TLEs and masses. */
183     private TimeSpanMap<Pair<TLE, Double>> tlesAndMasses;
184 
185     /** TLE generation algorithm used when resetting TLE from state. */
186     private TleGenerationAlgorithm generationAlgorithm;
187 
188     /** Protected constructor for derived classes.
189      *
190      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
191      *
192      * @param initialTLE the unique TLE to propagate
193      * @param attitudeProvider provider for attitude computation
194      * @param mass spacecraft mass (kg)
195      * @see #TLEPropagator(TLE, AttitudeProvider, double, Frame)
196      */
197     @DefaultDataContext
198     protected TLEPropagator(final TLE initialTLE, final AttitudeProvider attitudeProvider,
199                             final double mass) {
200         this(initialTLE, attitudeProvider, mass,
201                 DataContext.getDefault().getFrames().getTEME());
202     }
203 
204     /** Protected constructor for derived classes.
205      * @param initialTLE the unique TLE to propagate
206      * @param attitudeProvider provider for attitude computation
207      * @param mass spacecraft mass (kg)
208      * @param teme the TEME frame to use for propagation.
209      * @since 10.1
210      */
211     protected TLEPropagator(final TLE initialTLE,
212                             final AttitudeProvider attitudeProvider,
213                             final double mass,
214                             final Frame teme) {
215         super(attitudeProvider);
216         setStartDate(initialTLE.getDate());
217         this.utc       = initialTLE.getUtc();
218         initializeTle(initialTLE);
219         this.teme      = teme;
220         this.tlesAndMasses = new TimeSpanMap<>(new Pair<>(tle, mass));
221         this.generationAlgorithm = getDefaultTleGenerationAlgorithm(utc, teme);
222 
223         // set the initial state
224         final Orbit orbit = propagateOrbit(initialTLE.getDate());
225         final Attitude attitude = attitudeProvider.getAttitude(orbit, orbit.getDate(), orbit.getFrame());
226         super.resetInitialState(new SpacecraftState(orbit, attitude).withMass(mass));
227     }
228 
229     /** Selects the extrapolator to use with the selected TLE.
230      *
231      * <p>This method uses the {@link DataContext#getDefault() default data context}.
232      *
233      * @param tle the TLE to propagate.
234      * @return the correct propagator.
235      * @see #selectExtrapolator(TLE, Frame)
236      */
237     @DefaultDataContext
238     public static TLEPropagator selectExtrapolator(final TLE tle) {
239         return selectExtrapolator(tle, DataContext.getDefault().getFrames().getTEME());
240     }
241 
242     /** Selects the extrapolator to use with the selected TLE.
243      * @param tle the TLE to propagate.
244      * @param teme TEME frame.
245      * @return the correct propagator.
246      * @since 10.1
247      * @see #selectExtrapolator(TLE, Frame, AttitudeProvider)
248      */
249     public static TLEPropagator selectExtrapolator(final TLE tle, final Frame teme) {
250         return selectExtrapolator(tle, teme, FrameAlignedProvider.of(teme));
251     }
252 
253     /** Selects the extrapolator to use with the selected TLE.
254      * @param tle the TLE to propagate.
255      * @param teme TEME frame.
256      * @param attitudeProvider provider for attitude computation
257      * @return the correct propagator.
258      * @since 12.2
259      */
260     public static TLEPropagator selectExtrapolator(final TLE tle, final Frame teme, final AttitudeProvider attitudeProvider) {
261         return selectExtrapolator(tle, attitudeProvider, DEFAULT_MASS, teme);
262     }
263 
264     /** Selects the extrapolator to use with the selected TLE.
265      *
266      * <p>This method uses the {@link DataContext#getDefault() default data context}.
267      *
268      * @param tle the TLE to propagate.
269      * @param attitudeProvider provider for attitude computation
270      * @param mass spacecraft mass (kg)
271      * @return the correct propagator.
272      * @see #selectExtrapolator(TLE, AttitudeProvider, double, Frame)
273      */
274     @DefaultDataContext
275     public static TLEPropagator selectExtrapolator(final TLE tle, final AttitudeProvider attitudeProvider,
276                                                    final double mass) {
277         return selectExtrapolator(tle, attitudeProvider, mass,
278                 DataContext.getDefault().getFrames().getTEME());
279     }
280 
281     /** Selects the extrapolator to use with the selected TLE.
282      * @param tle the TLE to propagate.
283      * @param attitudeProvider provider for attitude computation
284      * @param mass spacecraft mass (kg)
285      * @param teme the TEME frame to use for propagation.
286      * @return the correct propagator.
287      * @since 10.1
288      */
289     public static TLEPropagator selectExtrapolator(final TLE tle,
290                                                     final AttitudeProvider attitudeProvider,
291                                                     final double mass,
292                                                     final Frame teme) {
293 
294         final double a1 = FastMath.pow(TLEConstants.XKE / (tle.getMeanMotion() * 60.0), TLEConstants.TWO_THIRD);
295         final double cosi0 = FastMath.cos(tle.getI());
296         final double temp = TLEConstants.CK2 * 1.5 * (3 * cosi0 * cosi0 - 1.0) *
297                 FastMath.pow(1.0 - tle.getE() * tle.getE(), -1.5);
298         final double delta1 = temp / (a1 * a1);
299         final double a0 = a1 * (1.0 - delta1 * (TLEConstants.ONE_THIRD + delta1 * (delta1 * 134.0 / 81.0 + 1.0)));
300         final double delta0 = temp / (a0 * a0);
301         final double xn0dp = tle.getMeanMotion() * 60.0 / (delta0 + 1.0);
302 
303         if (MathUtils.TWO_PI / (xn0dp * TLEConstants.MINUTES_PER_DAY) >= (1.0 / 6.4)) {
304             return new DeepSDP4(tle, attitudeProvider, mass, teme);
305         } else {
306             return new SGP4(tle, attitudeProvider, mass, teme);
307         }
308     }
309 
310     /** Get the TLE generation algorithm used when resetting TLE from state.
311      * @return TLE generation algorithm
312      * @since 14.0
313      */
314     TleGenerationAlgorithm getTleGenerationAlgorithm() {
315         return generationAlgorithm;
316     }
317 
318     /** Set the TLE generation algorithm used when resetting TLE from state.
319      * @param tleGenerationAlgorithm TLE generation algorithm
320      * @since 14.0
321      */
322     public void setTleGenerationAlgorithm(final TleGenerationAlgorithm tleGenerationAlgorithm) {
323         this.generationAlgorithm = tleGenerationAlgorithm;
324     }
325 
326     /** Get the Earth gravity coefficient used for TLE propagation.
327      * @return the Earth gravity coefficient.
328      */
329     public static double getMU() {
330         return TLEConstants.MU;
331     }
332 
333     /** Get the extrapolated position and velocity from an initial TLE.
334      * @param date the final date
335      * @return the final PVCoordinates
336      */
337     public PVCoordinates getPVCoordinates(final AbsoluteDate date) {
338 
339         sxpPropagate(date.durationFrom(tle.getDate()) / 60.0);
340 
341         // Compute PV with previous calculated parameters
342         return computePVCoordinates();
343     }
344 
345     /** Computation of the first commons parameters.
346      */
347     private void initializeCommons() {
348 
349         // Sine and cosine of inclination
350         final SinCos scI0 = FastMath.sinCos(tle.getI());
351 
352         final double a1 = FastMath.pow(TLEConstants.XKE / (tle.getMeanMotion() * 60.0), TLEConstants.TWO_THIRD);
353         cosi0 = scI0.cos();
354         theta2 = cosi0 * cosi0;
355         final double x3thm1 = 3.0 * theta2 - 1.0;
356         e0sq = tle.getE() * tle.getE();
357         beta02 = 1.0 - e0sq;
358         beta0 = FastMath.sqrt(beta02);
359         final double tval = TLEConstants.CK2 * 1.5 * x3thm1 / (beta0 * beta02);
360         final double delta1 = tval / (a1 * a1);
361         final double a0 = a1 * (1.0 - delta1 * (TLEConstants.ONE_THIRD + delta1 * (1.0 + 134.0 / 81.0 * delta1)));
362         final double delta0 = tval / (a0 * a0);
363 
364         // recover original mean motion and semi-major axis :
365         xn0dp = tle.getMeanMotion() * 60.0 / (delta0 + 1.0);
366         a0dp = a0 / (1.0 - delta0);
367 
368         // Values of s and qms2t :
369         s4 = TLEConstants.S;  // unmodified value for s
370         double q0ms24 = TLEConstants.QOMS2T; // unmodified value for q0ms2T
371 
372         perige = (a0dp * (1 - tle.getE()) - TLEConstants.NORMALIZED_EQUATORIAL_RADIUS) * TLEConstants.EARTH_RADIUS; // perige
373 
374         //  For perigee below 156 km, the values of s and qoms2t are changed :
375         if (perige < 156.0) {
376             if (perige <= 98.0) {
377                 s4 = 20.0;
378             } else {
379                 s4 = perige - 78.0;
380             }
381             final double temp_val = (120.0 - s4) * TLEConstants.NORMALIZED_EQUATORIAL_RADIUS / TLEConstants.EARTH_RADIUS;
382             final double temp_val_squared = temp_val * temp_val;
383             q0ms24 = temp_val_squared * temp_val_squared;
384             s4 = s4 / TLEConstants.EARTH_RADIUS + TLEConstants.NORMALIZED_EQUATORIAL_RADIUS; // new value for q0ms2T and s
385         }
386 
387         final double pinv = 1.0 / (a0dp * beta02);
388         final double pinvsq = pinv * pinv;
389         tsi = 1.0 / (a0dp - s4);
390         eta = a0dp * tle.getE() * tsi;
391         etasq = eta * eta;
392         eeta = tle.getE() * eta;
393 
394         final double psisq = FastMath.abs(1.0 - etasq); // abs because pow 3.5 needs positive value
395         final double tsi_squared = tsi * tsi;
396         coef = q0ms24 * tsi_squared * tsi_squared;
397         coef1 = coef / FastMath.pow(psisq, 3.5);
398 
399         // C2 and C1 coefficients computation :
400         c2 = coef1 * xn0dp * (a0dp * (1.0 + 1.5 * etasq + eeta * (4.0 + etasq)) +
401                 0.75 * TLEConstants.CK2 * tsi / psisq * x3thm1 * (8.0 + 3.0 * etasq * (8.0 + etasq)));
402         c1 = tle.getBStar() * c2;
403         sini0 = scI0.sin();
404 
405         final double x1mth2 = 1.0 - theta2;
406 
407         // C4 coefficient computation :
408         c4 = 2.0 * xn0dp * coef1 * a0dp * beta02 * (eta * (2.0 + 0.5 * etasq) +
409                 tle.getE() * (0.5 + 2.0 * etasq) -
410                 2 * TLEConstants.CK2 * tsi / (a0dp * psisq) *
411                         (-3.0 * x3thm1 * (1.0 - 2.0 * eeta + etasq * (1.5 - 0.5 * eeta)) +
412                                 0.75 * x1mth2 * (2.0 * etasq - eeta * (1.0 + etasq)) * FastMath.cos(2.0 * tle.getPerigeeArgument())));
413 
414         final double theta4 = theta2 * theta2;
415         final double temp1 = 3 * TLEConstants.CK2 * pinvsq * xn0dp;
416         final double temp2 = temp1 * TLEConstants.CK2 * pinvsq;
417         final double temp3 = 1.25 * TLEConstants.CK4 * pinvsq * pinvsq * xn0dp;
418 
419         // atmospheric and gravitation coefs :(Mdf and OMEGAdf)
420         xmdot = xn0dp +
421                 0.5 * temp1 * beta0 * x3thm1 +
422                 0.0625 * temp2 * beta0 * (13.0 - 78.0 * theta2 + 137.0 * theta4);
423 
424         final double x1m5th = 1.0 - 5.0 * theta2;
425 
426         omgdot = -0.5 * temp1 * x1m5th +
427                 0.0625 * temp2 * (7.0 - 114.0 * theta2 + 395.0 * theta4) +
428                 temp3 * (3.0 - 36.0 * theta2 + 49.0 * theta4);
429 
430         final double xhdot1 = -temp1 * cosi0;
431 
432         xnodot = xhdot1 + (0.5 * temp2 * (4.0 - 19.0 * theta2) + 2.0 * temp3 * (3.0 - 7.0 * theta2)) * cosi0;
433         xnodcf = 3.5 * beta02 * xhdot1 * c1;
434         t2cof = 1.5 * c1;
435 
436     }
437 
438     /** Retrieves the position and velocity.
439      * @return the computed PVCoordinates.
440      */
441     private PVCoordinates computePVCoordinates() {
442 
443         // Sine and cosine of final perigee argument
444         final SinCos scOmega = FastMath.sinCos(omega);
445 
446         // Long period periodics
447         final double axn = e * scOmega.cos();
448         double temp = 1.0 / (a * (1.0 - e * e));
449         final double xlcof = 0.125 * TLEConstants.A3OVK2 * sini0 * (3.0 + 5.0 * cosi0) / (1.0 + cosi0);
450         final double aycof = 0.25 * TLEConstants.A3OVK2 * sini0;
451         final double xll = temp * xlcof * axn;
452         final double aynl = temp * aycof;
453         final double xlt = xl + xll;
454         final double ayn = e * scOmega.sin() + aynl;
455         final double elsq = axn * axn + ayn * ayn;
456         final double capu = MathUtils.normalizeAngle(xlt - xnode, FastMath.PI);
457         double epw = capu;
458         double ecosE = 0;
459         double esinE = 0;
460         double sinEPW = 0;
461         double cosEPW = 0;
462 
463         // Dundee changes:  items dependent on cosio get recomputed:
464         final double cosi0Sq = cosi0 * cosi0;
465         final double x3thm1 = 3.0 * cosi0Sq - 1.0;
466         final double x1mth2 = 1.0 - cosi0Sq;
467         final double x7thm1 = 7.0 * cosi0Sq - 1.0;
468 
469         if (e > (1 - 1e-6)) {
470             throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL, e);
471         }
472 
473         // Solve Kepler's' Equation.
474         final double newtonRaphsonEpsilon = 1e-12;
475         for (int j = 0; j < 10; j++) {
476 
477             boolean doSecondOrderNewtonRaphson = true;
478 
479             final SinCos scEPW = FastMath.sinCos(epw);
480             sinEPW = scEPW.sin();
481             cosEPW = scEPW.cos();
482             ecosE = axn * cosEPW + ayn * sinEPW;
483             esinE = axn * sinEPW - ayn * cosEPW;
484             final double f = capu - epw + esinE;
485             if (FastMath.abs(f) < newtonRaphsonEpsilon) {
486                 break;
487             }
488             final double fdot = 1.0 - ecosE;
489             double delta_epw = f / fdot;
490             if (j == 0) {
491                 final double maxNewtonRaphson = 1.25 * FastMath.abs(e);
492                 doSecondOrderNewtonRaphson = false;
493                 if (delta_epw > maxNewtonRaphson) {
494                     delta_epw = maxNewtonRaphson;
495                 } else if (delta_epw < -maxNewtonRaphson) {
496                     delta_epw = -maxNewtonRaphson;
497                 } else {
498                     doSecondOrderNewtonRaphson = true;
499                 }
500             }
501             if (doSecondOrderNewtonRaphson) {
502                 delta_epw = f / (fdot + 0.5 * esinE * delta_epw);
503             }
504             epw += delta_epw;
505         }
506 
507         // Short period preliminary quantities
508         temp = 1.0 - elsq;
509         final double pl = a * temp;
510         final double r = a * (1.0 - ecosE);
511         double temp2 = a / r;
512         final double betal = FastMath.sqrt(temp);
513         temp = esinE / (1.0 + betal);
514         final double cosu = temp2 * (cosEPW - axn + ayn * temp);
515         final double sinu = temp2 * (sinEPW - ayn - axn * temp);
516         final double u = FastMath.atan2(sinu, cosu);
517         final double sin2u = 2.0 * sinu * cosu;
518         final double cos2u = 2.0 * cosu * cosu - 1.0;
519         final double temp1 = TLEConstants.CK2 / pl;
520         temp2 = temp1 / pl;
521 
522         // Update for short periodics
523         final double rk = r * (1.0 - 1.5 * temp2 * betal * x3thm1) + 0.5 * temp1 * x1mth2 * cos2u;
524         final double uk = u - 0.25 * temp2 * x7thm1 * sin2u;
525         final double xnodek = xnode + 1.5 * temp2 * cosi0 * sin2u;
526         final double xinck = i + 1.5 * temp2 * cosi0 * sini0 * cos2u;
527 
528         // Orientation vectors
529         final SinCos scuk   = FastMath.sinCos(uk);
530         final SinCos scik   = FastMath.sinCos(xinck);
531         final SinCos scnok  = FastMath.sinCos(xnodek);
532         final double sinuk  = scuk.sin();
533         final double cosuk  = scuk.cos();
534         final double sinik  = scik.sin();
535         final double cosik  = scik.cos();
536         final double sinnok = scnok.sin();
537         final double cosnok = scnok.cos();
538         final double xmx = -sinnok * cosik;
539         final double xmy = cosnok * cosik;
540         final double ux  = xmx * sinuk + cosnok * cosuk;
541         final double uy  = xmy * sinuk + sinnok * cosuk;
542         final double uz  = sinik * sinuk;
543 
544         // Position and velocity
545         final double cr = 1000 * rk * TLEConstants.EARTH_RADIUS;
546         final Vector3D pos = new Vector3D(cr * ux, cr * uy, cr * uz);
547 
548         final double rdot   = TLEConstants.XKE * FastMath.sqrt(a) * esinE / r;
549         final double rfdot  = TLEConstants.XKE * FastMath.sqrt(pl) / r;
550         final double xn     = TLEConstants.XKE / (a * FastMath.sqrt(a));
551         final double rdotk  = rdot - xn * temp1 * x1mth2 * sin2u;
552         final double rfdotk = rfdot + xn * temp1 * (x1mth2 * cos2u + 1.5 * x3thm1);
553         final double vx     = xmx * cosuk - cosnok * sinuk;
554         final double vy     = xmy * cosuk - sinnok * sinuk;
555         final double vz     = sinik * cosuk;
556 
557         final double cv = 1000.0 * TLEConstants.EARTH_RADIUS / 60.0;
558         final Vector3D vel = new Vector3D(cv * (rdotk * ux + rfdotk * vx),
559                 cv * (rdotk * uy + rfdotk * vy),
560                 cv * (rdotk * uz + rfdotk * vz));
561 
562         return new PVCoordinates(pos, vel);
563 
564     }
565 
566     /** Initialization proper to each propagator (SGP or SDP).
567      */
568     protected abstract void sxpInitialize();
569 
570     /** Propagation proper to each propagator (SGP or SDP).
571      * @param t the offset from initial epoch (min)
572      */
573     protected abstract void sxpPropagate(double t);
574 
575     /** {@inheritDoc}
576      * <p>
577      * For TLE propagator, calling this method is only recommended
578      * for covariance propagation when the new <code>state</code>
579      * differs from the previous one by only adding the additional
580      * state containing the derivatives.
581      * </p>
582      */
583     public void resetInitialState(final SpacecraftState state) {
584         super.resetInitialState(state);
585         resetTle(state);
586         tlesAndMasses = new TimeSpanMap<>(new Pair<>(tle, state.getMass()));
587     }
588 
589     /** {@inheritDoc} */
590     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
591         resetTle(state);
592         final Pair<TLE, Double> tleAndMass = new Pair<>(tle, state.getMass());
593         if (forward) {
594             tlesAndMasses.addValidAfter(tleAndMass, state.getDate(), false);
595         } else {
596             tlesAndMasses.addValidBefore(tleAndMass, state.getDate(), false);
597         }
598         stateChanged(state);
599     }
600 
601     /** Reset internal TLE from a SpacecraftState.
602      * @param state spacecraft state on which to base new TLE
603      */
604     private void resetTle(final SpacecraftState state) {
605 
606         final TLE newTle = generationAlgorithm.generate(state, tle);
607         initializeTle(newTle);
608     }
609 
610     /** Initialize internal TLE.
611      * @param newTle tle to replace current one
612      */
613     private void initializeTle(final TLE newTle) {
614         tle = newTle;
615         initializeCommons();
616         sxpInitialize();
617     }
618 
619     /** {@inheritDoc} */
620     protected double getMass(final AbsoluteDate date) {
621         return tlesAndMasses.get(date).getValue();
622     }
623 
624     /** {@inheritDoc} */
625     public Orbit propagateOrbit(final AbsoluteDate date) {
626         final TLE closestTle = tlesAndMasses.get(date).getKey();
627         if (!tle.equals(closestTle)) {
628             initializeTle(closestTle);
629         }
630         return new CartesianOrbit(getPVCoordinates(date), teme, date, TLEConstants.MU);
631     }
632 
633     /** Get the underlying TLE.
634      * If there has been calls to #resetInitialState or #resetIntermediateState,
635      * it will not be the same as given to the constructor.
636      * @return underlying TLE
637      */
638     public TLE getTLE() {
639         return tle;
640     }
641 
642     /** {@inheritDoc} */
643     public Frame getFrame() {
644         return teme;
645     }
646 
647     /** {@inheritDoc} */
648     @Override
649     protected AbstractMatricesHarvester createHarvester(final String stmName, final RealMatrix initialStm,
650                                                         final DoubleArrayDictionary initialJacobianColumns) {
651         // Create the harvester
652         final TLEHarvester harvester = new TLEHarvester(this, stmName, initialStm, initialJacobianColumns);
653         // Update the list of additional state provider
654         addAdditionalDataProvider(harvester);
655         // Return the configured harvester
656         return harvester;
657     }
658 
659     /**
660      * Get the names of the parameters in the matrix returned by {@link MatricesHarvester#getParametersJacobian}.
661      * @return names of the parameters (i.e. columns) of the Jacobian matrix
662      */
663     protected List<String> getJacobiansColumnsNames() {
664         final List<String> columnsNames = new ArrayList<>();
665         for (final ParameterDriver driver : tle.getParametersDrivers()) {
666 
667             if (driver.isSelected() && !columnsNames.contains(driver.getNamesSpanMap().getFirstSpan().getData())) {
668                 // As driver with same name should have same NamesSpanMap we only check the if condition on the
669                 // first span map and then if the condition is OK all the span names are added to the jacobian column names
670                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
671                     columnsNames.add(span.getData());
672                 }
673             }
674         }
675         Collections.sort(columnsNames);
676         return columnsNames;
677     }
678 
679     /**
680      * Get the default TLE generation algorithm.
681      * @param utc UTC time scale
682      * @param teme TEME frame
683      * @return a TLE generation algorithm
684      * @since 12.0
685      */
686     public static TleGenerationAlgorithm getDefaultTleGenerationAlgorithm(final TimeScale utc, final Frame teme) {
687         return new FixedPointTleGenerationAlgorithm(FixedPointTleGenerationAlgorithm.EPSILON_DEFAULT,
688                 FixedPointTleGenerationAlgorithm.MAX_ITERATIONS_DEFAULT,
689                 FixedPointTleGenerationAlgorithm.SCALE_DEFAULT, utc, teme);
690     }
691 
692 }