DeepSDP4.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 org.hipparchus.util.FastMath;
  19. import org.hipparchus.util.MathUtils;
  20. import org.hipparchus.util.SinCos;
  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. import org.orekit.time.DateTimeComponents;
  26. import org.orekit.utils.Constants;


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

  40.     // CHECKSTYLE: stop JavadocVariable check

  41.     /** Integration step (seconds). */
  42.     private static final double SECULAR_INTEGRATION_STEP  = 720.0;

  43.     /** Intermediate values. */
  44.     private double thgr;
  45.     private double xnq;
  46.     private double omegaq;
  47.     private double zcosil;
  48.     private double zsinil;
  49.     private double zsinhl;
  50.     private double zcoshl;
  51.     private double zmol;
  52.     private double zcosgl;
  53.     private double zsingl;
  54.     private double zmos;
  55.     private double savtsn;

  56.     private double ee2;
  57.     private double e3;
  58.     private double xi2;
  59.     private double xi3;
  60.     private double xl2;
  61.     private double xl3;
  62.     private double xl4;
  63.     private double xgh2;
  64.     private double xgh3;
  65.     private double xgh4;
  66.     private double xh2;
  67.     private double xh3;

  68.     private double d2201;
  69.     private double d2211;
  70.     private double d3210;
  71.     private double d3222;
  72.     private double d4410;
  73.     private double d4422;
  74.     private double d5220;
  75.     private double d5232;
  76.     private double d5421;
  77.     private double d5433;
  78.     private double xlamo;

  79.     private double sse;
  80.     private double ssi;
  81.     private double ssl;
  82.     private double ssh;
  83.     private double ssg;
  84.     private double se2;
  85.     private double si2;
  86.     private double sl2;
  87.     private double sgh2;
  88.     private double sh2;
  89.     private double se3;
  90.     private double si3;
  91.     private double sl3;
  92.     private double sgh3;
  93.     private double sh3;
  94.     private double sl4;
  95.     private double sgh4;

  96.     private double del1;
  97.     private double del2;
  98.     private double del3;
  99.     private double xfact;
  100.     private double xli;
  101.     private double xni;
  102.     private double atime;

  103.     private double pe;
  104.     private double pinc;
  105.     private double pl;
  106.     private double pgh;
  107.     private double ph;

  108.     private double[] derivs;

  109.     // CHECKSTYLE: resume JavadocVariable check

  110.     /** Flag for resonant orbits. */
  111.     private boolean resonant;

  112.     /** Flag for synchronous orbits. */
  113.     private boolean synchronous;

  114.     /** Flag for compliance with Dundee modifications. */
  115.     private boolean isDundeeCompliant = true;

  116.     /** Constructor for a unique initial TLE.
  117.      *
  118.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  119.      *
  120.      * @param initialTLE the TLE to propagate.
  121.      * @param attitudeProvider provider for attitude computation
  122.      * @param mass spacecraft mass (kg)
  123.      * @see #DeepSDP4(TLE, AttitudeProvider, double, Frame)
  124.      */
  125.     @DefaultDataContext
  126.     public DeepSDP4(final TLE initialTLE, final AttitudeProvider attitudeProvider,
  127.                     final double mass) {
  128.         this(initialTLE, attitudeProvider, mass,
  129.                 DataContext.getDefault().getFrames().getTEME());
  130.     }

  131.     /** Constructor for a unique initial TLE.
  132.      * @param initialTLE the TLE to propagate.
  133.      * @param attitudeProvider provider for attitude computation
  134.      * @param mass spacecraft mass (kg)
  135.      * @param teme the TEME frame to use for propagation.
  136.      * @since 10.1
  137.      */
  138.     public DeepSDP4(final TLE initialTLE,
  139.                     final AttitudeProvider attitudeProvider,
  140.                     final double mass,
  141.                     final Frame teme) {
  142.         super(initialTLE, attitudeProvider, mass, teme);
  143.     }

  144.     /** Computes luni - solar terms from initial coordinates and epoch.
  145.      */
  146.     protected void luniSolarTermsComputation() {

  147.         final SinCos scg  = FastMath.sinCos(tle.getPerigeeArgument());
  148.         final double sing = scg.sin();
  149.         final double cosg = scg.cos();

  150.         final SinCos scq  = FastMath.sinCos(tle.getRaan());
  151.         final double sinq = scq.sin();
  152.         final double cosq = scq.cos();
  153.         final double aqnv = 1.0 / a0dp;

  154.         // Compute julian days since 1900
  155.         final double daysSince1900 = (tle.getDate()
  156.                 .getComponents(utc)
  157.                 .offsetFrom(DateTimeComponents.JULIAN_EPOCH)) /
  158.                 Constants.JULIAN_DAY - 2415020;

  159.         double cc = TLEConstants.C1SS;
  160.         double ze = TLEConstants.ZES;
  161.         double zn = TLEConstants.ZNS;
  162.         double zsinh = sinq;
  163.         double zcosh = cosq;

  164.         thgr = thetaG(tle.getDate());
  165.         xnq = xn0dp;
  166.         omegaq = tle.getPerigeeArgument();

  167.         final double xnodce = 4.5236020 - 9.2422029e-4 * daysSince1900;
  168.         final SinCos scTem  = FastMath.sinCos(xnodce);
  169.         final double stem   = scTem.sin();
  170.         final double ctem   = scTem.cos();
  171.         final double c_minus_gam = 0.228027132 * daysSince1900 - 1.1151842;
  172.         final double gam = 5.8351514 + 0.0019443680 * daysSince1900;

  173.         zcosil = 0.91375164 - 0.03568096 * ctem;
  174.         zsinil = FastMath.sqrt(1.0 - zcosil * zcosil);
  175.         zsinhl = 0.089683511 * stem / zsinil;
  176.         zcoshl = FastMath.sqrt(1.0 - zsinhl * zsinhl);
  177.         zmol = MathUtils.normalizeAngle(c_minus_gam, FastMath.PI);

  178.         double zx = 0.39785416 * stem / zsinil;
  179.         final double zy = zcoshl * ctem + 0.91744867 * zsinhl * stem;
  180.         zx = FastMath.atan2( zx, zy) + gam - xnodce;
  181.         final SinCos scZx = FastMath.sinCos(zx);
  182.         zcosgl = scZx.cos();
  183.         zsingl = scZx.sin();
  184.         zmos = MathUtils.normalizeAngle(6.2565837 + 0.017201977 * daysSince1900, FastMath.PI);

  185.         // Do solar terms
  186.         savtsn = 1e20;

  187.         double zcosi =  0.91744867;
  188.         double zsini =  0.39785416;
  189.         double zsing = -0.98088458;
  190.         double zcosg =  0.1945905;

  191.         double se = 0;
  192.         double sgh = 0;
  193.         double sh = 0;
  194.         double si = 0;
  195.         double sl = 0;

  196.         // There was previously some convoluted logic here, but it boils
  197.         // down to this:  we compute the solar terms,  then the lunar terms.
  198.         // On a second pass,  we recompute the solar terms, taking advantage
  199.         // of the improved data that resulted from computing lunar terms.
  200.         for (int iteration = 0; iteration < 2; ++iteration) {
  201.             final double a1 = zcosg * zcosh + zsing * zcosi * zsinh;
  202.             final double a3 = -zsing * zcosh + zcosg * zcosi * zsinh;
  203.             final double a7 = -zcosg * zsinh + zsing * zcosi * zcosh;
  204.             final double a8 = zsing * zsini;
  205.             final double a9 = zsing * zsinh + zcosg * zcosi * zcosh;
  206.             final double a10 = zcosg * zsini;
  207.             final double a2 = cosi0 * a7 + sini0 * a8;
  208.             final double a4 = cosi0 * a9 + sini0 * a10;
  209.             final double a5 = -sini0 * a7 + cosi0 * a8;
  210.             final double a6 = -sini0 * a9 + cosi0 * a10;
  211.             final double x1 = a1 * cosg + a2 * sing;
  212.             final double x2 = a3 * cosg + a4 * sing;
  213.             final double x3 = -a1 * sing + a2 * cosg;
  214.             final double x4 = -a3 * sing + a4 * cosg;
  215.             final double x5 = a5 * sing;
  216.             final double x6 = a6 * sing;
  217.             final double x7 = a5 * cosg;
  218.             final double x8 = a6 * cosg;
  219.             final double z31 = 12 * x1 * x1 - 3 * x3 * x3;
  220.             final double z32 = 24 * x1 * x2 - 6 * x3 * x4;
  221.             final double z33 = 12 * x2 * x2 - 3 * x4 * x4;
  222.             final double z11 = -6 * a1 * a5 + e0sq * (-24 * x1 * x7 - 6 * x3 * x5);
  223.             final double z12 = -6 * (a1 * a6 + a3 * a5) +
  224.                                e0sq * (-24 * (x2 * x7 + x1 * x8) - 6 * (x3 * x6 + x4 * x5));
  225.             final double z13 = -6 * a3 * a6 + e0sq * (-24 * x2 * x8 - 6 * x4 * x6);
  226.             final double z21 = 6 * a2 * a5 + e0sq * (24 * x1 * x5 - 6 * x3 * x7);
  227.             final double z22 = 6 * (a4 * a5 + a2 * a6) +
  228.                                e0sq * (24 * (x2 * x5 + x1 * x6) - 6 * (x4 * x7 + x3 * x8));
  229.             final double z23 = 6 * a4 * a6 + e0sq * (24 * x2 * x6 - 6 * x4 * x8);
  230.             final double s3 = cc / xnq;
  231.             final double s2 = -0.5 * s3 / beta0;
  232.             final double s4 = s3 * beta0;
  233.             final double s1 = -15 * tle.getE() * s4;
  234.             final double s5 = x1 * x3 + x2 * x4;
  235.             final double s6 = x2 * x3 + x1 * x4;
  236.             final double s7 = x2 * x4 - x1 * x3;
  237.             double z1 = 3 * (a1 * a1 + a2 * a2) + z31 * e0sq;
  238.             double z2 = 6 * (a1 * a3 + a2 * a4) + z32 * e0sq;
  239.             double z3 = 3 * (a3 * a3 + a4 * a4) + z33 * e0sq;

  240.             z1 = z1 + z1 + beta02 * z31;
  241.             z2 = z2 + z2 + beta02 * z32;
  242.             z3 = z3 + z3 + beta02 * z33;
  243.             se = s1 * zn * s5;
  244.             si = s2 * zn * (z11 + z13);
  245.             sl = -zn * s3 * (z1 + z3 - 14 - 6 * e0sq);
  246.             sgh = s4 * zn * (z31 + z33 - 6);
  247.             if (tle.getI() < (FastMath.PI / 60.0)) {
  248.                 // inclination smaller than 3 degrees
  249.                 sh = 0;
  250.             } else {
  251.                 sh = -zn * s2 * (z21 + z23);
  252.             }
  253.             ee2  =  2 * s1 * s6;
  254.             e3   =  2 * s1 * s7;
  255.             xi2  =  2 * s2 * z12;
  256.             xi3  =  2 * s2 * (z13 - z11);
  257.             xl2  = -2 * s3 * z2;
  258.             xl3  = -2 * s3 * (z3 - z1);
  259.             xl4  = -2 * s3 * (-21 - 9 * e0sq) * ze;
  260.             xgh2 =  2 * s4 * z32;
  261.             xgh3 =  2 * s4 * (z33 - z31);
  262.             xgh4 = -18 * s4 * ze;
  263.             xh2  = -2 * s2 * z22;
  264.             xh3  = -2 * s2 * (z23 - z21);

  265.             if (iteration == 0) { // we compute lunar terms only on the first pass:
  266.                 sse = se;
  267.                 ssi = si;
  268.                 ssl = sl;
  269.                 ssh = (tle.getI() < (FastMath.PI / 60.0)) ? 0 : sh / sini0;
  270.                 ssg = sgh - cosi0 * ssh;
  271.                 se2 = ee2;
  272.                 si2 = xi2;
  273.                 sl2 = xl2;
  274.                 sgh2 = xgh2;
  275.                 sh2 = xh2;
  276.                 se3 = e3;
  277.                 si3 = xi3;
  278.                 sl3 = xl3;
  279.                 sgh3 = xgh3;
  280.                 sh3 = xh3;
  281.                 sl4 = xl4;
  282.                 sgh4 = xgh4;
  283.                 zcosg = zcosgl;
  284.                 zsing = zsingl;
  285.                 zcosi = zcosil;
  286.                 zsini = zsinil;
  287.                 zcosh = zcoshl * cosq + zsinhl * sinq;
  288.                 zsinh = sinq * zcoshl - cosq * zsinhl;
  289.                 zn = TLEConstants.ZNL;
  290.                 cc = TLEConstants.C1L;
  291.                 ze = TLEConstants.ZEL;
  292.             }
  293.         } // end of solar - lunar - solar terms computation

  294.         sse += se;
  295.         ssi += si;
  296.         ssl += sl;
  297.         ssg += sgh - ((tle.getI() < (FastMath.PI / 60.0)) ? 0 : (cosi0 / sini0 * sh));
  298.         ssh += (tle.getI() < (FastMath.PI / 60.0)) ? 0 : sh / sini0;



  299.         //        Start the resonant-synchronous tests and initialization

  300.         double bfact = 0;

  301.         // if mean motion is 1.893053 to 2.117652 revs/day, and eccentricity >= 0.5,
  302.         // start of the 12-hour orbit, e > 0.5 section
  303.         if (xnq >= 0.00826 && xnq <= 0.00924 && tle.getE() >= 0.5) {

  304.             final double g201 = -0.306 - (tle.getE() - 0.64) * 0.440;
  305.             final double eoc = tle.getE() * e0sq;
  306.             final double sini2 = sini0 * sini0;
  307.             final double f220 = 0.75 * (1 + 2 * cosi0 + theta2);
  308.             final double f221 = 1.5 * sini2;
  309.             final double f321 =  1.875 * sini0 * (1 - 2 * cosi0 - 3 * theta2);
  310.             final double f322 = -1.875 * sini0 * (1 + 2 * cosi0 - 3 * theta2);
  311.             final double f441 = 35 * sini2 * f220;
  312.             final double f442 = 39.3750 * sini2 * sini2;
  313.             final double f522 = 9.84375 * sini0 * (sini2 * (1 - 2 * cosi0 - 5 * theta2) +
  314.                                                    0.33333333 * (-2 + 4 * cosi0 + 6 * theta2));
  315.             final double f523 = sini0 * (4.92187512 * sini2 * (-2 - 4 * cosi0 + 10 * theta2) +
  316.                                          6.56250012 * (1 + 2 * cosi0 - 3 * theta2));
  317.             final double f542 = 29.53125 * sini0 * (2 - 8 * cosi0 + theta2 * (-12 + 8 * cosi0 + 10 * theta2));
  318.             final double f543 = 29.53125 * sini0 * (-2 - 8 * cosi0 + theta2 * (12 + 8 * cosi0 - 10 * theta2));
  319.             final double g211;
  320.             final double g310;
  321.             final double g322;
  322.             final double g410;
  323.             final double g422;
  324.             final double g520;

  325.             resonant = true;       // it is resonant...
  326.             synchronous = false;     // but it's not synchronous

  327.             // Geopotential resonance initialization for 12 hour orbits :
  328.             if (tle.getE() <= 0.65) {
  329.                 g211 =    3.616  -   13.247  * tle.getE() +   16.290  * e0sq;
  330.                 g310 =  -19.302  +  117.390  * tle.getE() -  228.419  * e0sq +  156.591  * eoc;
  331.                 g322 =  -18.9068 +  109.7927 * tle.getE() -  214.6334 * e0sq +  146.5816 * eoc;
  332.                 g410 =  -41.122  +  242.694  * tle.getE() -  471.094  * e0sq +  313.953  * eoc;
  333.                 g422 = -146.407  +  841.880  * tle.getE() - 1629.014  * e0sq + 1083.435  * eoc;
  334.                 g520 = -532.114  + 3017.977  * tle.getE() - 5740.032  * e0sq + 3708.276  * eoc;
  335.             } else  {
  336.                 g211 =   -72.099 +   331.819 * tle.getE() -   508.738 * e0sq +   266.724 * eoc;
  337.                 g310 =  -346.844 +  1582.851 * tle.getE() -  2415.925 * e0sq +  1246.113 * eoc;
  338.                 g322 =  -342.585 +  1554.908 * tle.getE() -  2366.899 * e0sq +  1215.972 * eoc;
  339.                 g410 = -1052.797 +  4758.686 * tle.getE() -  7193.992 * e0sq +  3651.957 * eoc;
  340.                 g422 = -3581.69  + 16178.11  * tle.getE() - 24462.77  * e0sq + 12422.52  * eoc;
  341.                 if (tle.getE() <= 0.715) {
  342.                     g520 = 1464.74 - 4664.75 * tle.getE() + 3763.64 * e0sq;
  343.                 } else {
  344.                     g520 = -5149.66 + 29936.92 * tle.getE() - 54087.36 * e0sq + 31324.56 * eoc;
  345.                 }
  346.             }

  347.             final double g533;
  348.             final double g521;
  349.             final double g532;
  350.             if (tle.getE() < 0.7) {
  351.                 g533 = -919.2277  + 4988.61   * tle.getE() - 9064.77   * e0sq + 5542.21  * eoc;
  352.                 g521 = -822.71072 + 4568.6173 * tle.getE() - 8491.4146 * e0sq + 5337.524 * eoc;
  353.                 g532 = -853.666   + 4690.25   * tle.getE() - 8624.77   * e0sq + 5341.4   * eoc;
  354.             } else {
  355.                 g533 = -37995.78  + 161616.52 * tle.getE() - 229838.2  * e0sq + 109377.94 * eoc;
  356.                 g521 = -51752.104 + 218913.95 * tle.getE() - 309468.16 * e0sq + 146349.42 * eoc;
  357.                 g532 = -40023.88  + 170470.89 * tle.getE() - 242699.48 * e0sq + 115605.82 * eoc;
  358.             }

  359.             double temp1 = 3 * xnq * xnq * aqnv * aqnv;
  360.             double temp = temp1 * TLEConstants.ROOT22;
  361.             d2201 = temp * f220 * g201;
  362.             d2211 = temp * f221 * g211;
  363.             temp1 *= aqnv;
  364.             temp = temp1 * TLEConstants.ROOT32;
  365.             d3210 = temp * f321 * g310;
  366.             d3222 = temp * f322 * g322;
  367.             temp1 *= aqnv;
  368.             temp = 2 * temp1 * TLEConstants.ROOT44;
  369.             d4410 = temp * f441 * g410;
  370.             d4422 = temp * f442 * g422;
  371.             temp1 *= aqnv;
  372.             temp = temp1 * TLEConstants.ROOT52;
  373.             d5220 = temp * f522 * g520;
  374.             d5232 = temp * f523 * g532;
  375.             temp = 2 * temp1 * TLEConstants.ROOT54;
  376.             d5421 = temp * f542 * g521;
  377.             d5433 = temp * f543 * g533;
  378.             xlamo = tle.getMeanAnomaly() + tle.getRaan() + tle.getRaan() - thgr - thgr;
  379.             bfact = xmdot + xnodot + xnodot - TLEConstants.THDT - TLEConstants.THDT;
  380.             bfact += ssl + ssh + ssh;
  381.         } else if (xnq < 0.0052359877 && xnq > 0.0034906585) {
  382.             // if mean motion is .8 to 1.2 revs/day : (geosynch)

  383.             final double cosio_plus_1 = 1.0 + cosi0;
  384.             final double g200 = 1 + e0sq * (-2.5 + 0.8125  * e0sq);
  385.             final double g300 = 1 + e0sq * (-6   + 6.60937 * e0sq);
  386.             final double f311 = 0.9375 * sini0 * sini0 * (1 + 3 * cosi0) - 0.75 * cosio_plus_1;
  387.             final double g310 = 1 + 2 * e0sq;
  388.             final double f220 = 0.75 * cosio_plus_1 * cosio_plus_1;
  389.             final double f330 = 2.5 * f220 * cosio_plus_1;

  390.             resonant = true;
  391.             synchronous = true;

  392.             // Synchronous resonance terms initialization
  393.             del1 = 3 * xnq * xnq * aqnv * aqnv;
  394.             del2 = 2 * del1 * f220 * g200 * TLEConstants.Q22;
  395.             del3 = 3 * del1 * f330 * g300 * TLEConstants.Q33 * aqnv;
  396.             del1 = del1 * f311 * g310 * TLEConstants.Q31 * aqnv;
  397.             xlamo = tle.getMeanAnomaly() + tle.getRaan() + tle.getPerigeeArgument() - thgr;
  398.             bfact = xmdot + omgdot + xnodot - TLEConstants.THDT;
  399.             bfact = bfact + ssl + ssg + ssh;
  400.         } else {
  401.             // it's neither a high-e 12-hours orbit nor a geosynchronous:
  402.             resonant = false;
  403.             synchronous = false;
  404.         }

  405.         if (resonant) {
  406.             xfact = bfact - xnq;

  407.             // Initialize integrator
  408.             xli   = xlamo;
  409.             xni   = xnq;
  410.             atime = 0;
  411.         }
  412.         derivs = new double[2];
  413.     }

  414.     /** Computes secular terms from current coordinates and epoch.
  415.      * @param t offset from initial epoch (minutes)
  416.      */
  417.     protected void deepSecularEffects(final double t)  {

  418.         xll    += ssl * t;
  419.         omgadf += ssg * t;
  420.         xnode  += ssh * t;
  421.         em      = tle.getE() + sse * t;
  422.         xinc    = tle.getI() + ssi * t;

  423.         if (resonant) {
  424.             // If we're closer to t = 0 than to the currently-stored data
  425.             // from the previous call to this function,  then we're
  426.             // better off "restarting",  going back to the initial data.
  427.             // The Dundee code rigs things up to _always_ take 720-minute
  428.             // steps from epoch to end time,  except for the final step.
  429.             // Easiest way to arrange similar behavior in this code is
  430.             // just to always do a restart,  if we're in Dundee-compliant
  431.             // mode.
  432.             if (FastMath.abs(t) < FastMath.abs(t - atime) || isDundeeCompliant)  {
  433.                 // Epoch restart
  434.                 atime = 0;
  435.                 xni = xnq;
  436.                 xli = xlamo;
  437.             }
  438.             boolean lastIntegrationStep = false;
  439.             // if |step|>|step max| then do one step at step max
  440.             while (!lastIntegrationStep) {
  441.                 double delt = t - atime;
  442.                 if (delt > SECULAR_INTEGRATION_STEP) {
  443.                     delt = SECULAR_INTEGRATION_STEP;
  444.                 } else if (delt < -SECULAR_INTEGRATION_STEP) {
  445.                     delt = -SECULAR_INTEGRATION_STEP;
  446.                 } else {
  447.                     lastIntegrationStep = true;
  448.                 }

  449.                 computeSecularDerivs();

  450.                 final double xldot = xni + xfact;

  451.                 double xlpow = 1.;
  452.                 xli += delt * xldot;
  453.                 xni += delt * derivs[0];
  454.                 double delt_factor = delt;
  455.                 xlpow *= xldot;
  456.                 derivs[1] *= xlpow;
  457.                 delt_factor *= delt / 2;
  458.                 xli += delt_factor * derivs[0];
  459.                 xni += delt_factor * derivs[1];
  460.                 atime += delt;
  461.             }
  462.             xn = xni;
  463.             final double temp = -xnode + thgr + t * TLEConstants.THDT;
  464.             xll = xli + temp + (synchronous ? -omgadf : temp);
  465.         }
  466.     }

  467.     /** Computes periodic terms from current coordinates and epoch.
  468.      * @param t offset from initial epoch (min)
  469.      */
  470.     protected void deepPeriodicEffects(final double t)  {

  471.         // If the time didn't change by more than 30 minutes,
  472.         // there's no good reason to recompute the perturbations;
  473.         // they don't change enough over so short a time span.
  474.         // However,  the Dundee code _always_ recomputes,  so if
  475.         // we're attempting to replicate its results,  we've gotta
  476.         // recompute everything,  too.
  477.         if (FastMath.abs(savtsn - t) >= 30.0 || isDundeeCompliant)  {

  478.             savtsn = t;

  479.             // Update solar perturbations for time T
  480.             double zm = zmos + TLEConstants.ZNS * t;
  481.             double zf = zm + 2 * TLEConstants.ZES * FastMath.sin(zm);
  482.             SinCos sczf = FastMath.sinCos(zf);
  483.             double sinzf = sczf.sin();
  484.             double f2 = 0.5 * sinzf * sinzf - 0.25;
  485.             double f3 = -0.5 * sinzf * sczf.cos();
  486.             final double ses = se2 * f2 + se3 * f3;
  487.             final double sis = si2 * f2 + si3 * f3;
  488.             final double sls = sl2 * f2 + sl3 * f3 + sl4 * sinzf;
  489.             final double sghs = sgh2 * f2 + sgh3 * f3 + sgh4 * sinzf;
  490.             final double shs = sh2 * f2 + sh3 * f3;

  491.             // Update lunar perturbations for time T
  492.             zm = zmol + TLEConstants.ZNL * t;
  493.             zf = zm + 2 * TLEConstants.ZEL * FastMath.sin(zm);
  494.             sczf = FastMath.sinCos(zf);
  495.             sinzf = sczf.sin();
  496.             f2 =  0.5 * sinzf * sinzf - 0.25;
  497.             f3 = -0.5 * sinzf * sczf.cos();
  498.             final double sel = ee2 * f2 + e3 * f3;
  499.             final double sil = xi2 * f2 + xi3 * f3;
  500.             final double sll = xl2 * f2 + xl3 * f3 + xl4 * sinzf;
  501.             final double sghl = xgh2 * f2 + xgh3 * f3 + xgh4 * sinzf;
  502.             final double sh1 = xh2 * f2 + xh3 * f3;

  503.             // Sum the solar and lunar contributions
  504.             pe   = ses  + sel;
  505.             pinc = sis  + sil;
  506.             pl   = sls  + sll;
  507.             pgh  = sghs + sghl;
  508.             ph   = shs  + sh1;
  509.         }

  510.         xinc += pinc;

  511.         final SinCos scis = FastMath.sinCos(xinc);
  512.         final double sinis = scis.sin();
  513.         final double cosis = scis.cos();

  514.         /* Add solar/lunar perturbation correction to eccentricity: */
  515.         em     += pe;
  516.         xll    += pl;
  517.         omgadf += pgh;
  518.         xinc    = MathUtils.normalizeAngle(xinc, 0);

  519.         if (FastMath.abs(xinc) >= 0.2) {
  520.             // Apply periodics directly
  521.             final double temp_val = ph / sinis;
  522.             omgadf -= cosis * temp_val;
  523.             xnode += temp_val;
  524.         } else {
  525.             // Apply periodics with Lyddane modification
  526.             final SinCos scok  = FastMath.sinCos(xnode);
  527.             final double sinok = scok.sin();
  528.             final double cosok = scok.cos();
  529.             final double alfdp =  ph * cosok + (pinc * cosis + sinis) * sinok;
  530.             final double betdp = -ph * sinok + (pinc * cosis + sinis) * cosok;
  531.             final double delta_xnode = MathUtils.normalizeAngle(FastMath.atan2(alfdp, betdp) - xnode, 0);
  532.             final double dls = -xnode * sinis * pinc;
  533.             omgadf += dls - cosis * delta_xnode;
  534.             xnode  += delta_xnode;
  535.         }
  536.     }

  537.     /** Computes internal secular derivs. */
  538.     private void computeSecularDerivs() {

  539.         final SinCos sc_li  = FastMath.sinCos(xli);
  540.         final double sin_li = sc_li.sin();
  541.         final double cos_li = sc_li.cos();
  542.         final double sin_2li = 2. * sin_li * cos_li;
  543.         final double cos_2li = 2. * cos_li * cos_li - 1.;

  544.         // Dot terms calculated :
  545.         if (synchronous)  {
  546.             final double sin_3li = sin_2li * cos_li + cos_2li * sin_li;
  547.             final double cos_3li = cos_2li * cos_li - sin_2li * sin_li;
  548.             final double term1a = del1 * (sin_li  * TLEConstants.C_FASX2  - cos_li  * TLEConstants.S_FASX2);
  549.             final double term2a = del2 * (sin_2li * TLEConstants.C_2FASX4 - cos_2li * TLEConstants.S_2FASX4);
  550.             final double term3a = del3 * (sin_3li * TLEConstants.C_3FASX6 - cos_3li * TLEConstants.S_3FASX6);
  551.             final double term1b = del1 * (cos_li  * TLEConstants.C_FASX2  + sin_li  * TLEConstants.S_FASX2);
  552.             final double term2b = 2.0 * del2 * (cos_2li * TLEConstants.C_2FASX4 + sin_2li * TLEConstants.S_2FASX4);
  553.             final double term3b = 3.0 * del3 * (cos_3li * TLEConstants.C_3FASX6 + sin_3li * TLEConstants.S_3FASX6);
  554.             derivs[0] = term1a + term2a + term3a;
  555.             derivs[1] = term1b + term2b + term3b;
  556.         } else {
  557.             // orbit is a 12-hour resonant one
  558.             final double xomi = omegaq + omgdot * atime;
  559.             final SinCos sc_omi  = FastMath.sinCos(xomi);
  560.             final double sin_omi = sc_omi.sin();
  561.             final double cos_omi = sc_omi.cos();
  562.             final double sin_li_m_omi = sin_li * cos_omi - sin_omi * cos_li;
  563.             final double sin_li_p_omi = sin_li * cos_omi + sin_omi * cos_li;
  564.             final double cos_li_m_omi = cos_li * cos_omi + sin_omi * sin_li;
  565.             final double cos_li_p_omi = cos_li * cos_omi - sin_omi * sin_li;
  566.             final double sin_2omi = 2. * sin_omi * cos_omi;
  567.             final double cos_2omi = 2. * cos_omi * cos_omi - 1.;
  568.             final double sin_2li_m_omi = sin_2li * cos_omi - sin_omi * cos_2li;
  569.             final double sin_2li_p_omi = sin_2li * cos_omi + sin_omi * cos_2li;
  570.             final double cos_2li_m_omi = cos_2li * cos_omi + sin_omi * sin_2li;
  571.             final double cos_2li_p_omi = cos_2li * cos_omi - sin_omi * sin_2li;
  572.             final double sin_2li_p_2omi = sin_2li * cos_2omi + sin_2omi * cos_2li;
  573.             final double cos_2li_p_2omi = cos_2li * cos_2omi - sin_2omi * sin_2li;
  574.             final double sin_2omi_p_li = sin_li * cos_2omi + sin_2omi * cos_li;
  575.             final double cos_2omi_p_li = cos_li * cos_2omi - sin_2omi * sin_li;
  576.             final double term1a = d2201 * (sin_2omi_p_li  * TLEConstants.C_G22 - cos_2omi_p_li  * TLEConstants.S_G22) +
  577.                                   d2211 * (sin_li         * TLEConstants.C_G22 - cos_li         * TLEConstants.S_G22) +
  578.                                   d3210 * (sin_li_p_omi   * TLEConstants.C_G32 - cos_li_p_omi   * TLEConstants.S_G32) +
  579.                                   d3222 * (sin_li_m_omi   * TLEConstants.C_G32 - cos_li_m_omi   * TLEConstants.S_G32) +
  580.                                   d5220 * (sin_li_p_omi   * TLEConstants.C_G52 - cos_li_p_omi   * TLEConstants.S_G52) +
  581.                                   d5232 * (sin_li_m_omi   * TLEConstants.C_G52 - cos_li_m_omi   * TLEConstants.S_G52);
  582.             final double term2a = d4410 * (sin_2li_p_2omi * TLEConstants.C_G44 - cos_2li_p_2omi * TLEConstants.S_G44) +
  583.                                   d4422 * (sin_2li        * TLEConstants.C_G44 - cos_2li        * TLEConstants.S_G44) +
  584.                                   d5421 * (sin_2li_p_omi  * TLEConstants.C_G54 - cos_2li_p_omi  * TLEConstants.S_G54) +
  585.                                   d5433 * (sin_2li_m_omi  * TLEConstants.C_G54 - cos_2li_m_omi  * TLEConstants.S_G54);
  586.             final double term1b = d2201 * (cos_2omi_p_li  * TLEConstants.C_G22 + sin_2omi_p_li  * TLEConstants.S_G22) +
  587.                                   d2211 * (cos_li         * TLEConstants.C_G22 + sin_li         * TLEConstants.S_G22) +
  588.                                   d3210 * (cos_li_p_omi   * TLEConstants.C_G32 + sin_li_p_omi   * TLEConstants.S_G32) +
  589.                                   d3222 * (cos_li_m_omi   * TLEConstants.C_G32 + sin_li_m_omi   * TLEConstants.S_G32) +
  590.                                   d5220 * (cos_li_p_omi   * TLEConstants.C_G52 + sin_li_p_omi   * TLEConstants.S_G52) +
  591.                                   d5232 * (cos_li_m_omi   * TLEConstants.C_G52 + sin_li_m_omi   * TLEConstants.S_G52);
  592.             final double term2b = 2.0 * (d4410 * (cos_2li_p_2omi * TLEConstants.C_G44 + sin_2li_p_2omi * TLEConstants.S_G44) +
  593.                                          d4422 * (cos_2li        * TLEConstants.C_G44 + sin_2li        * TLEConstants.S_G44) +
  594.                                          d5421 * (cos_2li_p_omi  * TLEConstants.C_G54 + sin_2li_p_omi  * TLEConstants.S_G54) +
  595.                                          d5433 * (cos_2li_m_omi  * TLEConstants.C_G54 + sin_2li_m_omi  * TLEConstants.S_G54));

  596.             derivs[0] = term1a + term2a;
  597.             derivs[1] = term1b + term2b;

  598.         }
  599.     }

  600. }