FieldSGP4.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 org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.hipparchus.util.FieldSinCos;
  21. import org.orekit.annotation.DefaultDataContext;
  22. import org.orekit.attitudes.AttitudeProvider;
  23. import org.orekit.data.DataContext;
  24. import org.orekit.frames.Frame;

  25. /** This class contains methods to compute propagated coordinates with the SGP4 model.
  26.  * <p>
  27.  * The user should not bother in this class since it is handled internaly by the
  28.  * {@link TLEPropagator}.
  29.  * </p>
  30.  * <p>This implementation is largely inspired from the paper and source code <a
  31.  * href="https://www.celestrak.com/publications/AIAA/2006-6753/">Revisiting Spacetrack
  32.  * Report #3</a> and is fully compliant with its results and tests cases.</p>
  33.  * @author Felix R. Hoots, Ronald L. Roehrich, December 1980 (original fortran)
  34.  * @author David A. Vallado, Paul Crawford, Richard Hujsak, T.S. Kelso (C++ translation and improvements)
  35.  * @author Fabien Maussion (java translation)
  36.  * @author Thomas Paulet (field translation)
  37.  * @since 11.0
  38.  */
  39. public class FieldSGP4<T extends CalculusFieldElement<T>> extends FieldTLEPropagator<T> {

  40.     /** If perige is less than 220 km, some calculus are avoided. */
  41.     private boolean lessThan220;

  42.     /** (1 + eta * cos(M0))³. */
  43.     private T delM0;

  44.     // CHECKSTYLE: stop JavadocVariable check
  45.     private T d2;
  46.     private T d3;
  47.     private T d4;
  48.     private T t3cof;
  49.     private T t4cof;
  50.     private T t5cof;
  51.     private T sinM0;
  52.     private T omgcof;
  53.     private T xmcof;
  54.     private T c5;
  55.     // CHECKSTYLE: resume JavadocVariable check

  56.     /** Constructor for a unique initial TLE.
  57.      *
  58.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  59.      *
  60.      * @param initialTLE the TLE to propagate.
  61.      * @param attitudeProvider provider for attitude computation
  62.      * @param mass spacecraft mass (kg)
  63.      * @param parameters SGP4 and SDP4 model parameters
  64.      * @see #FieldSGP4(FieldTLE, AttitudeProvider, CalculusFieldElement, Frame, CalculusFieldElement[])
  65.      */
  66.     @DefaultDataContext
  67.     public FieldSGP4(final FieldTLE<T> initialTLE, final AttitudeProvider attitudeProvider,
  68.                 final T mass, final T[] parameters) {
  69.         this(initialTLE, attitudeProvider, mass,
  70.                 DataContext.getDefault().getFrames().getTEME(), parameters);
  71.     }

  72.     /** Constructor for a unique initial TLE.
  73.      * @param initialTLE the TLE to propagate.
  74.      * @param attitudeProvider provider for attitude computation
  75.      * @param mass spacecraft mass (kg)
  76.      * @param teme the TEME frame to use for propagation.
  77.      * @param parameters SGP4 and SDP4 model parameters
  78.      */
  79.     public FieldSGP4(final FieldTLE<T> initialTLE,
  80.                 final AttitudeProvider attitudeProvider,
  81.                 final T mass,
  82.                 final Frame teme,
  83.                 final T[] parameters) {
  84.         super(initialTLE, attitudeProvider, mass, teme, parameters);
  85.     }

  86.     /** Initialization proper to each propagator (SGP or SDP).
  87.      * @param parameters model parameters
  88.      */
  89.     protected void sxpInitialize(final T[] parameters) {

  90.         final T bStar = parameters[0];
  91.         // For perigee less than 220 kilometers, the equations are truncated to
  92.         // linear variation in sqrt a and quadratic variation in mean anomaly.
  93.         // Also, the c3 term, the delta omega term, and the delta m term are dropped.
  94.         lessThan220 = perige.getReal() < 220;
  95.         if (!lessThan220) {
  96.             final FieldSinCos<T> scM0 = FastMath.sinCos(tle.getMeanAnomaly());
  97.             final T c1sq = c1.multiply(c1);
  98.             delM0 = eta.multiply(scM0.cos()).add(1.0);
  99.             delM0 = delM0.multiply(delM0).multiply(delM0);
  100.             d2 = a0dp.multiply(tsi).multiply(c1sq).multiply(4.0);
  101.             final T temp = d2.multiply(tsi).multiply(c1).divide(3.0);
  102.             d3 = a0dp.multiply(17.0).add(s4).multiply(temp);
  103.             d4 = temp.multiply(0.5).multiply(a0dp).multiply(tsi).multiply(a0dp.multiply(221.0).add(s4.multiply(31.0))).multiply(c1);
  104.             t3cof = d2.add(c1sq.multiply(2));
  105.             t4cof = d3.multiply(3.0).add(c1.multiply(d2.multiply(12.0).add(c1sq.multiply(10)))).multiply(0.25);
  106.             t5cof = d4.multiply(3.0).add(c1.multiply(12.0).multiply(d3)).add(
  107.                     d2.multiply(d2).multiply(6.0)).add(c1sq.multiply(15.0).multiply(d2.multiply(2).add(c1sq))).multiply(0.2);
  108.             sinM0 = scM0.sin();
  109.             if (tle.getE().getReal() < 1e-4) {
  110.                 omgcof = c1sq.getField().getZero();
  111.                 xmcof = c1sq.getField().getZero();
  112.             } else  {
  113.                 final T c3 = coef.multiply(tsi).multiply(xn0dp).multiply(TLEConstants.A3OVK2 * TLEConstants.NORMALIZED_EQUATORIAL_RADIUS).multiply(sini0.divide(tle.getE()));
  114.                 xmcof = coef.multiply(bStar).divide(eeta).multiply(-TLEConstants.TWO_THIRD * TLEConstants.NORMALIZED_EQUATORIAL_RADIUS);
  115.                 omgcof = bStar.multiply(c3).multiply(FastMath.cos(tle.getPerigeeArgument()));
  116.             }
  117.         }

  118.         c5 = coef1.multiply(2).multiply(a0dp).multiply(beta02).multiply(etasq.add(eeta).multiply(2.75).add(eeta.multiply(etasq)).add(1));
  119.         // initialized
  120.     }

  121.     /** Propagation proper to each propagator (SGP or SDP).
  122.      * @param tSince the offset from initial epoch (min)
  123.      * @param parameters model parameters
  124.      */
  125.     protected void sxpPropagate(final T tSince, final T[] parameters) {

  126.         // Update for secular gravity and atmospheric drag.
  127.         final T bStar = parameters[0];
  128.         final T xmdf = tle.getMeanAnomaly().add(xmdot.multiply(tSince));
  129.         final T omgadf = tle.getPerigeeArgument().add(omgdot.multiply(tSince));
  130.         final T xn0ddf = tle.getRaan().add(xnodot.multiply(tSince));
  131.         omega = omgadf;
  132.         T xmp = xmdf;
  133.         final T tsq = tSince.multiply(tSince);
  134.         xnode = xn0ddf.add(xnodcf.multiply(tsq));
  135.         T tempa = c1.multiply(tSince).negate().add(1.0);
  136.         T tempe = bStar.multiply(c4).multiply(tSince);
  137.         T templ = t2cof.multiply(tsq);

  138.         if (!lessThan220) {
  139.             final T delomg = omgcof.multiply(tSince);
  140.             T delm = eta.multiply(FastMath.cos(xmdf)).add(1.0);
  141.             delm = xmcof.multiply(delm.multiply(delm).multiply(delm).subtract(delM0));
  142.             final T temp = delomg.add(delm);
  143.             xmp = xmdf.add(temp);
  144.             omega = omgadf.subtract(temp);
  145.             final T tcube = tsq.multiply(tSince);
  146.             final T tfour = tSince.multiply(tcube);
  147.             tempa = tempa.subtract(d2.multiply(tsq)).subtract(d3.multiply(tcube)).subtract(d4.multiply(tfour));
  148.             tempe = tempe.add(bStar.multiply(c5).multiply(FastMath.sin(xmp).subtract(sinM0)));
  149.             templ = templ.add(t3cof.multiply(tcube)).add(tfour.multiply(t4cof.add(tSince.multiply(t5cof))));
  150.         }

  151.         a = a0dp.multiply(tempa).multiply(tempa);
  152.         e = tle.getE().subtract(tempe);

  153.         // A highly arbitrary lower limit on e,  of 1e-6:
  154.         if (e.getReal() < 1e-6) {
  155.             e = e.getField().getZero().add(1e-6);
  156.         }

  157.         xl = xmp.add(omega).add(xnode).add(xn0dp.multiply(templ));

  158.         i = tle.getI();

  159.     }

  160. }