FieldSGP4.java

  1. /* Copyright 2002-2023 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.  * @param <T> type of the field elements
  39.  */
  40. public class FieldSGP4<T extends CalculusFieldElement<T>> extends FieldTLEPropagator<T> {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  159.         i = tle.getI();

  160.     }

  161. }