FieldTLEPropagator.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.List;

  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.hipparchus.util.MathUtils;
  23. import org.hipparchus.util.Pair;
  24. import org.orekit.annotation.DefaultDataContext;
  25. import org.orekit.attitudes.AttitudeProvider;
  26. import org.orekit.attitudes.FieldAttitude;
  27. import org.orekit.attitudes.FrameAlignedProvider;
  28. import org.orekit.data.DataContext;
  29. import org.orekit.errors.OrekitException;
  30. import org.orekit.errors.OrekitMessages;
  31. import org.orekit.frames.Frame;
  32. import org.orekit.orbits.FieldCartesianOrbit;
  33. import org.orekit.orbits.FieldOrbit;
  34. import org.orekit.propagation.FieldSpacecraftState;
  35. import org.orekit.propagation.analytical.FieldAbstractAnalyticalPropagator;
  36. import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
  37. import org.orekit.time.FieldAbsoluteDate;
  38. import org.orekit.time.TimeScale;
  39. import org.orekit.utils.FieldPVCoordinates;
  40. import org.orekit.utils.PVCoordinates;
  41. import org.orekit.utils.ParameterDriver;
  42. import org.orekit.utils.TimeSpanMap;


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

  72.     // CHECKSTYLE: stop VisibilityModifier check

  73.     /** Initial state. */
  74.     protected FieldTLE<T> tle;

  75.     /** UTC time scale. */
  76.     protected final TimeScale utc;

  77.     /** final RAAN. */
  78.     protected T xnode;

  79.     /** final semi major axis. */
  80.     protected T a;

  81.     /** final eccentricity. */
  82.     protected T e;

  83.     /** final inclination. */
  84.     protected T i;

  85.     /** final perigee argument. */
  86.     protected T omega;

  87.     /** L from SPTRCK #3. */
  88.     protected T xl;

  89.     /** original recovered semi major axis. */
  90.     protected T a0dp;

  91.     /** original recovered mean motion. */
  92.     protected T xn0dp;

  93.     /** cosinus original inclination. */
  94.     protected T cosi0;

  95.     /** cos io squared. */
  96.     protected T theta2;

  97.     /** sinus original inclination. */
  98.     protected T sini0;

  99.     /** common parameter for mean anomaly (M) computation. */
  100.     protected T xmdot;

  101.     /** common parameter for perigee argument (omega) computation. */
  102.     protected T omgdot;

  103.     /** common parameter for raan (OMEGA) computation. */
  104.     protected T xnodot;

  105.     /** original eccentricity squared. */
  106.     protected T e0sq;
  107.     /** 1 - e2. */
  108.     protected T beta02;

  109.     /** sqrt (1 - e2). */
  110.     protected T beta0;

  111.     /** perigee, expressed in KM and ALTITUDE. */
  112.     protected T perige;

  113.     /** eta squared. */
  114.     protected T etasq;

  115.     /** original eccentricity * eta. */
  116.     protected T eeta;

  117.     /** s* new value for the contant s. */
  118.     protected T s4;

  119.     /** tsi from SPTRCK #3. */
  120.     protected T tsi;

  121.     /** eta from SPTRCK #3. */
  122.     protected T eta;

  123.     /** coef for SGP C3 computation. */
  124.     protected T coef;

  125.     /** coef for SGP C5 computation. */
  126.     protected T coef1;

  127.     /** C1 from SPTRCK #3. */
  128.     protected T c1;

  129.     /** C2 from SPTRCK #3. */
  130.     protected T c2;

  131.     /** C4 from SPTRCK #3. */
  132.     protected T c4;

  133.     /** common parameter for raan (OMEGA) computation. */
  134.     protected T xnodcf;

  135.     /** 3/2 * C1. */
  136.     protected T t2cof;

  137.     // CHECKSTYLE: resume VisibilityModifier check

  138.     /** TLE frame. */
  139.     private final Frame teme;

  140.     /** All TLEs and masses. */
  141.     private TimeSpanMap<Pair<FieldTLE<T>, T>> tlesAndMasses;

  142.     /** Protected constructor for derived classes.
  143.      *
  144.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  145.      *
  146.      * @param initialTLE the unique TLE to propagate
  147.      * @param attitudeProvider provider for attitude computation
  148.      * @param mass spacecraft mass (kg)
  149.      * @param parameters SGP4 and SDP4 model parameters
  150.      * @see #FieldTLEPropagator(FieldTLE, AttitudeProvider, CalculusFieldElement, Frame, CalculusFieldElement[])
  151.      */
  152.     @DefaultDataContext
  153.     protected FieldTLEPropagator(final FieldTLE<T> initialTLE, final AttitudeProvider attitudeProvider, final T mass,
  154.                                  final T[] parameters) {
  155.         this(initialTLE, attitudeProvider, mass, DataContext.getDefault().getFrames().getTEME(), parameters);
  156.     }

  157.     /** Protected constructor for derived classes.
  158.      * @param initialTLE the unique TLE to propagate
  159.      * @param attitudeProvider provider for attitude computation
  160.      * @param mass spacecraft mass (kg)
  161.      * @param teme the TEME frame to use for propagation.
  162.      * @param parameters SGP4 and SDP4 model parameters
  163.      */
  164.     protected FieldTLEPropagator(final FieldTLE<T> initialTLE, final AttitudeProvider attitudeProvider, final T mass,
  165.                                  final Frame teme, final T[] parameters) {
  166.         super(initialTLE.getE().getField(), attitudeProvider);
  167.         setStartDate(initialTLE.getDate());
  168.         this.utc       = initialTLE.getUtc();
  169.         initializeTle(initialTLE);
  170.         this.teme      = teme;
  171.         this.tlesAndMasses      = new TimeSpanMap<>(new Pair<>(tle, mass));

  172.         initializeCommons(parameters);
  173.         sxpInitialize(parameters);
  174.         // set the initial state
  175.         final FieldOrbit<T> orbit = propagateOrbit(initialTLE.getDate(), parameters);
  176.         final FieldAttitude<T> attitude = attitudeProvider.getAttitude(orbit, orbit.getDate(), orbit.getFrame());
  177.         super.resetInitialState(new FieldSpacecraftState<>(orbit, attitude).withMass(mass));
  178.     }

  179.     /** Selects the extrapolator to use with the selected TLE.
  180.      *
  181.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  182.      *
  183.      * @param tle the TLE to propagate.
  184.      * @param parameters SGP4 and SDP4 model parameters
  185.      * @return the correct propagator.
  186.      * @param <T> elements type
  187.      * @see #selectExtrapolator(FieldTLE, Frame, CalculusFieldElement[])
  188.      */
  189.     @DefaultDataContext
  190.     public static <T extends CalculusFieldElement<T>> FieldTLEPropagator<T> selectExtrapolator(final FieldTLE<T> tle, final T[] parameters) {
  191.         return selectExtrapolator(tle, DataContext.getDefault().getFrames().getTEME(), parameters);
  192.     }

  193.     /** Selects the extrapolator to use with the selected TLE.
  194.      *
  195.      *<p>This method uses the {@link DataContext#getDefault() default data context}.
  196.      *
  197.      * @param tle the TLE to propagate.
  198.      * @param teme TEME frame.
  199.      * @param parameters SGP4 and SDP4 model parameters
  200.      * @return the correct propagator.
  201.      * @param <T> elements type
  202.      */
  203.     public static <T extends CalculusFieldElement<T>> FieldTLEPropagator<T> selectExtrapolator(final FieldTLE<T> tle, final Frame teme, final T[] parameters) {
  204.         return selectExtrapolator(
  205.                 tle,
  206.                 FrameAlignedProvider.of(teme),
  207.                 tle.getE().getField().getZero().newInstance(DEFAULT_MASS),
  208.                 teme,
  209.                 parameters);
  210.     }

  211.     /** Selects the extrapolator to use with the selected TLE.
  212.      *
  213.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  214.      *
  215.      * @param tle the TLE to propagate.
  216.      * @param attitudeProvider provider for attitude computation
  217.      * @param mass spacecraft mass (kg)
  218.      * @param parameters SGP4 and SDP4 model parameters
  219.      * @return the correct propagator.
  220.      * @param <T> elements type
  221.      * @see #selectExtrapolator(FieldTLE, AttitudeProvider, CalculusFieldElement, Frame, CalculusFieldElement[])
  222.      */
  223.     @DefaultDataContext
  224.     public static <T extends CalculusFieldElement<T>> FieldTLEPropagator<T> selectExtrapolator(final FieldTLE<T> tle,
  225.                                                    final AttitudeProvider attitudeProvider,
  226.                                                    final T mass,
  227.                                                    final T[] parameters) {
  228.         return selectExtrapolator(tle, attitudeProvider, mass,
  229.                 DataContext.getDefault().getFrames().getTEME(), parameters);
  230.     }

  231.     /** Selects the extrapolator to use with the selected TLE.
  232.      *
  233.      * @param tle the TLE to propagate.
  234.      * @param attitudeProvider provider for attitude computation
  235.      * @param mass spacecraft mass (kg)
  236.      * @param teme the TEME frame to use for propagation.
  237.      * @param parameters SGP4 and SDP4 model parameters
  238.      * @return the correct propagator.
  239.      * @param <T> elements type
  240.      */
  241.     public static <T extends CalculusFieldElement<T>> FieldTLEPropagator<T> selectExtrapolator(final FieldTLE<T> tle,
  242.                                                    final AttitudeProvider attitudeProvider,
  243.                                                    final T mass,
  244.                                                    final Frame teme,
  245.                                                    final T[] parameters) {

  246.         final T a1 = tle.getMeanMotion().multiply(60.0).reciprocal().multiply(TLEConstants.XKE).pow(TLEConstants.TWO_THIRD);
  247.         final T cosi0 = FastMath.cos(tle.getI());
  248.         final T temp1 = cosi0.multiply(cosi0.multiply(3.0)).subtract(1.0).multiply(1.5 * TLEConstants.CK2);
  249.         final T temp2 = tle.getE().multiply(tle.getE()).negate().add(1.0).pow(-1.5);
  250.         final T temp = temp1.multiply(temp2);
  251.         final T delta1 = temp.divide(a1.multiply(a1));
  252.         final T a0 = a1.multiply(delta1.multiply(delta1.multiply(
  253.                         delta1.multiply(134.0 / 81.0).add(1.0)).add(TLEConstants.ONE_THIRD)).negate().add(1.0));
  254.         final T delta0 = temp.divide(a0.multiply(a0));

  255.         // recover original mean motion :
  256.         final T xn0dp = tle.getMeanMotion().multiply(60.0).divide(delta0.add(1.0));

  257.         // Period >= 225 minutes is deep space
  258.         if (MathUtils.TWO_PI / (xn0dp.multiply(TLEConstants.MINUTES_PER_DAY).getReal()) >= (1.0 / 6.4)) {
  259.             return new FieldDeepSDP4<>(tle, attitudeProvider, mass, teme, parameters);
  260.         } else {
  261.             return new FieldSGP4<>(tle, attitudeProvider, mass, teme, parameters);
  262.         }
  263.     }

  264.     /** Get the Earth gravity coefficient used for TLE propagation.
  265.      * @return the Earth gravity coefficient.
  266.      */
  267.     public static double getMU() {
  268.         return TLEConstants.MU;
  269.     }

  270.     /** Get the extrapolated position and velocity from an initial TLE.
  271.      * @param date the final date
  272.      * @param parameters values of the model
  273.      * @return the final PVCoordinates
  274.      */
  275.     public FieldPVCoordinates<T> getPVCoordinates(final FieldAbsoluteDate<T> date, final T[] parameters) {

  276.         sxpPropagate(date.durationFrom(tle.getDate()).divide(60.0), parameters);

  277.         // Compute PV with previous calculated parameters
  278.         return computePVCoordinates();
  279.     }

  280.     /** Computation of the first commons parameters.
  281.      * @param parameters SGP4 and SDP4 model parameters
  282.      */
  283.     private void initializeCommons(final T[] parameters) {

  284.         final T zero = tle.getDate().getField().getZero();
  285.         final T bStar = parameters[0];
  286.         final T a1 = tle.getMeanMotion().multiply(60.0).reciprocal().multiply(TLEConstants.XKE).pow(TLEConstants.TWO_THIRD);
  287.         cosi0 = FastMath.cos(tle.getI());
  288.         theta2 = cosi0.multiply(cosi0);
  289.         final T x3thm1 = theta2.multiply(3.0).subtract(1.0);
  290.         e0sq = tle.getE().square();
  291.         beta02 = e0sq.negate().add(1.0);
  292.         beta0 = FastMath.sqrt(beta02);
  293.         final T tval = x3thm1.multiply(1.5 * TLEConstants.CK2).divide(beta0.multiply(beta02));
  294.         final T delta1 = tval.divide(a1.multiply(a1));
  295.         final T a0 = a1.multiply(delta1.multiply(
  296.                      delta1.multiply(134.0 / 81.0).add(1.0).multiply(delta1).add(TLEConstants.ONE_THIRD)).negate().add(1.0));
  297.         final T delta0 = tval.divide(a0.multiply(a0));

  298.         // recover original mean motion and semi-major axis :
  299.         xn0dp = tle.getMeanMotion().multiply(60.0).divide(delta0.add(1.0));
  300.         a0dp = a0.divide(delta0.negate().add(1.0));

  301.         // Values of s and qms2t :
  302.         s4 = zero.newInstance(TLEConstants.S);  // unmodified value for s
  303.         T q0ms24 = zero.newInstance(TLEConstants.QOMS2T); // unmodified value for q0ms2T

  304.         perige = a0dp.multiply(tle.getE().negate().add(1.0)).subtract(TLEConstants.NORMALIZED_EQUATORIAL_RADIUS).multiply(
  305.                                                                                                 TLEConstants.EARTH_RADIUS); // perige

  306.         //  For perigee below 156 km, the values of s and qoms2t are changed :
  307.         if (perige.getReal() < 156.0) {
  308.             if (perige.getReal() <= 98.0) {
  309.                 s4 = zero.newInstance(20.0);
  310.             } else {
  311.                 s4 = perige.subtract(78.0);
  312.             }
  313.             final T temp_val = s4.negate().add(120.0).multiply(TLEConstants.NORMALIZED_EQUATORIAL_RADIUS / TLEConstants.EARTH_RADIUS);
  314.             final T temp_val_squared = temp_val.multiply(temp_val);
  315.             q0ms24 = temp_val_squared.square();
  316.             s4 = s4.divide(TLEConstants.EARTH_RADIUS).add(TLEConstants.NORMALIZED_EQUATORIAL_RADIUS); // new value for q0ms2T and s
  317.         }

  318.         final T pinv = a0dp.multiply(beta02).reciprocal();
  319.         final T pinvsq = pinv.square();
  320.         tsi = a0dp.subtract(s4).reciprocal();
  321.         eta = a0dp.multiply(tle.getE()).multiply(tsi);
  322.         etasq = eta.square();
  323.         eeta = tle.getE().multiply(eta);

  324.         final T psisq = etasq.negate().add(1.0).abs(); // abs because pow 3.5 needs positive value
  325.         final T tsi_squared = tsi.multiply(tsi);
  326.         coef = q0ms24.multiply(tsi_squared.square());
  327.         coef1 = coef.divide(psisq.pow(3.5));

  328.         // C2 and C1 coefficients computation :
  329.         c2 = coef1.multiply(xn0dp).multiply(a0dp.multiply(
  330.                            etasq.multiply(1.5).add(eeta.multiply(etasq.add(4.0))).add(1.0)).add(
  331.                            tsi.divide(psisq).multiply(x3thm1).multiply(0.75 * TLEConstants.CK2).multiply(
  332.                            etasq.multiply(etasq.add(8.0)).multiply(3.0).add(8.0))));
  333.         c1 = bStar.multiply(c2);
  334.         sini0 = FastMath.sin(tle.getI());

  335.         final T x1mth2 = theta2.negate().add(1.0);

  336.         // C4 coefficient computation :
  337.         c4 = xn0dp.multiply(coef1).multiply(a0dp).multiply(2.0).multiply(beta02).multiply(
  338.                            eta.multiply(etasq.multiply(0.5).add(2.0)).add(tle.getE().multiply(etasq.multiply(2.0).add(0.5))).subtract(
  339.                            tsi.divide(a0dp.multiply(psisq)).multiply(2 * TLEConstants.CK2).multiply(
  340.                            x3thm1.multiply(-3).multiply(etasq.multiply(eeta.multiply(-0.5).add(1.5)).add(eeta.multiply(-2.0)).add(1.0)).add(
  341.                            x1mth2.multiply(0.75).multiply(etasq.multiply(2.0).subtract(eeta.multiply(etasq.add(1.0)))).multiply(FastMath.cos(tle.getPerigeeArgument().multiply(2.0)))))));

  342.         final T theta4 = theta2.multiply(theta2);
  343.         final T temp1  = pinvsq.multiply(xn0dp).multiply(3 * TLEConstants.CK2);
  344.         final T temp2  = temp1.multiply(pinvsq).multiply(TLEConstants.CK2);
  345.         final T temp3  = pinvsq.multiply(pinvsq).multiply(xn0dp).multiply(1.25 * TLEConstants.CK4);

  346.         // atmospheric and gravitation coefs :(Mdf and OMEGAdf)
  347.         xmdot = xn0dp.add(
  348.                 temp1.multiply(0.5).multiply(beta0).multiply(x3thm1)).add(
  349.                 temp2.multiply(0.0625).multiply(beta0).multiply(
  350.                 theta2.multiply(78.0).negate().add(13.0).add(theta4.multiply(137.0))));

  351.         final T x1m5th = theta2.multiply(5.0).negate().add(1.0);

  352.         omgdot = temp1.multiply(-0.5).multiply(x1m5th).add(
  353.                  temp2.multiply(0.0625).multiply(theta2.multiply(114.0).negate().add(
  354.                  theta4.multiply(395.0)).add(7.0))).add(
  355.                  temp3.multiply(theta2.multiply(36.0).negate().add(theta4.multiply(49.0)).add(3.0)));

  356.         final T xhdot1 = temp1.negate().multiply(cosi0);

  357.         xnodot = xhdot1.add(temp2.multiply(0.5).multiply(theta2.multiply(19.0).negate().add(4.0)).add(
  358.                  temp3.multiply(2.0).multiply(theta2.multiply(7.0).negate().add(3.0))).multiply(cosi0));
  359.         xnodcf = beta02.multiply(xhdot1).multiply(c1).multiply(3.5);
  360.         t2cof = c1.multiply(1.5);

  361.     }

  362.     /** Retrieves the position and velocity.
  363.      * @return the computed PVCoordinates.
  364.      */
  365.     private FieldPVCoordinates<T> computePVCoordinates() {

  366.         final T zero = tle.getDate().getField().getZero();
  367.         // Long period periodics
  368.         final T axn = e.multiply(FastMath.cos(omega));
  369.         T temp = a.multiply(e.multiply(e).negate().add(1.0)).reciprocal();
  370.         final T xlcof = sini0.multiply(0.125 * TLEConstants.A3OVK2).multiply(
  371.                              cosi0.multiply(5.0).add(3.0).divide(cosi0.add(1.0)));
  372.         final T aycof = sini0.multiply(0.25 * TLEConstants.A3OVK2);
  373.         final T xll   = temp.multiply(xlcof).multiply(axn);
  374.         final T aynl  = temp.multiply(aycof);
  375.         final T xlt   = xl.add(xll);
  376.         final T ayn   = e.multiply(FastMath.sin(omega)).add(aynl);
  377.         final T elsq  = axn.square().add(ayn.square());
  378.         final T capu  = MathUtils.normalizeAngle(xlt.subtract(xnode), zero.getPi());
  379.         T epw    = capu;
  380.         T ecosE  = zero;
  381.         T esinE  = zero;
  382.         T sinEPW = zero;
  383.         T cosEPW = zero;

  384.         // Dundee changes:  items dependent on cosio get recomputed:
  385.         final T cosi0Sq = cosi0.square();
  386.         final T x3thm1  = cosi0Sq.multiply(3.0).subtract(1.0);
  387.         final T x1mth2  = cosi0Sq.negate().add(1.0);
  388.         final T x7thm1  = cosi0Sq.multiply(7.0).subtract(1.0);

  389.         if (e.getReal() > (1 - 1e-6)) {
  390.             throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL, e);
  391.         }

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

  395.             boolean doSecondOrderNewtonRaphson = true;

  396.             sinEPW = FastMath.sin( epw);
  397.             cosEPW = FastMath.cos( epw);
  398.             ecosE  = axn.multiply(cosEPW).add(ayn.multiply(sinEPW));
  399.             esinE  = axn.multiply(sinEPW).subtract(ayn.multiply(cosEPW));
  400.             final T f = capu.subtract(epw).add(esinE);
  401.             if (FastMath.abs(f.getReal()) < newtonRaphsonEpsilon) {
  402.                 break;
  403.             }
  404.             final T fdot = ecosE.negate().add(1.0);
  405.             T delta_epw = f.divide(fdot);
  406.             if (j == 0) {
  407.                 final T maxNewtonRaphson = e.abs().multiply(1.25);
  408.                 doSecondOrderNewtonRaphson = false;
  409.                 if (delta_epw.getReal() > maxNewtonRaphson.getReal()) {
  410.                     delta_epw = maxNewtonRaphson;
  411.                 } else if (delta_epw.getReal() < -maxNewtonRaphson.getReal()) {
  412.                     delta_epw = maxNewtonRaphson.negate();
  413.                 } else {
  414.                     doSecondOrderNewtonRaphson = true;
  415.                 }
  416.             }
  417.             if (doSecondOrderNewtonRaphson) {
  418.                 delta_epw = f.divide(fdot.add(esinE.multiply(0.5).multiply(delta_epw)));
  419.             }
  420.             epw = epw.add(delta_epw);
  421.         }

  422.         // Short period preliminary quantities
  423.         temp = elsq.negate().add(1.0);
  424.         final T pl = a.multiply(temp);
  425.         final T r  = a.multiply(ecosE.negate().add(1.0));
  426.         T temp2 = a.divide(r);
  427.         final T betal = FastMath.sqrt(temp);
  428.         temp = esinE.divide(betal.add(1.0));
  429.         final T cosu  = temp2.multiply(cosEPW.subtract(axn).add(ayn.multiply(temp)));
  430.         final T sinu  = temp2.multiply(sinEPW.subtract(ayn).subtract(axn.multiply(temp)));
  431.         final T u     = FastMath.atan2(sinu, cosu);
  432.         final T sin2u = sinu.multiply(cosu).multiply(2.0);
  433.         final T cos2u = cosu.multiply(cosu).multiply(2.0).subtract(1.0);
  434.         final T temp1 = pl.reciprocal().multiply(TLEConstants.CK2);
  435.         temp2         = temp1.divide(pl);

  436.         // Update for short periodics
  437.         final T rk = r.multiply(temp2.multiply(betal).multiply(x3thm1).multiply(-1.5).add(1.0)).add(
  438.                      temp1.multiply(x1mth2).multiply(cos2u).multiply(0.5));
  439.         final T uk = u.subtract(temp2.multiply(x7thm1).multiply(sin2u).multiply(0.25));
  440.         final T xnodek = xnode.add(temp2.multiply(cosi0).multiply(sin2u).multiply(1.5));
  441.         final T xinck = i.add(temp2.multiply(cosi0).multiply(sini0).multiply(cos2u).multiply(1.5));

  442.         // Orientation vectors
  443.         final T sinuk  = FastMath.sin(uk);
  444.         final T cosuk  = FastMath.cos(uk);
  445.         final T sinik  = FastMath.sin(xinck);
  446.         final T cosik  = FastMath.cos(xinck);
  447.         final T sinnok = FastMath.sin(xnodek);
  448.         final T cosnok = FastMath.cos(xnodek);
  449.         final T xmx    = sinnok.negate().multiply(cosik);
  450.         final T xmy    = cosnok.multiply(cosik);
  451.         final T ux     = xmx.multiply(sinuk).add(cosnok.multiply(cosuk));
  452.         final T uy     = xmy.multiply(sinuk).add(sinnok.multiply(cosuk));
  453.         final T uz     = sinik.multiply(sinuk);

  454.         // Position and velocity
  455.         final T cr = rk.multiply(1000 * TLEConstants.EARTH_RADIUS);
  456.         final FieldVector3D<T> pos = new FieldVector3D<>(cr.multiply(ux), cr.multiply(uy), cr.multiply(uz));

  457.         final T sqrtA  = FastMath.sqrt(a);
  458.         final T rdot   = sqrtA.multiply(esinE.divide(r)).multiply(TLEConstants.XKE);
  459.         final T rfdot  = FastMath.sqrt(pl).divide(r).multiply(TLEConstants.XKE);
  460.         final T xn     = a.multiply(sqrtA).reciprocal().multiply(TLEConstants.XKE);
  461.         final T rdotk  = rdot.subtract(xn.multiply(temp1).multiply(x1mth2).multiply(sin2u));
  462.         final T rfdotk = rfdot.add(xn.multiply(temp1).multiply(x1mth2.multiply(cos2u).add(x3thm1.multiply(1.5))));
  463.         final T vx     = xmx.multiply(cosuk).subtract(cosnok.multiply(sinuk));
  464.         final T vy     = xmy.multiply(cosuk).subtract(sinnok.multiply(sinuk));
  465.         final T vz     = sinik.multiply(cosuk);

  466.         final double cv = 1000.0 * TLEConstants.EARTH_RADIUS / 60.0;
  467.         final FieldVector3D<T> vel = new FieldVector3D<>(rdotk.multiply(ux).add(rfdotk.multiply(vx)).multiply(cv),
  468.                                                           rdotk.multiply(uy).add(rfdotk.multiply(vy)).multiply(cv),
  469.                                                           rdotk.multiply(uz).add(rfdotk.multiply(vz)).multiply(cv));
  470.         return new FieldPVCoordinates<>(pos, vel);

  471.     }

  472.     /** {@inheritDoc} */
  473.     @Override
  474.     public List<ParameterDriver> getParametersDrivers() {
  475.         return tle.getParametersDrivers();
  476.     }

  477.     /** Initialization proper to each propagator (SGP or SDP).
  478.      * @param parameters model parameters
  479.      */
  480.     protected abstract void sxpInitialize(T[] parameters);

  481.     /** Propagation proper to each propagator (SGP or SDP).
  482.      * @param t the offset from initial epoch (min)
  483.      * @param parameters model parameters
  484.      */
  485.     protected abstract void sxpPropagate(T t, T[] parameters);

  486.     /** {@inheritDoc}
  487.      * <p>
  488.      * For TLE propagator, calling this method is only recommended
  489.      * for covariance propagation when the new <code>state</code>
  490.      * differs from the previous one by only adding the additional
  491.      * state containing the derivatives.
  492.      * </p>
  493.      */
  494.     public void resetInitialState(final FieldSpacecraftState<T> state) {
  495.         super.resetInitialState(state);
  496.         resetTle(state);
  497.         tlesAndMasses = new TimeSpanMap<>(new Pair<>(tle, state.getMass()));
  498.     }

  499.     /** {@inheritDoc} */
  500.     protected void resetIntermediateState(final FieldSpacecraftState<T> state, final boolean forward) {
  501.         resetTle(state);
  502.         final Pair<FieldTLE<T>, T> tleAndMass = new Pair<>(tle, state.getMass());
  503.         if (forward) {
  504.             tlesAndMasses.addValidAfter(tleAndMass, state.getDate().toAbsoluteDate(), false);
  505.         } else {
  506.             tlesAndMasses.addValidBefore(tleAndMass, state.getDate().toAbsoluteDate(), false);
  507.         }
  508.         stateChanged(state);
  509.     }

  510.     /** Reset internal TLE from a SpacecraftState.
  511.      * @param state spacecraft state on which to base new TLE
  512.      */
  513.     private void resetTle(final FieldSpacecraftState<T> state) {
  514.         final TleGenerationAlgorithm algorithm = TLEPropagator.getDefaultTleGenerationAlgorithm(utc, teme);
  515.         final FieldTLE<T> newTle = algorithm.generate(state, tle);
  516.         initializeTle(newTle);
  517.     }

  518.     /** Initialize internal TLE.
  519.      * @param newTle tle to replace current one
  520.      */
  521.     private void initializeTle(final FieldTLE<T> newTle) {
  522.         tle = newTle;
  523.         final T[] parameters = tle.getParameters(tle.getDate().getField());
  524.         initializeCommons(parameters);
  525.         sxpInitialize(parameters);
  526.     }

  527.     /** {@inheritDoc} */
  528.     protected T getMass(final FieldAbsoluteDate<T> date) {
  529.         return tlesAndMasses.get(date.toAbsoluteDate()).getValue();
  530.     }

  531.     /** {@inheritDoc} */
  532.     public FieldOrbit<T> propagateOrbit(final FieldAbsoluteDate<T> date, final T[] parameters) {
  533.         final FieldTLE<T> closestTle = tlesAndMasses.get(date.toAbsoluteDate()).getKey();
  534.         if (!tle.equals(closestTle)) {
  535.             initializeTle(closestTle);
  536.         }
  537.         final T mu = date.getField().getZero().newInstance(TLEConstants.MU);
  538.         return new FieldCartesianOrbit<>(getPVCoordinates(date, parameters), teme, date, mu);
  539.     }

  540.     /** Get the underlying TLE.
  541.      * If there has been calls to #resetInitialState or #resetIntermediateState,
  542.      * it will not be the same as given to the constructor.
  543.      * @return underlying TLE
  544.      */
  545.     public FieldTLE<T> getTLE() {
  546.         return tle;
  547.     }

  548.     /** {@inheritDoc} */
  549.     public Frame getFrame() {
  550.         return teme;
  551.     }

  552. }