TLEPropagator.java

  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.analytical.tle;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.linear.RealMatrix;
  23. import org.hipparchus.util.FastMath;
  24. import org.hipparchus.util.MathUtils;
  25. import org.hipparchus.util.Pair;
  26. import org.hipparchus.util.SinCos;
  27. import org.orekit.annotation.DefaultDataContext;
  28. import org.orekit.attitudes.Attitude;
  29. import org.orekit.attitudes.AttitudeProvider;
  30. import org.orekit.attitudes.FrameAlignedProvider;
  31. import org.orekit.data.DataContext;
  32. import org.orekit.errors.OrekitException;
  33. import org.orekit.errors.OrekitMessages;
  34. import org.orekit.frames.Frame;
  35. import org.orekit.orbits.CartesianOrbit;
  36. import org.orekit.orbits.Orbit;
  37. import org.orekit.propagation.AbstractMatricesHarvester;
  38. import org.orekit.propagation.MatricesHarvester;
  39. import org.orekit.propagation.SpacecraftState;
  40. import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
  41. import org.orekit.propagation.analytical.tle.generation.FixedPointTleGenerationAlgorithm;
  42. import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
  43. import org.orekit.time.AbsoluteDate;
  44. import org.orekit.time.TimeScale;
  45. import org.orekit.utils.DoubleArrayDictionary;
  46. import org.orekit.utils.PVCoordinates;
  47. import org.orekit.utils.ParameterDriver;
  48. import org.orekit.utils.TimeSpanMap;
  49. import org.orekit.utils.TimeSpanMap.Span;

  50. /** This class provides elements to propagate TLE's.
  51.  * <p>
  52.  * The models used are SGP4 and SDP4, initially proposed by NORAD as the unique convenient
  53.  * propagator for TLE's. Inputs and outputs of this propagator are only suited for
  54.  * NORAD two lines elements sets, since it uses estimations and mean values appropriate
  55.  * for TLE's only.
  56.  * </p>
  57.  * <p>
  58.  * Deep- or near- space propagator is selected internally according to NORAD recommendations
  59.  * so that the user has not to worry about the used computation methods. One instance is created
  60.  * for each TLE (this instance can only be get using {@link #selectExtrapolator(TLE)} method,
  61.  * and can compute {@link PVCoordinates position and velocity coordinates} at any
  62.  * time. Maximum accuracy is guaranteed in a 24h range period before and after the provided
  63.  * TLE epoch (of course this accuracy is not really measurable nor predictable: according to
  64.  * <a href="https://www.celestrak.com/">CelesTrak</a>, the precision is close to one kilometer
  65.  * and error won't probably rise above 2 km).
  66.  * </p>
  67.  * <p>This implementation is largely inspired from the paper and source code <a
  68.  * href="https://www.celestrak.com/publications/AIAA/2006-6753/">Revisiting Spacetrack
  69.  * Report #3</a> and is fully compliant with its results and tests cases.</p>
  70.  * @author Felix R. Hoots, Ronald L. Roehrich, December 1980 (original fortran)
  71.  * @author David A. Vallado, Paul Crawford, Richard Hujsak, T.S. Kelso (C++ translation and improvements)
  72.  * @author Fabien Maussion (java translation)
  73.  * @see TLE
  74.  */
  75. public abstract class TLEPropagator extends AbstractAnalyticalPropagator {

  76.     // CHECKSTYLE: stop VisibilityModifier check

  77.     /** Initial state. */
  78.     protected TLE tle;

  79.     /** UTC time scale. */
  80.     protected final TimeScale utc;

  81.     /** final RAAN. */
  82.     protected double xnode;

  83.     /** final semi major axis. */
  84.     protected double a;

  85.     /** final eccentricity. */
  86.     protected double e;

  87.     /** final inclination. */
  88.     protected double i;

  89.     /** final perigee argument. */
  90.     protected double omega;

  91.     /** L from SPTRCK #3. */
  92.     protected double xl;

  93.     /** original recovered semi major axis. */
  94.     protected double a0dp;

  95.     /** original recovered mean motion. */
  96.     protected double xn0dp;

  97.     /** cosinus original inclination. */
  98.     protected double cosi0;

  99.     /** cos io squared. */
  100.     protected double theta2;

  101.     /** sinus original inclination. */
  102.     protected double sini0;

  103.     /** common parameter for mean anomaly (M) computation. */
  104.     protected double xmdot;

  105.     /** common parameter for perigee argument (omega) computation. */
  106.     protected double omgdot;

  107.     /** common parameter for raan (OMEGA) computation. */
  108.     protected double xnodot;

  109.     /** original eccentricity squared. */
  110.     protected double e0sq;
  111.     /** 1 - e2. */
  112.     protected double beta02;

  113.     /** sqrt (1 - e2). */
  114.     protected double beta0;

  115.     /** perigee, expressed in KM and ALTITUDE. */
  116.     protected double perige;

  117.     /** eta squared. */
  118.     protected double etasq;

  119.     /** original eccentricity * eta. */
  120.     protected double eeta;

  121.     /** s* new value for the contant s. */
  122.     protected double s4;

  123.     /** tsi from SPTRCK #3. */
  124.     protected double tsi;

  125.     /** eta from SPTRCK #3. */
  126.     protected double eta;

  127.     /** coef for SGP C3 computation. */
  128.     protected double coef;

  129.     /** coef for SGP C5 computation. */
  130.     protected double coef1;

  131.     /** C1 from SPTRCK #3. */
  132.     protected double c1;

  133.     /** C2 from SPTRCK #3. */
  134.     protected double c2;

  135.     /** C4 from SPTRCK #3. */
  136.     protected double c4;

  137.     /** common parameter for raan (OMEGA) computation. */
  138.     protected double xnodcf;

  139.     /** 3/2 * C1. */
  140.     protected double t2cof;

  141.     // CHECKSTYLE: resume VisibilityModifier check

  142.     /** TLE frame. */
  143.     private final Frame teme;

  144.     /** All TLEs and masses. */
  145.     private TimeSpanMap<Pair<TLE, Double>> tlesAndMasses;

  146.     /** Protected constructor for derived classes.
  147.      *
  148.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  149.      *
  150.      * @param initialTLE the unique TLE to propagate
  151.      * @param attitudeProvider provider for attitude computation
  152.      * @param mass spacecraft mass (kg)
  153.      * @see #TLEPropagator(TLE, AttitudeProvider, double, Frame)
  154.      */
  155.     @DefaultDataContext
  156.     protected TLEPropagator(final TLE initialTLE, final AttitudeProvider attitudeProvider,
  157.                             final double mass) {
  158.         this(initialTLE, attitudeProvider, mass,
  159.                 DataContext.getDefault().getFrames().getTEME());
  160.     }

  161.     /** Protected constructor for derived classes.
  162.      * @param initialTLE the unique TLE to propagate
  163.      * @param attitudeProvider provider for attitude computation
  164.      * @param mass spacecraft mass (kg)
  165.      * @param teme the TEME frame to use for propagation.
  166.      * @since 10.1
  167.      */
  168.     protected TLEPropagator(final TLE initialTLE,
  169.                             final AttitudeProvider attitudeProvider,
  170.                             final double mass,
  171.                             final Frame teme) {
  172.         super(attitudeProvider);
  173.         setStartDate(initialTLE.getDate());
  174.         this.utc       = initialTLE.getUtc();
  175.         initializeTle(initialTLE);
  176.         this.teme      = teme;
  177.         this.tlesAndMasses = new TimeSpanMap<>(new Pair<>(tle, mass));

  178.         // set the initial state
  179.         final Orbit orbit = propagateOrbit(initialTLE.getDate());
  180.         final Attitude attitude = attitudeProvider.getAttitude(orbit, orbit.getDate(), orbit.getFrame());
  181.         super.resetInitialState(new SpacecraftState(orbit, attitude).withMass(mass));
  182.     }

  183.     /** Selects the extrapolator to use with the selected TLE.
  184.      *
  185.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  186.      *
  187.      * @param tle the TLE to propagate.
  188.      * @return the correct propagator.
  189.      * @see #selectExtrapolator(TLE, Frame)
  190.      */
  191.     @DefaultDataContext
  192.     public static TLEPropagator selectExtrapolator(final TLE tle) {
  193.         return selectExtrapolator(tle, DataContext.getDefault().getFrames().getTEME());
  194.     }

  195.     /** Selects the extrapolator to use with the selected TLE.
  196.      * @param tle the TLE to propagate.
  197.      * @param teme TEME frame.
  198.      * @return the correct propagator.
  199.      * @since 10.1
  200.      * @see #selectExtrapolator(TLE, Frame, AttitudeProvider)
  201.      */
  202.     public static TLEPropagator selectExtrapolator(final TLE tle, final Frame teme) {
  203.         return selectExtrapolator(tle, teme, FrameAlignedProvider.of(teme));
  204.     }

  205.     /** Selects the extrapolator to use with the selected TLE.
  206.      * @param tle the TLE to propagate.
  207.      * @param teme TEME frame.
  208.      * @param attitudeProvider provider for attitude computation
  209.      * @return the correct propagator.
  210.      * @since 12.2
  211.      */
  212.     public static TLEPropagator selectExtrapolator(final TLE tle, final Frame teme, final AttitudeProvider attitudeProvider) {
  213.         return selectExtrapolator(tle, attitudeProvider, DEFAULT_MASS, teme);
  214.     }

  215.     /** Selects the extrapolator to use with the selected TLE.
  216.      *
  217.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  218.      *
  219.      * @param tle the TLE to propagate.
  220.      * @param attitudeProvider provider for attitude computation
  221.      * @param mass spacecraft mass (kg)
  222.      * @return the correct propagator.
  223.      * @see #selectExtrapolator(TLE, AttitudeProvider, double, Frame)
  224.      */
  225.     @DefaultDataContext
  226.     public static TLEPropagator selectExtrapolator(final TLE tle, final AttitudeProvider attitudeProvider,
  227.                                                    final double mass) {
  228.         return selectExtrapolator(tle, attitudeProvider, mass,
  229.                                   DataContext.getDefault().getFrames().getTEME());
  230.     }

  231.     /** Selects the extrapolator to use with the selected TLE.
  232.      * @param tle the TLE to propagate.
  233.      * @param attitudeProvider provider for attitude computation
  234.      * @param mass spacecraft mass (kg)
  235.      * @param teme the TEME frame to use for propagation.
  236.      * @return the correct propagator.
  237.      * @since 10.1
  238.      */
  239.     public static TLEPropagator selectExtrapolator(final TLE tle,
  240.                                                    final AttitudeProvider attitudeProvider,
  241.                                                    final double mass,
  242.                                                    final Frame teme) {

  243.         final double a1 = FastMath.pow( TLEConstants.XKE / (tle.getMeanMotion() * 60.0), TLEConstants.TWO_THIRD);
  244.         final double cosi0 = FastMath.cos(tle.getI());
  245.         final double temp = TLEConstants.CK2 * 1.5 * (3 * cosi0 * cosi0 - 1.0) *
  246.                             FastMath.pow(1.0 - tle.getE() * tle.getE(), -1.5);
  247.         final double delta1 = temp / (a1 * a1);
  248.         final double a0 = a1 * (1.0 - delta1 * (TLEConstants.ONE_THIRD + delta1 * (delta1 * 134.0 / 81.0 + 1.0)));
  249.         final double delta0 = temp / (a0 * a0);

  250.         // recover original mean motion :
  251.         final double xn0dp = tle.getMeanMotion() * 60.0 / (delta0 + 1.0);

  252.         // Period >= 225 minutes is deep space
  253.         if (MathUtils.TWO_PI / (xn0dp * TLEConstants.MINUTES_PER_DAY) >= (1.0 / 6.4)) {
  254.             return new DeepSDP4(tle, attitudeProvider, mass, teme);
  255.         } else {
  256.             return new SGP4(tle, attitudeProvider, mass, teme);
  257.         }
  258.     }

  259.     /** Get the Earth gravity coefficient used for TLE propagation.
  260.      * @return the Earth gravity coefficient.
  261.      */
  262.     public static double getMU() {
  263.         return TLEConstants.MU;
  264.     }

  265.     /** Get the extrapolated position and velocity from an initial TLE.
  266.      * @param date the final date
  267.      * @return the final PVCoordinates
  268.      */
  269.     public PVCoordinates getPVCoordinates(final AbsoluteDate date) {

  270.         sxpPropagate(date.durationFrom(tle.getDate()) / 60.0);

  271.         // Compute PV with previous calculated parameters
  272.         return computePVCoordinates();
  273.     }

  274.     /** Computation of the first commons parameters.
  275.      */
  276.     private void initializeCommons() {

  277.         // Sine and cosine of inclination
  278.         final SinCos scI0 = FastMath.sinCos(tle.getI());

  279.         final double a1 = FastMath.pow(TLEConstants.XKE / (tle.getMeanMotion() * 60.0), TLEConstants.TWO_THIRD);
  280.         cosi0 = scI0.cos();
  281.         theta2 = cosi0 * cosi0;
  282.         final double x3thm1 = 3.0 * theta2 - 1.0;
  283.         e0sq = tle.getE() * tle.getE();
  284.         beta02 = 1.0 - e0sq;
  285.         beta0 = FastMath.sqrt(beta02);
  286.         final double tval = TLEConstants.CK2 * 1.5 * x3thm1 / (beta0 * beta02);
  287.         final double delta1 = tval / (a1 * a1);
  288.         final double a0 = a1 * (1.0 - delta1 * (TLEConstants.ONE_THIRD + delta1 * (1.0 + 134.0 / 81.0 * delta1)));
  289.         final double delta0 = tval / (a0 * a0);

  290.         // recover original mean motion and semi-major axis :
  291.         xn0dp = tle.getMeanMotion() * 60.0 / (delta0 + 1.0);
  292.         a0dp = a0 / (1.0 - delta0);

  293.         // Values of s and qms2t :
  294.         s4 = TLEConstants.S;  // unmodified value for s
  295.         double q0ms24 = TLEConstants.QOMS2T; // unmodified value for q0ms2T

  296.         perige = (a0dp * (1 - tle.getE()) - TLEConstants.NORMALIZED_EQUATORIAL_RADIUS) * TLEConstants.EARTH_RADIUS; // perige

  297.         //  For perigee below 156 km, the values of s and qoms2t are changed :
  298.         if (perige < 156.0) {
  299.             if (perige <= 98.0) {
  300.                 s4 = 20.0;
  301.             } else {
  302.                 s4 = perige - 78.0;
  303.             }
  304.             final double temp_val = (120.0 - s4) * TLEConstants.NORMALIZED_EQUATORIAL_RADIUS / TLEConstants.EARTH_RADIUS;
  305.             final double temp_val_squared = temp_val * temp_val;
  306.             q0ms24 = temp_val_squared * temp_val_squared;
  307.             s4 = s4 / TLEConstants.EARTH_RADIUS + TLEConstants.NORMALIZED_EQUATORIAL_RADIUS; // new value for q0ms2T and s
  308.         }

  309.         final double pinv = 1.0 / (a0dp * beta02);
  310.         final double pinvsq = pinv * pinv;
  311.         tsi = 1.0 / (a0dp - s4);
  312.         eta = a0dp * tle.getE() * tsi;
  313.         etasq = eta * eta;
  314.         eeta = tle.getE() * eta;

  315.         final double psisq = FastMath.abs(1.0 - etasq); // abs because pow 3.5 needs positive value
  316.         final double tsi_squared = tsi * tsi;
  317.         coef = q0ms24 * tsi_squared * tsi_squared;
  318.         coef1 = coef / FastMath.pow(psisq, 3.5);

  319.         // C2 and C1 coefficients computation :
  320.         c2 = coef1 * xn0dp * (a0dp * (1.0 + 1.5 * etasq + eeta * (4.0 + etasq)) +
  321.              0.75 * TLEConstants.CK2 * tsi / psisq * x3thm1 * (8.0 + 3.0 * etasq * (8.0 + etasq)));
  322.         c1 = tle.getBStar() * c2;
  323.         sini0 = scI0.sin();

  324.         final double x1mth2 = 1.0 - theta2;

  325.         // C4 coefficient computation :
  326.         c4 = 2.0 * xn0dp * coef1 * a0dp * beta02 * (eta * (2.0 + 0.5 * etasq) +
  327.              tle.getE() * (0.5 + 2.0 * etasq) -
  328.              2 * TLEConstants.CK2 * tsi / (a0dp * psisq) *
  329.              (-3.0 * x3thm1 * (1.0 - 2.0 * eeta + etasq * (1.5 - 0.5 * eeta)) +
  330.               0.75 * x1mth2 * (2.0 * etasq - eeta * (1.0 + etasq)) * FastMath.cos(2.0 * tle.getPerigeeArgument())));

  331.         final double theta4 = theta2 * theta2;
  332.         final double temp1 = 3 * TLEConstants.CK2 * pinvsq * xn0dp;
  333.         final double temp2 = temp1 * TLEConstants.CK2 * pinvsq;
  334.         final double temp3 = 1.25 * TLEConstants.CK4 * pinvsq * pinvsq * xn0dp;

  335.         // atmospheric and gravitation coefs :(Mdf and OMEGAdf)
  336.         xmdot = xn0dp +
  337.                 0.5 * temp1 * beta0 * x3thm1 +
  338.                 0.0625 * temp2 * beta0 * (13.0 - 78.0 * theta2 + 137.0 * theta4);

  339.         final double x1m5th = 1.0 - 5.0 * theta2;

  340.         omgdot = -0.5 * temp1 * x1m5th +
  341.                  0.0625 * temp2 * (7.0 - 114.0 * theta2 + 395.0 * theta4) +
  342.                  temp3 * (3.0 - 36.0 * theta2 + 49.0 * theta4);

  343.         final double xhdot1 = -temp1 * cosi0;

  344.         xnodot = xhdot1 + (0.5 * temp2 * (4.0 - 19.0 * theta2) + 2.0 * temp3 * (3.0 - 7.0 * theta2)) * cosi0;
  345.         xnodcf = 3.5 * beta02 * xhdot1 * c1;
  346.         t2cof = 1.5 * c1;

  347.     }

  348.     /** Retrieves the position and velocity.
  349.      * @return the computed PVCoordinates.
  350.      */
  351.     private PVCoordinates computePVCoordinates() {

  352.         // Sine and cosine of final perigee argument
  353.         final SinCos scOmega = FastMath.sinCos(omega);

  354.         // Long period periodics
  355.         final double axn = e * scOmega.cos();
  356.         double temp = 1.0 / (a * (1.0 - e * e));
  357.         final double xlcof = 0.125 * TLEConstants.A3OVK2 * sini0 * (3.0 + 5.0 * cosi0) / (1.0 + cosi0);
  358.         final double aycof = 0.25 * TLEConstants.A3OVK2 * sini0;
  359.         final double xll = temp * xlcof * axn;
  360.         final double aynl = temp * aycof;
  361.         final double xlt = xl + xll;
  362.         final double ayn = e * scOmega.sin() + aynl;
  363.         final double elsq = axn * axn + ayn * ayn;
  364.         final double capu = MathUtils.normalizeAngle(xlt - xnode, FastMath.PI);
  365.         double epw = capu;
  366.         double ecosE = 0;
  367.         double esinE = 0;
  368.         double sinEPW = 0;
  369.         double cosEPW = 0;

  370.         // Dundee changes:  items dependent on cosio get recomputed:
  371.         final double cosi0Sq = cosi0 * cosi0;
  372.         final double x3thm1 = 3.0 * cosi0Sq - 1.0;
  373.         final double x1mth2 = 1.0 - cosi0Sq;
  374.         final double x7thm1 = 7.0 * cosi0Sq - 1.0;

  375.         if (e > (1 - 1e-6)) {
  376.             throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL, e);
  377.         }

  378.         // Solve Kepler's' Equation.
  379.         final double newtonRaphsonEpsilon = 1e-12;
  380.         for (int j = 0; j < 10; j++) {

  381.             boolean doSecondOrderNewtonRaphson = true;

  382.             final SinCos scEPW = FastMath.sinCos(epw);
  383.             sinEPW = scEPW.sin();
  384.             cosEPW = scEPW.cos();
  385.             ecosE = axn * cosEPW + ayn * sinEPW;
  386.             esinE = axn * sinEPW - ayn * cosEPW;
  387.             final double f = capu - epw + esinE;
  388.             if (FastMath.abs(f) < newtonRaphsonEpsilon) {
  389.                 break;
  390.             }
  391.             final double fdot = 1.0 - ecosE;
  392.             double delta_epw = f / fdot;
  393.             if (j == 0) {
  394.                 final double maxNewtonRaphson = 1.25 * FastMath.abs(e);
  395.                 doSecondOrderNewtonRaphson = false;
  396.                 if (delta_epw > maxNewtonRaphson) {
  397.                     delta_epw = maxNewtonRaphson;
  398.                 } else if (delta_epw < -maxNewtonRaphson) {
  399.                     delta_epw = -maxNewtonRaphson;
  400.                 } else {
  401.                     doSecondOrderNewtonRaphson = true;
  402.                 }
  403.             }
  404.             if (doSecondOrderNewtonRaphson) {
  405.                 delta_epw = f / (fdot + 0.5 * esinE * delta_epw);
  406.             }
  407.             epw += delta_epw;
  408.         }

  409.         // Short period preliminary quantities
  410.         temp = 1.0 - elsq;
  411.         final double pl = a * temp;
  412.         final double r = a * (1.0 - ecosE);
  413.         double temp2 = a / r;
  414.         final double betal = FastMath.sqrt(temp);
  415.         temp = esinE / (1.0 + betal);
  416.         final double cosu = temp2 * (cosEPW - axn + ayn * temp);
  417.         final double sinu = temp2 * (sinEPW - ayn - axn * temp);
  418.         final double u = FastMath.atan2(sinu, cosu);
  419.         final double sin2u = 2.0 * sinu * cosu;
  420.         final double cos2u = 2.0 * cosu * cosu - 1.0;
  421.         final double temp1 = TLEConstants.CK2 / pl;
  422.         temp2 = temp1 / pl;

  423.         // Update for short periodics
  424.         final double rk = r * (1.0 - 1.5 * temp2 * betal * x3thm1) + 0.5 * temp1 * x1mth2 * cos2u;
  425.         final double uk = u - 0.25 * temp2 * x7thm1 * sin2u;
  426.         final double xnodek = xnode + 1.5 * temp2 * cosi0 * sin2u;
  427.         final double xinck = i + 1.5 * temp2 * cosi0 * sini0 * cos2u;

  428.         // Orientation vectors
  429.         final SinCos scuk   = FastMath.sinCos(uk);
  430.         final SinCos scik   = FastMath.sinCos(xinck);
  431.         final SinCos scnok  = FastMath.sinCos(xnodek);
  432.         final double sinuk  = scuk.sin();
  433.         final double cosuk  = scuk.cos();
  434.         final double sinik  = scik.sin();
  435.         final double cosik  = scik.cos();
  436.         final double sinnok = scnok.sin();
  437.         final double cosnok = scnok.cos();
  438.         final double xmx = -sinnok * cosik;
  439.         final double xmy = cosnok * cosik;
  440.         final double ux  = xmx * sinuk + cosnok * cosuk;
  441.         final double uy  = xmy * sinuk + sinnok * cosuk;
  442.         final double uz  = sinik * sinuk;

  443.         // Position and velocity
  444.         final double cr = 1000 * rk * TLEConstants.EARTH_RADIUS;
  445.         final Vector3D pos = new Vector3D(cr * ux, cr * uy, cr * uz);

  446.         final double rdot   = TLEConstants.XKE * FastMath.sqrt(a) * esinE / r;
  447.         final double rfdot  = TLEConstants.XKE * FastMath.sqrt(pl) / r;
  448.         final double xn     = TLEConstants.XKE / (a * FastMath.sqrt(a));
  449.         final double rdotk  = rdot - xn * temp1 * x1mth2 * sin2u;
  450.         final double rfdotk = rfdot + xn * temp1 * (x1mth2 * cos2u + 1.5 * x3thm1);
  451.         final double vx     = xmx * cosuk - cosnok * sinuk;
  452.         final double vy     = xmy * cosuk - sinnok * sinuk;
  453.         final double vz     = sinik * cosuk;

  454.         final double cv = 1000.0 * TLEConstants.EARTH_RADIUS / 60.0;
  455.         final Vector3D vel = new Vector3D(cv * (rdotk * ux + rfdotk * vx),
  456.                                           cv * (rdotk * uy + rfdotk * vy),
  457.                                           cv * (rdotk * uz + rfdotk * vz));

  458.         return new PVCoordinates(pos, vel);

  459.     }

  460.     /** Initialization proper to each propagator (SGP or SDP).
  461.      */
  462.     protected abstract void sxpInitialize();

  463.     /** Propagation proper to each propagator (SGP or SDP).
  464.      * @param t the offset from initial epoch (min)
  465.      */
  466.     protected abstract void sxpPropagate(double t);

  467.     /** {@inheritDoc}
  468.      * <p>
  469.      * For TLE propagator, calling this method is only recommended
  470.      * for covariance propagation when the new <code>state</code>
  471.      * differs from the previous one by only adding the additional
  472.      * state containing the derivatives.
  473.      * </p>
  474.      */
  475.     public void resetInitialState(final SpacecraftState state) {
  476.         super.resetInitialState(state);
  477.         resetTle(state);
  478.         tlesAndMasses = new TimeSpanMap<>(new Pair<>(tle, state.getMass()));
  479.     }

  480.     /** {@inheritDoc} */
  481.     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
  482.         resetTle(state);
  483.         final Pair<TLE, Double> tleAndMass = new Pair<>(tle, state.getMass());
  484.         if (forward) {
  485.             tlesAndMasses.addValidAfter(tleAndMass, state.getDate(), false);
  486.         } else {
  487.             tlesAndMasses.addValidBefore(tleAndMass, state.getDate(), false);
  488.         }
  489.         stateChanged(state);
  490.     }

  491.     /** Reset internal TLE from a SpacecraftState.
  492.      * @param state spacecraft state on which to base new TLE
  493.      */
  494.     private void resetTle(final SpacecraftState state) {
  495.         final TleGenerationAlgorithm algorithm = getDefaultTleGenerationAlgorithm(utc, teme);
  496.         final TLE newTle = algorithm.generate(state, tle);
  497.         initializeTle(newTle);
  498.     }

  499.     /** Initialize internal TLE.
  500.      * @param newTle tle to replace current one
  501.      */
  502.     private void initializeTle(final TLE newTle) {
  503.         tle = newTle;
  504.         initializeCommons();
  505.         sxpInitialize();
  506.     }

  507.     /** {@inheritDoc} */
  508.     protected double getMass(final AbsoluteDate date) {
  509.         return tlesAndMasses.get(date).getValue();
  510.     }

  511.     /** {@inheritDoc} */
  512.     public Orbit propagateOrbit(final AbsoluteDate date) {
  513.         final TLE closestTle = tlesAndMasses.get(date).getKey();
  514.         if (!tle.equals(closestTle)) {
  515.             initializeTle(closestTle);
  516.         }
  517.         return new CartesianOrbit(getPVCoordinates(date), teme, date, TLEConstants.MU);
  518.     }

  519.     /** Get the underlying TLE.
  520.      * If there has been calls to #resetInitialState or #resetIntermediateState,
  521.      * it will not be the same as given to the constructor.
  522.      * @return underlying TLE
  523.      */
  524.     public TLE getTLE() {
  525.         return tle;
  526.     }

  527.     /** {@inheritDoc} */
  528.     public Frame getFrame() {
  529.         return teme;
  530.     }

  531.     /** {@inheritDoc} */
  532.     @Override
  533.     protected AbstractMatricesHarvester createHarvester(final String stmName, final RealMatrix initialStm,
  534.                                                         final DoubleArrayDictionary initialJacobianColumns) {
  535.         // Create the harvester
  536.         final TLEHarvester harvester = new TLEHarvester(this, stmName, initialStm, initialJacobianColumns);
  537.         // Update the list of additional state provider
  538.         addAdditionalDataProvider(harvester);
  539.         // Return the configured harvester
  540.         return harvester;
  541.     }

  542.     /**
  543.      * Get the names of the parameters in the matrix returned by {@link MatricesHarvester#getParametersJacobian}.
  544.      * @return names of the parameters (i.e. columns) of the Jacobian matrix
  545.      */
  546.     protected List<String> getJacobiansColumnsNames() {
  547.         final List<String> columnsNames = new ArrayList<>();
  548.         for (final ParameterDriver driver : tle.getParametersDrivers()) {

  549.             if (driver.isSelected() && !columnsNames.contains(driver.getNamesSpanMap().getFirstSpan().getData())) {
  550.                 // As driver with same name should have same NamesSpanMap we only check the if condition on the
  551.                 // first span map and then if the condition is OK all the span names are added to the jacobian column names
  552.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  553.                     columnsNames.add(span.getData());
  554.                 }
  555.             }
  556.         }
  557.         Collections.sort(columnsNames);
  558.         return columnsNames;
  559.     }

  560.     /**
  561.      * Get the default TLE generation algorithm.
  562.      * @param utc UTC time scale
  563.      * @param teme TEME frame
  564.      * @return a TLE generation algorithm
  565.      * @since 12.0
  566.      */
  567.     public static TleGenerationAlgorithm getDefaultTleGenerationAlgorithm(final TimeScale utc, final Frame teme) {
  568.         return new FixedPointTleGenerationAlgorithm(FixedPointTleGenerationAlgorithm.EPSILON_DEFAULT,
  569.                                                     FixedPointTleGenerationAlgorithm.MAX_ITERATIONS_DEFAULT,
  570.                                                     FixedPointTleGenerationAlgorithm.SCALE_DEFAULT, utc, teme);
  571.     }

  572. }