TLEPropagator.java

  1. /* Copyright 2002-2024 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.SinCos;
  26. import org.orekit.annotation.DefaultDataContext;
  27. import org.orekit.attitudes.Attitude;
  28. import org.orekit.attitudes.AttitudeProvider;
  29. import org.orekit.attitudes.FrameAlignedProvider;
  30. import org.orekit.data.DataContext;
  31. import org.orekit.errors.OrekitException;
  32. import org.orekit.errors.OrekitMessages;
  33. import org.orekit.frames.Frame;
  34. import org.orekit.orbits.CartesianOrbit;
  35. import org.orekit.orbits.Orbit;
  36. import org.orekit.propagation.AbstractMatricesHarvester;
  37. import org.orekit.propagation.MatricesHarvester;
  38. import org.orekit.propagation.SpacecraftState;
  39. import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
  40. import org.orekit.propagation.analytical.tle.generation.FixedPointTleGenerationAlgorithm;
  41. import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
  42. import org.orekit.time.AbsoluteDate;
  43. import org.orekit.time.TimeScale;
  44. import org.orekit.utils.DoubleArrayDictionary;
  45. import org.orekit.utils.PVCoordinates;
  46. import org.orekit.utils.ParameterDriver;
  47. import org.orekit.utils.TimeSpanMap.Span;


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

  74.     // CHECKSTYLE: stop VisibilityModifier check

  75.     /** Initial state. */
  76.     protected TLE tle;

  77.     /** UTC time scale. */
  78.     protected final TimeScale utc;

  79.     /** final RAAN. */
  80.     protected double xnode;

  81.     /** final semi major axis. */
  82.     protected double a;

  83.     /** final eccentricity. */
  84.     protected double e;

  85.     /** final inclination. */
  86.     protected double i;

  87.     /** final perigee argument. */
  88.     protected double omega;

  89.     /** L from SPTRCK #3. */
  90.     protected double xl;

  91.     /** original recovered semi major axis. */
  92.     protected double a0dp;

  93.     /** original recovered mean motion. */
  94.     protected double xn0dp;

  95.     /** cosinus original inclination. */
  96.     protected double cosi0;

  97.     /** cos io squared. */
  98.     protected double theta2;

  99.     /** sinus original inclination. */
  100.     protected double sini0;

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

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

  105.     /** common parameter for raan (OMEGA) computation. */
  106.     protected double xnodot;

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

  111.     /** sqrt (1 - e2). */
  112.     protected double beta0;

  113.     /** perigee, expressed in KM and ALTITUDE. */
  114.     protected double perige;

  115.     /** eta squared. */
  116.     protected double etasq;

  117.     /** original eccentricity * eta. */
  118.     protected double eeta;

  119.     /** s* new value for the contant s. */
  120.     protected double s4;

  121.     /** tsi from SPTRCK #3. */
  122.     protected double tsi;

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

  125.     /** coef for SGP C3 computation. */
  126.     protected double coef;

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

  129.     /** C1 from SPTRCK #3. */
  130.     protected double c1;

  131.     /** C2 from SPTRCK #3. */
  132.     protected double c2;

  133.     /** C4 from SPTRCK #3. */
  134.     protected double c4;

  135.     /** common parameter for raan (OMEGA) computation. */
  136.     protected double xnodcf;

  137.     /** 3/2 * C1. */
  138.     protected double t2cof;

  139.     // CHECKSTYLE: resume VisibilityModifier check

  140.     /** TLE frame. */
  141.     private final Frame teme;

  142.     /** Spacecraft mass (kg). */
  143.     private final double mass;

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

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

  176.         initializeCommons();
  177.         sxpInitialize();
  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, 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.      */
  201.     public static TLEPropagator selectExtrapolator(final TLE tle, final Frame teme) {
  202.         return selectExtrapolator(
  203.                 tle,
  204.                 FrameAlignedProvider.of(teme),
  205.                 DEFAULT_MASS,
  206.                 teme);
  207.     }

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

  224.     /** Selects the extrapolator to use with the selected TLE.
  225.      * @param tle the TLE to propagate.
  226.      * @param attitudeProvider provider for attitude computation
  227.      * @param mass spacecraft mass (kg)
  228.      * @param teme the TEME frame to use for propagation.
  229.      * @return the correct propagator.
  230.      * @since 10.1
  231.      */
  232.     public static TLEPropagator selectExtrapolator(final TLE tle,
  233.                                                    final AttitudeProvider attitudeProvider,
  234.                                                    final double mass,
  235.                                                    final Frame teme) {

  236.         final double a1 = FastMath.pow( TLEConstants.XKE / (tle.getMeanMotion() * 60.0), TLEConstants.TWO_THIRD);
  237.         final double cosi0 = FastMath.cos(tle.getI());
  238.         final double temp = TLEConstants.CK2 * 1.5 * (3 * cosi0 * cosi0 - 1.0) *
  239.                             FastMath.pow(1.0 - tle.getE() * tle.getE(), -1.5);
  240.         final double delta1 = temp / (a1 * a1);
  241.         final double a0 = a1 * (1.0 - delta1 * (TLEConstants.ONE_THIRD + delta1 * (delta1 * 134.0 / 81.0 + 1.0)));
  242.         final double delta0 = temp / (a0 * a0);

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

  245.         // Period >= 225 minutes is deep space
  246.         if (MathUtils.TWO_PI / (xn0dp * TLEConstants.MINUTES_PER_DAY) >= (1.0 / 6.4)) {
  247.             return new DeepSDP4(tle, attitudeProvider, mass, teme);
  248.         } else {
  249.             return new SGP4(tle, attitudeProvider, mass, teme);
  250.         }
  251.     }

  252.     /** Get the Earth gravity coefficient used for TLE propagation.
  253.      * @return the Earth gravity coefficient.
  254.      */
  255.     public static double getMU() {
  256.         return TLEConstants.MU;
  257.     }

  258.     /** Get the extrapolated position and velocity from an initial TLE.
  259.      * @param date the final date
  260.      * @return the final PVCoordinates
  261.      */
  262.     public PVCoordinates getPVCoordinates(final AbsoluteDate date) {

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

  264.         // Compute PV with previous calculated parameters
  265.         return computePVCoordinates();
  266.     }

  267.     /** Computation of the first commons parameters.
  268.      */
  269.     private void initializeCommons() {

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

  272.         final double a1 = FastMath.pow(TLEConstants.XKE / (tle.getMeanMotion() * 60.0), TLEConstants.TWO_THIRD);
  273.         cosi0 = scI0.cos();
  274.         theta2 = cosi0 * cosi0;
  275.         final double x3thm1 = 3.0 * theta2 - 1.0;
  276.         e0sq = tle.getE() * tle.getE();
  277.         beta02 = 1.0 - e0sq;
  278.         beta0 = FastMath.sqrt(beta02);
  279.         final double tval = TLEConstants.CK2 * 1.5 * x3thm1 / (beta0 * beta02);
  280.         final double delta1 = tval / (a1 * a1);
  281.         final double a0 = a1 * (1.0 - delta1 * (TLEConstants.ONE_THIRD + delta1 * (1.0 + 134.0 / 81.0 * delta1)));
  282.         final double delta0 = tval / (a0 * a0);

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

  286.         // Values of s and qms2t :
  287.         s4 = TLEConstants.S;  // unmodified value for s
  288.         double q0ms24 = TLEConstants.QOMS2T; // unmodified value for q0ms2T

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

  290.         //  For perigee below 156 km, the values of s and qoms2t are changed :
  291.         if (perige < 156.0) {
  292.             if (perige <= 98.0) {
  293.                 s4 = 20.0;
  294.             } else {
  295.                 s4 = perige - 78.0;
  296.             }
  297.             final double temp_val = (120.0 - s4) * TLEConstants.NORMALIZED_EQUATORIAL_RADIUS / TLEConstants.EARTH_RADIUS;
  298.             final double temp_val_squared = temp_val * temp_val;
  299.             q0ms24 = temp_val_squared * temp_val_squared;
  300.             s4 = s4 / TLEConstants.EARTH_RADIUS + TLEConstants.NORMALIZED_EQUATORIAL_RADIUS; // new value for q0ms2T and s
  301.         }

  302.         final double pinv = 1.0 / (a0dp * beta02);
  303.         final double pinvsq = pinv * pinv;
  304.         tsi = 1.0 / (a0dp - s4);
  305.         eta = a0dp * tle.getE() * tsi;
  306.         etasq = eta * eta;
  307.         eeta = tle.getE() * eta;

  308.         final double psisq = FastMath.abs(1.0 - etasq); // abs because pow 3.5 needs positive value
  309.         final double tsi_squared = tsi * tsi;
  310.         coef = q0ms24 * tsi_squared * tsi_squared;
  311.         coef1 = coef / FastMath.pow(psisq, 3.5);

  312.         // C2 and C1 coefficients computation :
  313.         c2 = coef1 * xn0dp * (a0dp * (1.0 + 1.5 * etasq + eeta * (4.0 + etasq)) +
  314.              0.75 * TLEConstants.CK2 * tsi / psisq * x3thm1 * (8.0 + 3.0 * etasq * (8.0 + etasq)));
  315.         c1 = tle.getBStar() * c2;
  316.         sini0 = scI0.sin();

  317.         final double x1mth2 = 1.0 - theta2;

  318.         // C4 coefficient computation :
  319.         c4 = 2.0 * xn0dp * coef1 * a0dp * beta02 * (eta * (2.0 + 0.5 * etasq) +
  320.              tle.getE() * (0.5 + 2.0 * etasq) -
  321.              2 * TLEConstants.CK2 * tsi / (a0dp * psisq) *
  322.              (-3.0 * x3thm1 * (1.0 - 2.0 * eeta + etasq * (1.5 - 0.5 * eeta)) +
  323.               0.75 * x1mth2 * (2.0 * etasq - eeta * (1.0 + etasq)) * FastMath.cos(2.0 * tle.getPerigeeArgument())));

  324.         final double theta4 = theta2 * theta2;
  325.         final double temp1 = 3 * TLEConstants.CK2 * pinvsq * xn0dp;
  326.         final double temp2 = temp1 * TLEConstants.CK2 * pinvsq;
  327.         final double temp3 = 1.25 * TLEConstants.CK4 * pinvsq * pinvsq * xn0dp;

  328.         // atmospheric and gravitation coefs :(Mdf and OMEGAdf)
  329.         xmdot = xn0dp +
  330.                 0.5 * temp1 * beta0 * x3thm1 +
  331.                 0.0625 * temp2 * beta0 * (13.0 - 78.0 * theta2 + 137.0 * theta4);

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

  333.         omgdot = -0.5 * temp1 * x1m5th +
  334.                  0.0625 * temp2 * (7.0 - 114.0 * theta2 + 395.0 * theta4) +
  335.                  temp3 * (3.0 - 36.0 * theta2 + 49.0 * theta4);

  336.         final double xhdot1 = -temp1 * cosi0;

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

  340.     }

  341.     /** Retrieves the position and velocity.
  342.      * @return the computed PVCoordinates.
  343.      */
  344.     private PVCoordinates computePVCoordinates() {

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

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

  363.         // Dundee changes:  items dependent on cosio get recomputed:
  364.         final double cosi0Sq = cosi0 * cosi0;
  365.         final double x3thm1 = 3.0 * cosi0Sq - 1.0;
  366.         final double x1mth2 = 1.0 - cosi0Sq;
  367.         final double x7thm1 = 7.0 * cosi0Sq - 1.0;

  368.         if (e > (1 - 1e-6)) {
  369.             throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL, e);
  370.         }

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

  374.             boolean doSecondOrderNewtonRaphson = true;

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

  402.         // Short period preliminary quantities
  403.         temp = 1.0 - elsq;
  404.         final double pl = a * temp;
  405.         final double r = a * (1.0 - ecosE);
  406.         double temp2 = a / r;
  407.         final double betal = FastMath.sqrt(temp);
  408.         temp = esinE / (1.0 + betal);
  409.         final double cosu = temp2 * (cosEPW - axn + ayn * temp);
  410.         final double sinu = temp2 * (sinEPW - ayn - axn * temp);
  411.         final double u = FastMath.atan2(sinu, cosu);
  412.         final double sin2u = 2.0 * sinu * cosu;
  413.         final double cos2u = 2.0 * cosu * cosu - 1.0;
  414.         final double temp1 = TLEConstants.CK2 / pl;
  415.         temp2 = temp1 / pl;

  416.         // Update for short periodics
  417.         final double rk = r * (1.0 - 1.5 * temp2 * betal * x3thm1) + 0.5 * temp1 * x1mth2 * cos2u;
  418.         final double uk = u - 0.25 * temp2 * x7thm1 * sin2u;
  419.         final double xnodek = xnode + 1.5 * temp2 * cosi0 * sin2u;
  420.         final double xinck = i + 1.5 * temp2 * cosi0 * sini0 * cos2u;

  421.         // Orientation vectors
  422.         final SinCos scuk   = FastMath.sinCos(uk);
  423.         final SinCos scik   = FastMath.sinCos(xinck);
  424.         final SinCos scnok  = FastMath.sinCos(xnodek);
  425.         final double sinuk  = scuk.sin();
  426.         final double cosuk  = scuk.cos();
  427.         final double sinik  = scik.sin();
  428.         final double cosik  = scik.cos();
  429.         final double sinnok = scnok.sin();
  430.         final double cosnok = scnok.cos();
  431.         final double xmx = -sinnok * cosik;
  432.         final double xmy = cosnok * cosik;
  433.         final double ux  = xmx * sinuk + cosnok * cosuk;
  434.         final double uy  = xmy * sinuk + sinnok * cosuk;
  435.         final double uz  = sinik * sinuk;

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

  439.         final double rdot   = TLEConstants.XKE * FastMath.sqrt(a) * esinE / r;
  440.         final double rfdot  = TLEConstants.XKE * FastMath.sqrt(pl) / r;
  441.         final double xn     = TLEConstants.XKE / (a * FastMath.sqrt(a));
  442.         final double rdotk  = rdot - xn * temp1 * x1mth2 * sin2u;
  443.         final double rfdotk = rfdot + xn * temp1 * (x1mth2 * cos2u + 1.5 * x3thm1);
  444.         final double vx     = xmx * cosuk - cosnok * sinuk;
  445.         final double vy     = xmy * cosuk - sinnok * sinuk;
  446.         final double vz     = sinik * cosuk;

  447.         final double cv = 1000.0 * TLEConstants.EARTH_RADIUS / 60.0;
  448.         final Vector3D vel = new Vector3D(cv * (rdotk * ux + rfdotk * vx),
  449.                                           cv * (rdotk * uy + rfdotk * vy),
  450.                                           cv * (rdotk * uz + rfdotk * vz));

  451.         return new PVCoordinates(pos, vel);

  452.     }

  453.     /** Initialization proper to each propagator (SGP or SDP).
  454.      */
  455.     protected abstract void sxpInitialize();

  456.     /** Propagation proper to each propagator (SGP or SDP).
  457.      * @param t the offset from initial epoch (min)
  458.      */
  459.     protected abstract void sxpPropagate(double t);

  460.     /** {@inheritDoc}
  461.      * <p>
  462.      * For TLE propagator, calling this method is only recommended
  463.      * for covariance propagation when the new <code>state</code>
  464.      * differs from the previous one by only adding the additional
  465.      * state containing the derivatives.
  466.      * </p>
  467.      */
  468.     public void resetInitialState(final SpacecraftState state) {
  469.         super.resetInitialState(state);
  470.         super.setStartDate(state.getDate());
  471.         final TleGenerationAlgorithm algorithm = getDefaultTleGenerationAlgorithm(utc, teme);
  472.         final TLE newTLE = algorithm.generate(state, tle);
  473.         this.tle = newTLE;
  474.         initializeCommons();
  475.         sxpInitialize();
  476.     }

  477.     /** {@inheritDoc} */
  478.     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
  479.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  480.     }

  481.     /** {@inheritDoc} */
  482.     protected double getMass(final AbsoluteDate date) {
  483.         return mass;
  484.     }

  485.     /** {@inheritDoc} */
  486.     protected Orbit propagateOrbit(final AbsoluteDate date) {
  487.         return new CartesianOrbit(getPVCoordinates(date), teme, date, TLEConstants.MU);
  488.     }

  489.     /** Get the underlying TLE.
  490.      * @return underlying TLE
  491.      */
  492.     public TLE getTLE() {
  493.         return tle;
  494.     }

  495.     /** {@inheritDoc} */
  496.     public Frame getFrame() {
  497.         return teme;
  498.     }

  499.     /** {@inheritDoc} */
  500.     @Override
  501.     protected AbstractMatricesHarvester createHarvester(final String stmName, final RealMatrix initialStm,
  502.                                                         final DoubleArrayDictionary initialJacobianColumns) {
  503.         // Create the harvester
  504.         final TLEHarvester harvester = new TLEHarvester(this, stmName, initialStm, initialJacobianColumns);
  505.         // Update the list of additional state provider
  506.         addAdditionalStateProvider(harvester);
  507.         // Return the configured harvester
  508.         return harvester;
  509.     }

  510.     /**
  511.      * Get the names of the parameters in the matrix returned by {@link MatricesHarvester#getParametersJacobian}.
  512.      * @return names of the parameters (i.e. columns) of the Jacobian matrix
  513.      */
  514.     protected List<String> getJacobiansColumnsNames() {
  515.         final List<String> columnsNames = new ArrayList<>();
  516.         for (final ParameterDriver driver : tle.getParametersDrivers()) {

  517.             if (driver.isSelected() && !columnsNames.contains(driver.getNamesSpanMap().getFirstSpan().getData())) {
  518.                 // As driver with same name should have same NamesSpanMap we only check the if condition on the
  519.                 // first span map and then if the condition is OK all the span names are added to the jacobian column names
  520.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  521.                     columnsNames.add(span.getData());
  522.                 }
  523.             }
  524.         }
  525.         Collections.sort(columnsNames);
  526.         return columnsNames;
  527.     }

  528.     /**
  529.      * Get the default TLE generation algorithm.
  530.      * @param utc UTC time scale
  531.      * @param teme TEME frame
  532.      * @return a TLE generation algorithm
  533.      * @since 12.0
  534.      */
  535.     public static TleGenerationAlgorithm getDefaultTleGenerationAlgorithm(final TimeScale utc, final Frame teme) {
  536.         return new FixedPointTleGenerationAlgorithm(FixedPointTleGenerationAlgorithm.EPSILON_DEFAULT,
  537.                                                     FixedPointTleGenerationAlgorithm.MAX_ITERATIONS_DEFAULT,
  538.                                                     FixedPointTleGenerationAlgorithm.SCALE_DEFAULT, utc, teme);
  539.     }

  540. }