FieldTLEPropagator.java

  1. /* Copyright 2002-2022 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.orekit.annotation.DefaultDataContext;
  24. import org.orekit.attitudes.AttitudeProvider;
  25. import org.orekit.attitudes.FieldAttitude;
  26. import org.orekit.attitudes.InertialProvider;
  27. import org.orekit.data.DataContext;
  28. import org.orekit.errors.OrekitException;
  29. import org.orekit.errors.OrekitMessages;
  30. import org.orekit.frames.Frame;
  31. import org.orekit.frames.Frames;
  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.time.FieldAbsoluteDate;
  37. import org.orekit.time.TimeScale;
  38. import org.orekit.utils.FieldPVCoordinates;
  39. import org.orekit.utils.PVCoordinates;
  40. import org.orekit.utils.ParameterDriver;


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

  69.     // CHECKSTYLE: stop VisibilityModifier check

  70.     /** Initial state. */
  71.     protected FieldTLE<T> tle;

  72.     /** UTC time scale. */
  73.     protected final TimeScale utc;

  74.     /** final RAAN. */
  75.     protected T xnode;

  76.     /** final semi major axis. */
  77.     protected T a;

  78.     /** final eccentricity. */
  79.     protected T e;

  80.     /** final inclination. */
  81.     protected T i;

  82.     /** final perigee argument. */
  83.     protected T omega;

  84.     /** L from SPTRCK #3. */
  85.     protected T xl;

  86.     /** original recovered semi major axis. */
  87.     protected T a0dp;

  88.     /** original recovered mean motion. */
  89.     protected T xn0dp;

  90.     /** cosinus original inclination. */
  91.     protected T cosi0;

  92.     /** cos io squared. */
  93.     protected T theta2;

  94.     /** sinus original inclination. */
  95.     protected T sini0;

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

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

  100.     /** common parameter for raan (OMEGA) computation. */
  101.     protected T xnodot;

  102.     /** original eccentricity squared. */
  103.     protected T e0sq;
  104.     /** 1 - e2. */
  105.     protected T beta02;

  106.     /** sqrt (1 - e2). */
  107.     protected T beta0;

  108.     /** perigee, expressed in KM and ALTITUDE. */
  109.     protected T perige;

  110.     /** eta squared. */
  111.     protected T etasq;

  112.     /** original eccentricity * eta. */
  113.     protected T eeta;

  114.     /** s* new value for the contant s. */
  115.     protected T s4;

  116.     /** tsi from SPTRCK #3. */
  117.     protected T tsi;

  118.     /** eta from SPTRCK #3. */
  119.     protected T eta;

  120.     /** coef for SGP C3 computation. */
  121.     protected T coef;

  122.     /** coef for SGP C5 computation. */
  123.     protected T coef1;

  124.     /** C1 from SPTRCK #3. */
  125.     protected T c1;

  126.     /** C2 from SPTRCK #3. */
  127.     protected T c2;

  128.     /** C4 from SPTRCK #3. */
  129.     protected T c4;

  130.     /** common parameter for raan (OMEGA) computation. */
  131.     protected T xnodcf;

  132.     /** 3/2 * C1. */
  133.     protected T t2cof;

  134.     // CHECKSTYLE: resume VisibilityModifier check

  135.     /** TLE frame. */
  136.     private final Frame teme;

  137.     /** Spacecraft mass (kg). */
  138.     private final T mass;

  139.     /** Protected constructor for derived classes.
  140.      *
  141.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  142.      *
  143.      * @param initialTLE the unique TLE to propagate
  144.      * @param attitudeProvider provider for attitude computation
  145.      * @param mass spacecraft mass (kg)
  146.      * @param parameters SGP4 and SDP4 model parameters
  147.      * @see #FieldTLEPropagator(FieldTLE, AttitudeProvider, CalculusFieldElement, Frame, CalculusFieldElement[])
  148.      */
  149.     @DefaultDataContext
  150.     protected FieldTLEPropagator(final FieldTLE<T> initialTLE,
  151.                             final AttitudeProvider attitudeProvider,
  152.                             final T mass,
  153.                             final T[] parameters) {
  154.         this(initialTLE, attitudeProvider, mass,
  155.                 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,
  165.                             final AttitudeProvider attitudeProvider,
  166.                             final T mass,
  167.                             final Frame teme,
  168.                             final T[] parameters) {
  169.         super(initialTLE.getE().getField(), attitudeProvider);
  170.         setStartDate(initialTLE.getDate());
  171.         this.tle  = initialTLE;
  172.         this.teme = teme;
  173.         this.mass = mass;
  174.         this.utc = initialTLE.getUtc();

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

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

  196.     /** Selects the extrapolator to use with the selected TLE.
  197.      *
  198.      *<p>This method uses the {@link DataContext#getDefault() default data context}.
  199.      *
  200.      * @param tle the TLE to propagate.
  201.      * @param frames set of Frames to use in the propagator.
  202.      * @param parameters SGP4 and SDP4 model parameters
  203.      * @return the correct propagator.
  204.      * @param <T> elements type
  205.      */
  206.     public static <T extends CalculusFieldElement<T>> FieldTLEPropagator<T> selectExtrapolator(final FieldTLE<T> tle, final Frames frames, final T[] parameters) {
  207.         return selectExtrapolator(
  208.                 tle,
  209.                 InertialProvider.of(frames.getTEME()),
  210.                 tle.getE().getField().getZero().add(DEFAULT_MASS),
  211.                 frames.getTEME(),
  212.                 parameters);
  213.     }

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

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

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

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

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

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

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

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

  280.         // Compute PV with previous calculated parameters
  281.         return computePVCoordinates();
  282.     }

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

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

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

  304.         // Values of s and qms2t :
  305.         s4 = zero.add(TLEConstants.S);  // unmodified value for s
  306.         T q0ms24 = zero.add(TLEConstants.QOMS2T); // unmodified value for q0ms2T

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

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

  321.         final T pinv = a0dp.multiply(beta02).reciprocal();
  322.         final T pinvsq = pinv.multiply(pinv);
  323.         tsi = a0dp.subtract(s4).reciprocal();
  324.         eta = a0dp.multiply(tle.getE()).multiply(tsi);
  325.         etasq = eta.multiply(eta);
  326.         eeta = tle.getE().multiply(eta);

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

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

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

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

  345.         final T theta4 = theta2.multiply(theta2);
  346.         final T temp1  = pinvsq.multiply(xn0dp).multiply(3 * TLEConstants.CK2);
  347.         final T temp2  = temp1.multiply(pinvsq).multiply(TLEConstants.CK2);
  348.         final T temp3  = pinvsq.multiply(pinvsq).multiply(xn0dp).multiply(1.25 * TLEConstants.CK4);

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

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

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

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

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

  364.     }

  365.     /** Retrieves the position and velocity.
  366.      * @return the computed PVCoordinates.
  367.      */
  368.     private FieldPVCoordinates<T> computePVCoordinates() {

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

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

  392.         if (e.getReal() > (1 - 1e-6)) {
  393.             throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL, e);
  394.         }

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

  398.             boolean doSecondOrderNewtonRaphson = true;

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

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

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

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

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

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

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

  473.     }

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

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

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

  488.     /** {@inheritDoc}
  489.      * <p>
  490.      * For TLE propagator, calling this method is only recommended
  491.      * for covariance propagation when the new <code>state</code>
  492.      * differs from the previous one by only adding the additional
  493.      * state containing the derivatives.
  494.      * </p>
  495.      */
  496.     public void resetInitialState(final FieldSpacecraftState<T> state) {
  497.         super.resetInitialState(state);
  498.         super.setStartDate(state.getDate());
  499.         final FieldTLE<T> newTLE = FieldTLE.stateToTLE(state, tle, utc, teme);
  500.         this.tle = newTLE;
  501.         initializeCommons(tle.getParameters(state.getDate().getField()));
  502.         sxpInitialize(tle.getParameters(state.getDate().getField()));
  503.     }

  504.     /** {@inheritDoc} */
  505.     protected void resetIntermediateState(final FieldSpacecraftState<T> state, final boolean forward) {
  506.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  507.     }

  508.     /** {@inheritDoc} */
  509.     protected T getMass(final FieldAbsoluteDate<T> date) {
  510.         return mass;
  511.     }

  512.     /** {@inheritDoc} */
  513.     public FieldOrbit<T> propagateOrbit(final FieldAbsoluteDate<T> date, final T[] parameters) {
  514.         return new FieldCartesianOrbit<>(getPVCoordinates(date, parameters), teme, date, date.getField().getZero().add(TLEConstants.MU));
  515.     }

  516.     /** Get the underlying TLE.
  517.      * @return underlying TLE
  518.      */
  519.     public FieldTLE<T> getTLE() {
  520.         return tle;
  521.     }

  522.     /** {@inheritDoc} */
  523.     public Frame getFrame() {
  524.         return teme;
  525.     }

  526. }