BrouwerLyddanePropagator.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;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
  22. import org.hipparchus.linear.RealMatrix;
  23. import org.hipparchus.util.CombinatoricsUtils;
  24. import org.hipparchus.util.FastMath;
  25. import org.hipparchus.util.MathUtils;
  26. import org.hipparchus.util.Precision;
  27. import org.hipparchus.util.SinCos;
  28. import org.orekit.attitudes.AttitudeProvider;
  29. import org.orekit.attitudes.InertialProvider;
  30. import org.orekit.errors.OrekitException;
  31. import org.orekit.errors.OrekitMessages;
  32. import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider;
  33. import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider.UnnormalizedSphericalHarmonics;
  34. import org.orekit.orbits.KeplerianOrbit;
  35. import org.orekit.orbits.Orbit;
  36. import org.orekit.orbits.OrbitType;
  37. import org.orekit.orbits.PositionAngle;
  38. import org.orekit.propagation.AbstractMatricesHarvester;
  39. import org.orekit.propagation.MatricesHarvester;
  40. import org.orekit.propagation.PropagationType;
  41. import org.orekit.propagation.SpacecraftState;
  42. import org.orekit.propagation.analytical.tle.TLE;
  43. import org.orekit.time.AbsoluteDate;
  44. import org.orekit.utils.DoubleArrayDictionary;
  45. import org.orekit.utils.ParameterDriver;
  46. import org.orekit.utils.TimeSpanMap;

  47. /**
  48.  * This class propagates a {@link org.orekit.propagation.SpacecraftState}
  49.  *  using the analytical Brouwer-Lyddane model (from J2 to J5 zonal harmonics).
  50.  * <p>
  51.  * At the opposite of the {@link EcksteinHechlerPropagator}, the Brouwer-Lyddane model is
  52.  * suited for elliptical orbits, there is no problem having a rather small eccentricity or inclination
  53.  * (Lyddane helped to solve this issue with the Brouwer model). Singularity for the critical
  54.  * inclination i = 63.4° is avoided using the method developed in Warren Phipps' 1992 thesis.
  55.  * <p>
  56.  * By default, Brouwer-Lyddane model considers only the perturbations due to zonal harmonics.
  57.  * However, for low Earth orbits, the magnitude of the perturbative acceleration due to
  58.  * atmospheric drag can be significant. Warren Phipps' 1992 thesis considered the atmospheric
  59.  * drag by time derivatives of the <i>mean</i> mean anomaly using the catch-all coefficient
  60.  * {@link #M2Driver}.
  61.  *
  62.  * Usually, M2 is adjusted during an orbit determination process and it represents the
  63.  * combination of all unmodeled secular along-track effects (i.e. not just the atmospheric drag).
  64.  * The behavior of M2 is close to the {@link TLE#getBStar()} parameter for the TLE.
  65.  *
  66.  * If the value of M2 is equal to {@link #M2 0.0}, the along-track  secular effects are not
  67.  * considered in the dynamical model. Typical values for M2 are not known. It depends on the
  68.  * orbit type. However, the value of M2 must be very small (e.g. between 1.0e-14 and 1.0e-15).
  69.  * The unit of M2 is rad/s².
  70.  *
  71.  * The along-track effects, represented by the secular rates of the mean semi-major axis
  72.  * and eccentricity, are computed following Eq. 2.38, 2.41, and 2.45 of Warren Phipps' thesis.
  73.  *
  74.  * @see "Brouwer, Dirk. Solution of the problem of artificial satellite theory without drag.
  75.  *       YALE UNIV NEW HAVEN CT NEW HAVEN United States, 1959."
  76.  *
  77.  * @see "Lyddane, R. H. Small eccentricities or inclinations in the Brouwer theory of the
  78.  *       artificial satellite. The Astronomical Journal 68 (1963): 555."
  79.  *
  80.  * @see "Phipps Jr, Warren E. Parallelization of the Navy Space Surveillance Center
  81.  *       (NAVSPASUR) Satellite Model. NAVAL POSTGRADUATE SCHOOL MONTEREY CA, 1992."
  82.  *
  83.  * @author Melina Vanel
  84.  * @author Bryan Cazabonne
  85.  * @since 11.1
  86.  */
  87. public class BrouwerLyddanePropagator extends AbstractAnalyticalPropagator {

  88.     /** Parameter name for M2 coefficient. */
  89.     public static final String M2_NAME = "M2";

  90.     /** Default value for M2 coefficient. */
  91.     public static final double M2 = 0.0;

  92.     /** Parameters scaling factor.
  93.      * <p>
  94.      * We use a power of 2 to avoid numeric noise introduction
  95.      * in the multiplications/divisions sequences.
  96.      * </p>
  97.      */
  98.     private static final double SCALE = FastMath.scalb(1.0, -32);

  99.     /** Beta constant used by T2 function. */
  100.     private static final double BETA = FastMath.scalb(100, -11);

  101.     /** Initial Brouwer-Lyddane model. */
  102.     private BLModel initialModel;

  103.     /** All models. */
  104.     private transient TimeSpanMap<BLModel> models;

  105.     /** Reference radius of the central body attraction model (m). */
  106.     private double referenceRadius;

  107.     /** Central attraction coefficient (m³/s²). */
  108.     private double mu;

  109.     /** Un-normalized zonal coefficients. */
  110.     private double[] ck0;

  111.     /** Empirical coefficient used in the drag modeling. */
  112.     private final ParameterDriver M2Driver;

  113.     /** Build a propagator from orbit and potential provider.
  114.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  115.      *
  116.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  117.      *
  118.      * @param initialOrbit initial orbit
  119.      * @param provider for un-normalized zonal coefficients
  120.      * @param M2 value of empirical drag coefficient in rad/s².
  121.      *        If equal to {@link #M2} drag is not computed
  122.      * @see #BrouwerLyddanePropagator(Orbit, AttitudeProvider, UnnormalizedSphericalHarmonicsProvider, double)
  123.      * @see #BrouwerLyddanePropagator(Orbit, UnnormalizedSphericalHarmonicsProvider, PropagationType, double)
  124.      */
  125.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  126.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  127.                                     final double M2) {
  128.         this(initialOrbit, InertialProvider.of(initialOrbit.getFrame()),
  129.              DEFAULT_MASS, provider, provider.onDate(initialOrbit.getDate()), M2);
  130.     }

  131.     /**
  132.      * Private helper constructor.
  133.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  134.      * @param initialOrbit initial orbit
  135.      * @param attitude attitude provider
  136.      * @param mass spacecraft mass
  137.      * @param provider for un-normalized zonal coefficients
  138.      * @param harmonics {@code provider.onDate(initialOrbit.getDate())}
  139.      * @param M2 value of empirical drag coefficient in rad/s².
  140.      *        If equal to {@link #M2} drag is not computed
  141.      * @see #BrouwerLyddanePropagator(Orbit, AttitudeProvider, double,
  142.      *                                 UnnormalizedSphericalHarmonicsProvider,
  143.      *                                 UnnormalizedSphericalHarmonicsProvider.UnnormalizedSphericalHarmonics,
  144.      *                                 PropagationType, double)
  145.      */
  146.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  147.                                     final AttitudeProvider attitude,
  148.                                     final double mass,
  149.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  150.                                     final UnnormalizedSphericalHarmonics harmonics,
  151.                                     final double M2) {
  152.         this(initialOrbit, attitude, mass, provider.getAe(), provider.getMu(),
  153.              harmonics.getUnnormalizedCnm(2, 0),
  154.              harmonics.getUnnormalizedCnm(3, 0),
  155.              harmonics.getUnnormalizedCnm(4, 0),
  156.              harmonics.getUnnormalizedCnm(5, 0),
  157.              M2);
  158.     }

  159.     /** Build a propagator from orbit and potential.
  160.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  161.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  162.      * are related to both the normalized coefficients
  163.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  164.      *  and the J<sub>n</sub> one as follows:</p>
  165.      *
  166.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  167.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  168.      *
  169.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  170.      *
  171.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  172.      *
  173.      * @param initialOrbit initial orbit
  174.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  175.      * @param mu central attraction coefficient (m³/s²)
  176.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  177.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  178.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  179.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  180.      * @param M2 value of empirical drag coefficient in rad/s².
  181.      *        If equal to {@link #M2} drag is not computed
  182.      * @see org.orekit.utils.Constants
  183.      * @see #BrouwerLyddanePropagator(Orbit, AttitudeProvider, double, double, double,
  184.      * double, double, double, double, double)
  185.      */
  186.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  187.                                     final double referenceRadius, final double mu,
  188.                                     final double c20, final double c30, final double c40,
  189.                                     final double c50, final double M2) {
  190.         this(initialOrbit, InertialProvider.of(initialOrbit.getFrame()),
  191.                 DEFAULT_MASS, referenceRadius, mu, c20, c30, c40, c50, M2);
  192.     }

  193.     /** Build a propagator from orbit, mass and potential provider.
  194.      * <p>Attitude law is set to an unspecified non-null arbitrary value.</p>
  195.      *
  196.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  197.      *
  198.      * @param initialOrbit initial orbit
  199.      * @param mass spacecraft mass
  200.      * @param provider for un-normalized zonal coefficients
  201.      * @param M2 value of empirical drag coefficient in rad/s².
  202.      *        If equal to {@link #M2} drag is not computed
  203.      * @see #BrouwerLyddanePropagator(Orbit, AttitudeProvider, double, UnnormalizedSphericalHarmonicsProvider, double)
  204.      */
  205.     public BrouwerLyddanePropagator(final Orbit initialOrbit, final double mass,
  206.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  207.                                     final double M2) {
  208.         this(initialOrbit, InertialProvider.of(initialOrbit.getFrame()),
  209.              mass, provider, provider.onDate(initialOrbit.getDate()), M2);
  210.     }

  211.     /** Build a propagator from orbit, mass and potential.
  212.      * <p>Attitude law is set to an unspecified non-null arbitrary value.</p>
  213.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  214.      * are related to both the normalized coefficients
  215.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  216.      *  and the J<sub>n</sub> one as follows:</p>
  217.      *
  218.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  219.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  220.      *
  221.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  222.      *
  223.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  224.      *
  225.      * @param initialOrbit initial orbit
  226.      * @param mass spacecraft mass
  227.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  228.      * @param mu central attraction coefficient (m³/s²)
  229.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  230.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  231.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  232.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  233.      * @param M2 value of empirical drag coefficient in rad/s².
  234.      *        If equal to {@link #M2} drag is not computed
  235.      * @see #BrouwerLyddanePropagator(Orbit, AttitudeProvider, double, double, double,
  236.      * double, double, double, double, double)
  237.      */
  238.     public BrouwerLyddanePropagator(final Orbit initialOrbit, final double mass,
  239.                                     final double referenceRadius, final double mu,
  240.                                     final double c20, final double c30, final double c40,
  241.                                     final double c50, final double M2) {
  242.         this(initialOrbit, InertialProvider.of(initialOrbit.getFrame()),
  243.              mass, referenceRadius, mu, c20, c30, c40, c50, M2);
  244.     }

  245.     /** Build a propagator from orbit, attitude provider and potential provider.
  246.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  247.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  248.      * @param initialOrbit initial orbit
  249.      * @param attitudeProv attitude provider
  250.      * @param provider for un-normalized zonal coefficients
  251.      * @param M2 value of empirical drag coefficient in rad/s².
  252.      *        If equal to {@link #M2} drag is not computed
  253.      */
  254.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  255.                                     final AttitudeProvider attitudeProv,
  256.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  257.                                     final double M2) {
  258.         this(initialOrbit, attitudeProv, DEFAULT_MASS, provider, provider.onDate(initialOrbit.getDate()), M2);
  259.     }

  260.     /** Build a propagator from orbit, attitude provider and potential.
  261.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  262.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  263.      * are related to both the normalized coefficients
  264.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  265.      *  and the J<sub>n</sub> one as follows:</p>
  266.      *
  267.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  268.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  269.      *
  270.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  271.      *
  272.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  273.      *
  274.      * @param initialOrbit initial orbit
  275.      * @param attitudeProv attitude provider
  276.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  277.      * @param mu central attraction coefficient (m³/s²)
  278.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  279.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  280.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  281.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  282.      * @param M2 value of empirical drag coefficient in rad/s².
  283.      *        If equal to {@link #M2} drag is not computed
  284.      */
  285.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  286.                                     final AttitudeProvider attitudeProv,
  287.                                     final double referenceRadius, final double mu,
  288.                                     final double c20, final double c30, final double c40,
  289.                                     final double c50, final double M2) {
  290.         this(initialOrbit, attitudeProv, DEFAULT_MASS, referenceRadius, mu, c20, c30, c40, c50, M2);
  291.     }

  292.     /** Build a propagator from orbit, attitude provider, mass and potential provider.
  293.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  294.      * @param initialOrbit initial orbit
  295.      * @param attitudeProv attitude provider
  296.      * @param mass spacecraft mass
  297.      * @param provider for un-normalized zonal coefficients
  298.      * @param M2 value of empirical drag coefficient in rad/s².
  299.      *        If equal to {@link #M2} drag is not computed
  300.      * @see #BrouwerLyddanePropagator(Orbit, AttitudeProvider, double,
  301.      *                                UnnormalizedSphericalHarmonicsProvider, PropagationType, double)
  302.      */
  303.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  304.                                     final AttitudeProvider attitudeProv,
  305.                                     final double mass,
  306.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  307.                                     final double M2) {
  308.         this(initialOrbit, attitudeProv, mass, provider, provider.onDate(initialOrbit.getDate()), M2);
  309.     }

  310.     /** Build a propagator from orbit, attitude provider, mass and potential.
  311.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  312.      * are related to both the normalized coefficients
  313.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  314.      *  and the J<sub>n</sub> one as follows:</p>
  315.      *
  316.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  317.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  318.      *
  319.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  320.      *
  321.      * <p>Using this constructor, an initial osculating orbit is considered.</p>
  322.      *
  323.      * @param initialOrbit initial orbit
  324.      * @param attitudeProv attitude provider
  325.      * @param mass spacecraft mass
  326.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  327.      * @param mu central attraction coefficient (m³/s²)
  328.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  329.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  330.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  331.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  332.      * @param M2 value of empirical drag coefficient in rad/s².
  333.      *        If equal to {@link #M2} drag is not computed
  334.      * @see #BrouwerLyddanePropagator(Orbit, AttitudeProvider, double, double, double,
  335.      *                                 double, double, double, double, PropagationType, double)
  336.      */
  337.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  338.                                     final AttitudeProvider attitudeProv,
  339.                                     final double mass,
  340.                                     final double referenceRadius, final double mu,
  341.                                     final double c20, final double c30, final double c40,
  342.                                     final double c50, final double M2) {
  343.         this(initialOrbit, attitudeProv, mass, referenceRadius, mu, c20, c30, c40, c50,
  344.              PropagationType.OSCULATING, M2);
  345.     }


  346.     /** Build a propagator from orbit and potential provider.
  347.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  348.      *
  349.      * <p>Using this constructor, it is possible to define the initial orbit as
  350.      * a mean Brouwer-Lyddane orbit or an osculating one.</p>
  351.      *
  352.      * @param initialOrbit initial orbit
  353.      * @param provider for un-normalized zonal coefficients
  354.      * @param initialType initial orbit type (mean Brouwer-Lyddane orbit or osculating orbit)
  355.      * @param M2 value of empirical drag coefficient in rad/s².
  356.      *        If equal to {@link #M2} drag is not computed
  357.      */
  358.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  359.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  360.                                     final PropagationType initialType, final double M2) {
  361.         this(initialOrbit, InertialProvider.of(initialOrbit.getFrame()),
  362.              DEFAULT_MASS, provider, provider.onDate(initialOrbit.getDate()), initialType, M2);
  363.     }

  364.     /** Build a propagator from orbit, attitude provider, mass and potential provider.
  365.      * <p>Using this constructor, it is possible to define the initial orbit as
  366.      * a mean Brouwer-Lyddane orbit or an osculating one.</p>
  367.      * @param initialOrbit initial orbit
  368.      * @param attitudeProv attitude provider
  369.      * @param mass spacecraft mass
  370.      * @param provider for un-normalized zonal coefficients
  371.      * @param initialType initial orbit type (mean Brouwer-Lyddane orbit or osculating orbit)
  372.      * @param M2 value of empirical drag coefficient in rad/s².
  373.      *        If equal to {@link #M2} drag is not computed
  374.      */
  375.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  376.                                     final AttitudeProvider attitudeProv,
  377.                                     final double mass,
  378.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  379.                                     final PropagationType initialType, final double M2) {
  380.         this(initialOrbit, attitudeProv, mass, provider, provider.onDate(initialOrbit.getDate()), initialType, M2);
  381.     }

  382.     /**
  383.      * Private helper constructor.
  384.      * <p>Using this constructor, it is possible to define the initial orbit as
  385.      * a mean Brouwer-Lyddane orbit or an osculating one.</p>
  386.      * @param initialOrbit initial orbit
  387.      * @param attitude attitude provider
  388.      * @param mass spacecraft mass
  389.      * @param provider for un-normalized zonal coefficients
  390.      * @param harmonics {@code provider.onDate(initialOrbit.getDate())}
  391.      * @param initialType initial orbit type (mean Brouwer-Lyddane orbit or osculating orbit)
  392.      * @param M2 value of empirical drag coefficient in rad/s².
  393.      *        If equal to {@link #M2} drag is not computed
  394.      */
  395.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  396.                                     final AttitudeProvider attitude,
  397.                                     final double mass,
  398.                                     final UnnormalizedSphericalHarmonicsProvider provider,
  399.                                     final UnnormalizedSphericalHarmonics harmonics,
  400.                                     final PropagationType initialType, final double M2) {
  401.         this(initialOrbit, attitude, mass, provider.getAe(), provider.getMu(),
  402.              harmonics.getUnnormalizedCnm(2, 0),
  403.              harmonics.getUnnormalizedCnm(3, 0),
  404.              harmonics.getUnnormalizedCnm(4, 0),
  405.              harmonics.getUnnormalizedCnm(5, 0),
  406.              initialType, M2);
  407.     }

  408.     /** Build a propagator from orbit, attitude provider, mass and potential.
  409.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  410.      * are related to both the normalized coefficients
  411.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  412.      *  and the J<sub>n</sub> one as follows:</p>
  413.      *
  414.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  415.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  416.      *
  417.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  418.      *
  419.      * <p>Using this constructor, it is possible to define the initial orbit as
  420.      * a mean Brouwer-Lyddane orbit or an osculating one.</p>
  421.      *
  422.      * @param initialOrbit initial orbit
  423.      * @param attitudeProv attitude provider
  424.      * @param mass spacecraft mass
  425.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  426.      * @param mu central attraction coefficient (m³/s²)
  427.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  428.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  429.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  430.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  431.      * @param initialType initial orbit type (mean Brouwer-Lyddane orbit or osculating orbit)
  432.      * @param M2 value of empirical drag coefficient in rad/s².
  433.      *        If equal to {@link #M2} drag is not computed
  434.      */
  435.     public BrouwerLyddanePropagator(final Orbit initialOrbit,
  436.                                     final AttitudeProvider attitudeProv,
  437.                                     final double mass,
  438.                                     final double referenceRadius, final double mu,
  439.                                     final double c20, final double c30, final double c40,
  440.                                     final double c50,
  441.                                     final PropagationType initialType, final double M2) {

  442.         super(attitudeProv);

  443.         // store model coefficients
  444.         this.referenceRadius = referenceRadius;
  445.         this.mu  = mu;
  446.         this.ck0 = new double[] {0.0, 0.0, c20, c30, c40, c50};

  447.         // initialize M2 driver
  448.         this.M2Driver = new ParameterDriver(M2_NAME, M2, SCALE,
  449.                                             Double.NEGATIVE_INFINITY,
  450.                                             Double.POSITIVE_INFINITY);

  451.         // compute mean parameters if needed
  452.         resetInitialState(new SpacecraftState(initialOrbit,
  453.                                               attitudeProv.getAttitude(initialOrbit,
  454.                                                                        initialOrbit.getDate(),
  455.                                                                        initialOrbit.getFrame()),
  456.                                               mass),
  457.                                               initialType);

  458.     }

  459.     /** {@inheritDoc}
  460.      * <p>The new initial state to consider
  461.      * must be defined with an osculating orbit.</p>
  462.      * @see #resetInitialState(SpacecraftState, PropagationType)
  463.      */
  464.     public void resetInitialState(final SpacecraftState state) {
  465.         resetInitialState(state, PropagationType.OSCULATING);
  466.     }

  467.     /** Reset the propagator initial state.
  468.      * @param state new initial state to consider
  469.      * @param stateType mean Brouwer-Lyddane orbit or osculating orbit
  470.      */
  471.     public void resetInitialState(final SpacecraftState state, final PropagationType stateType) {
  472.         super.resetInitialState(state);
  473.         final KeplerianOrbit keplerian = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(state.getOrbit());
  474.         this.initialModel = (stateType == PropagationType.MEAN) ?
  475.                              new BLModel(keplerian, state.getMass(), referenceRadius, mu, ck0) :
  476.                              computeMeanParameters(keplerian, state.getMass());
  477.         this.models = new TimeSpanMap<BLModel>(initialModel);
  478.     }

  479.     /** {@inheritDoc} */
  480.     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
  481.         final BLModel newModel = computeMeanParameters((KeplerianOrbit) OrbitType.KEPLERIAN.convertType(state.getOrbit()),
  482.                                                        state.getMass());
  483.         if (forward) {
  484.             models.addValidAfter(newModel, state.getDate(), false);
  485.         } else {
  486.             models.addValidBefore(newModel, state.getDate(), false);
  487.         }
  488.         stateChanged(state);
  489.     }

  490.     /** Compute mean parameters according to the Brouwer-Lyddane analytical model computation
  491.      * in order to do the propagation.
  492.      * @param osculating osculating orbit
  493.      * @param mass constant mass
  494.      * @return Brouwer-Lyddane mean model
  495.      */
  496.     private BLModel computeMeanParameters(final KeplerianOrbit osculating, final double mass) {

  497.         // sanity check
  498.         if (osculating.getA() < referenceRadius) {
  499.             throw new OrekitException(OrekitMessages.TRAJECTORY_INSIDE_BRILLOUIN_SPHERE,
  500.                                            osculating.getA());
  501.         }

  502.         // rough initialization of the mean parameters
  503.         BLModel current = new BLModel(osculating, mass, referenceRadius, mu, ck0);

  504.         // threshold for each parameter
  505.         final double epsilon         = 1.0e-13;
  506.         final double thresholdA      = epsilon * (1 + FastMath.abs(current.mean.getA()));
  507.         final double thresholdE      = epsilon * (1 + current.mean.getE());
  508.         final double thresholdAngles = epsilon * FastMath.PI;

  509.         int i = 0;
  510.         while (i++ < 200) {

  511.             // recompute the osculating parameters from the current mean parameters
  512.             final UnivariateDerivative2[] parameters = current.propagateParameters(current.mean.getDate());

  513.             // adapted parameters residuals
  514.             final double deltaA     = osculating.getA() - parameters[0].getValue();
  515.             final double deltaE     = osculating.getE() - parameters[1].getValue();
  516.             final double deltaI     = osculating.getI() - parameters[2].getValue();
  517.             final double deltaOmega = MathUtils.normalizeAngle(osculating.getPerigeeArgument() -
  518.                                       parameters[3].getValue(),
  519.                                       0.0);
  520.             final double deltaRAAN  = MathUtils.normalizeAngle(osculating.getRightAscensionOfAscendingNode() -
  521.                                       parameters[4].getValue(),
  522.                                       0.0);
  523.             final double deltaAnom = MathUtils.normalizeAngle(osculating.getMeanAnomaly() -
  524.                                      parameters[5].getValue(),
  525.                                      0.0);


  526.             // update mean parameters
  527.             current = new BLModel(new KeplerianOrbit(current.mean.getA() + deltaA,
  528.                                                      current.mean.getE() + deltaE,
  529.                                                      current.mean.getI() + deltaI,
  530.                                                      current.mean.getPerigeeArgument() + deltaOmega,
  531.                                                      current.mean.getRightAscensionOfAscendingNode() + deltaRAAN,
  532.                                                      current.mean.getMeanAnomaly() + deltaAnom,
  533.                                                      PositionAngle.MEAN,
  534.                                                      current.mean.getFrame(),
  535.                                                      current.mean.getDate(), mu),
  536.                                   mass, referenceRadius, mu, ck0);
  537.             // check convergence
  538.             if (FastMath.abs(deltaA)     < thresholdA &&
  539.                 FastMath.abs(deltaE)     < thresholdE &&
  540.                 FastMath.abs(deltaI)     < thresholdAngles &&
  541.                 FastMath.abs(deltaOmega) < thresholdAngles &&
  542.                 FastMath.abs(deltaRAAN)  < thresholdAngles &&
  543.                 FastMath.abs(deltaAnom)  < thresholdAngles) {
  544.                 return current;
  545.             }
  546.         }
  547.         throw new OrekitException(OrekitMessages.UNABLE_TO_COMPUTE_BROUWER_LYDDANE_MEAN_PARAMETERS, i);
  548.     }


  549.     /** {@inheritDoc} */
  550.     public KeplerianOrbit propagateOrbit(final AbsoluteDate date) {
  551.         // compute Cartesian parameters, taking derivatives into account
  552.         // to make sure velocity and acceleration are consistent
  553.         final BLModel current = models.get(date);
  554.         final UnivariateDerivative2[] propOrb_parameters = current.propagateParameters(date);
  555.         return new KeplerianOrbit(propOrb_parameters[0].getValue(), propOrb_parameters[1].getValue(),
  556.                                   propOrb_parameters[2].getValue(), propOrb_parameters[3].getValue(),
  557.                                   propOrb_parameters[4].getValue(), propOrb_parameters[5].getValue(),
  558.                                   PositionAngle.MEAN, current.mean.getFrame(), date, mu);
  559.     }

  560.     /**
  561.      * Get the value of the M2 drag parameter.
  562.      * @return the value of the M2 drag parameter
  563.      */
  564.     public double getM2() {
  565.         return M2Driver.getValue();
  566.     }

  567.     /**
  568.      * Get the central attraction coefficient μ.
  569.      * @return mu central attraction coefficient (m³/s²)
  570.      */
  571.     public double getMu() {
  572.         return mu;
  573.     }

  574.     /**
  575.      * Get the un-normalized zonal coefficients.
  576.      * @return the un-normalized zonal coefficients
  577.      */
  578.     public double[] getCk0() {
  579.         return ck0.clone();
  580.     }

  581.     /**
  582.      * Get the reference radius of the central body attraction model.
  583.      * @return the reference radius in meters
  584.      */
  585.     public double getReferenceRadius() {
  586.         return referenceRadius;
  587.     }

  588.     /**
  589.      * Get the parameters driver for propagation model.
  590.      * @return drivers for propagation model
  591.      */
  592.     public List<ParameterDriver> getParametersDrivers() {
  593.         return Collections.singletonList(M2Driver);
  594.     }

  595.     /** {@inheritDoc} */
  596.     @Override
  597.     protected AbstractMatricesHarvester createHarvester(final String stmName, final RealMatrix initialStm,
  598.                                                         final DoubleArrayDictionary initialJacobianColumns) {
  599.         return new BrouwerLyddaneHarvester(this, stmName, initialStm, initialJacobianColumns);
  600.     }

  601.     /**
  602.      * Get the names of the parameters in the matrix returned by {@link MatricesHarvester#getParametersJacobian}.
  603.      * @return names of the parameters (i.e. columns) of the Jacobian matrix
  604.      */
  605.     protected List<String> getJacobiansColumnsNames() {
  606.         final List<String> columnsNames = new ArrayList<>();
  607.         for (final ParameterDriver driver : getParametersDrivers()) {
  608.             if (driver.isSelected() && !columnsNames.contains(driver.getName())) {
  609.                 columnsNames.add(driver.getName());
  610.             }
  611.         }
  612.         Collections.sort(columnsNames);
  613.         return columnsNames;
  614.     }

  615.     /** Local class for Brouwer-Lyddane model. */
  616.     private class BLModel {

  617.         /** Mean orbit. */
  618.         private final KeplerianOrbit mean;

  619.         /** Constant mass. */
  620.         private final double mass;

  621.         // CHECKSTYLE: stop JavadocVariable check

  622.         // preprocessed values

  623.         // Constant for secular terms l'', g'', h''
  624.         // l standing for true anomaly, g for perigee argument and h for raan
  625.         private final double xnotDot;
  626.         private final double n;
  627.         private final double lt;
  628.         private final double gt;
  629.         private final double ht;


  630.         // Long period terms
  631.         private final double dei3sg;
  632.         private final double de2sg;
  633.         private final double deisg;
  634.         private final double de;


  635.         private final double dlgs2g;
  636.         private final double dlgc3g;
  637.         private final double dlgcg;


  638.         private final double dh2sgcg;
  639.         private final double dhsgcg;
  640.         private final double dhcg;


  641.         // Short period terms
  642.         private final double aC;
  643.         private final double aCbis;
  644.         private final double ac2g2f;


  645.         private final double eC;
  646.         private final double ecf;
  647.         private final double e2cf;
  648.         private final double e3cf;
  649.         private final double ec2f2g;
  650.         private final double ecfc2f2g;
  651.         private final double e2cfc2f2g;
  652.         private final double e3cfc2f2g;
  653.         private final double ec2gf;
  654.         private final double ec2g3f;


  655.         private final double ide;
  656.         private final double isfs2f2g;
  657.         private final double icfc2f2g;
  658.         private final double ic2f2g;


  659.         private final double glf;
  660.         private final double gll;
  661.         private final double glsf;
  662.         private final double glosf;
  663.         private final double gls2f2g;
  664.         private final double gls2gf;
  665.         private final double glos2gf;
  666.         private final double gls2g3f;
  667.         private final double glos2g3f;


  668.         private final double hf;
  669.         private final double hl;
  670.         private final double hsf;
  671.         private final double hcfs2g2f;
  672.         private final double hs2g2f;
  673.         private final double hsfc2g2f;


  674.         private final double edls2g;
  675.         private final double edlcg;
  676.         private final double edlc3g;
  677.         private final double edlsf;
  678.         private final double edls2gf;
  679.         private final double edls2g3f;

  680.         // Drag terms
  681.         private final double aRate;
  682.         private final double eRate;

  683.         // CHECKSTYLE: resume JavadocVariable check

  684.         /** Create a model for specified mean orbit.
  685.          * @param mean mean orbit
  686.          * @param mass constant mass
  687.          * @param referenceRadius reference radius of the central body attraction model (m)
  688.          * @param mu central attraction coefficient (m³/s²)
  689.          * @param ck0 un-normalized zonal coefficients
  690.          */
  691.         BLModel(final KeplerianOrbit mean, final double mass,
  692.                 final double referenceRadius, final double mu, final double[] ck0) {

  693.             this.mean = mean;
  694.             this.mass = mass;

  695.             final double app = mean.getA();
  696.             xnotDot = FastMath.sqrt(mu / app) / app;

  697.             // preliminary processing
  698.             final double q = referenceRadius / app;
  699.             double ql = q * q;
  700.             final double y2 = -0.5 * ck0[2] * ql;

  701.             n = FastMath.sqrt(1 - mean.getE() * mean.getE());
  702.             final double n2 = n * n;
  703.             final double n3 = n2 * n;
  704.             final double n4 = n2 * n2;
  705.             final double n6 = n4 * n2;
  706.             final double n8 = n4 * n4;
  707.             final double n10 = n8 * n2;

  708.             final double yp2 = y2 / n4;
  709.             ql *= q;
  710.             final double yp3 = ck0[3] * ql / n6;
  711.             ql *= q;
  712.             final double yp4 = 0.375 * ck0[4] * ql / n8;
  713.             ql *= q;
  714.             final double yp5 = ck0[5] * ql / n10;


  715.             final SinCos sc    = FastMath.sinCos(mean.getI());
  716.             final double sinI1 = sc.sin();
  717.             final double sinI2 = sinI1 * sinI1;
  718.             final double cosI1 = sc.cos();
  719.             final double cosI2 = cosI1 * cosI1;
  720.             final double cosI3 = cosI2 * cosI1;
  721.             final double cosI4 = cosI2 * cosI2;
  722.             final double cosI6 = cosI4 * cosI2;
  723.             final double C5c2 = 1.0 / T2(cosI1);
  724.             final double C3c2 = 3.0 * cosI2 - 1.0;

  725.             final double epp = mean.getE();
  726.             final double epp2 = epp * epp;
  727.             final double epp3 = epp2 * epp;
  728.             final double epp4 = epp2 * epp2;

  729.             if (epp >= 1) {
  730.                 // Only for elliptical (e < 1) orbits
  731.                 throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL,
  732.                                           mean.getE());
  733.             }

  734.             // secular multiplicative
  735.             lt = 1 +
  736.                     1.5 * yp2 * n * C3c2 +
  737.                     0.09375 * yp2 * yp2 * n * (-15.0 + 16.0 * n + 25.0 * n2 + (30.0 - 96.0 * n - 90.0 * n2) * cosI2 + (105.0 + 144.0 * n + 25.0 * n2) * cosI4) +
  738.                     0.9375 * yp4 * n * epp2 * (3.0 - 30.0 * cosI2 + 35.0 * cosI4);

  739.             gt = -1.5 * yp2 * C5c2 +
  740.                     0.09375 * yp2 * yp2 * (-35.0 + 24.0 * n + 25.0 * n2 + (90.0 - 192.0 * n - 126.0 * n2) * cosI2 + (385.0 + 360.0 * n + 45.0 * n2) * cosI4) +
  741.                     0.3125 * yp4 * (21.0 - 9.0 * n2 + (-270.0 + 126.0 * n2) * cosI2 + (385.0 - 189.0 * n2) * cosI4 );

  742.             ht = -3.0 * yp2 * cosI1 +
  743.                     0.375 * yp2 * yp2 * ((-5.0 + 12.0 * n + 9.0 * n2) * cosI1 + (-35.0 - 36.0 * n - 5.0 * n2) * cosI3) +
  744.                     1.25 * yp4 * (5.0 - 3.0 * n2) * cosI1 * (3.0 - 7.0 * cosI2);

  745.             final double cA = 1.0 - 11.0 * cosI2 - 40.0 * cosI4 / C5c2;
  746.             final double cB = 1.0 - 3.0 * cosI2 - 8.0 * cosI4 / C5c2;
  747.             final double cC = 1.0 - 9.0 * cosI2 - 24.0 * cosI4 / C5c2;
  748.             final double cD = 1.0 - 5.0 * cosI2 - 16.0 * cosI4 / C5c2;

  749.             final double qyp2_4 = 3.0 * yp2 * yp2 * cA -
  750.                                   10.0 * yp4 * cB;
  751.             final double qyp52 = epp3 * cosI1 * (0.5 * cD / sinI1 +
  752.                                  sinI1 * (5.0 + 32.0 * cosI2 / C5c2 + 80.0 * cosI4 / C5c2 / C5c2));
  753.             final double qyp22 = 2.0 + epp2 - 11.0 * (2.0 + 3.0 * epp2) * cosI2 -
  754.                                  40.0 * (2.0 + 5.0 * epp2) * cosI4 / C5c2 -
  755.                                  400.0 * epp2 * cosI6 / C5c2 / C5c2;
  756.             final double qyp42 = ( qyp22 + 4.0 * (2.0 + epp2 - (2.0 + 3.0 * epp2) * cosI2) ) / 5.0;
  757.             final double qyp52bis = epp * cosI1 * sinI1 *
  758.                                     (4.0 + 3.0 * epp2) *
  759.                                     (3.0 + 16.0 * cosI2 / C5c2 + 40.0 * cosI4 / C5c2 / C5c2);

  760.             // long periodic multiplicative
  761.             dei3sg =  35.0 / 96.0 * yp5 / yp2 * epp2 * n2 * cD * sinI1;
  762.             de2sg = -1.0 / 12.0 * epp * n2 / yp2 * qyp2_4;
  763.             deisg = ( -35.0 / 128.0 * yp5 / yp2 * epp2 * n2 * cD +
  764.                     1.0 / 4.0 * n2 / yp2 * (yp3 + 5.0 / 16.0 * yp5 * (4.0 + 3.0 * epp2) * cC)) * sinI1;
  765.             de = epp2 * n2 / 24.0 / yp2 * qyp2_4;

  766.             final double qyp52quotient = epp * (-32.0 + 81.0 * epp4) / (4.0 + 3.0 * epp2 + n * (4.0 + 9.0 * epp2));
  767.             dlgs2g = 1.0 / 48.0 / yp2 * (-3.0 * yp2 * yp2 * qyp22 +
  768.                      10.0 * yp4 * qyp42 ) +
  769.                      n3 / yp2 * qyp2_4 / 24.0;
  770.             dlgc3g = 35.0 / 384.0 * yp5 / yp2 * n3 * epp * cD * sinI1 +
  771.                      35.0 / 1152.0 * yp5 / yp2 * (2.0 * qyp52 * cosI1 - epp * cD * sinI1 * (3.0 + 2.0 * epp2));
  772.             dlgcg = -yp3 * epp * cosI2 / ( 4.0 * yp2 * sinI1) +
  773.                     0.078125 * yp5 / yp2 * (-epp * cosI2 / sinI1 * (4.0 + 3.0 * epp2) + epp2 * sinI1 * (26.0 + 9.0 * epp2)) * cC -
  774.                     0.46875 * yp5 / yp2 * qyp52bis * cosI1 +
  775.                     0.25 * yp3 / yp2 * sinI1 * epp / (1.0 + n3) * (3.0 - epp2 * (3.0 - epp2)) +
  776.                     0.078125 * yp5 / yp2 * n2 * cC * qyp52quotient * sinI1;


  777.             final double qyp24 = 3.0 * yp2 * yp2 * (11.0 + 80.0 * cosI2 / sinI1 + 200.0 * cosI4 / sinI2) -
  778.                                  10.0 * yp4 * (3.0 + 16.0 * cosI2 / sinI1 + 40.0 * cosI4 / sinI2);
  779.             dh2sgcg = 35.0 / 144.0 * yp5 / yp2 * qyp52;
  780.             dhsgcg = -epp2 * cosI1 / (12.0 * yp2) * qyp24;
  781.             dhcg = -35.0 / 576.0 * yp5 / yp2 * qyp52 +
  782.                    epp * cosI1 / (4.0 * yp2 * sinI1) * (yp3 + 0.3125 * yp5 * (4.0 + 3.0 * epp2) * cC) +
  783.                    1.875 / (4.0 * yp2) * yp5 * qyp52bis;

  784.             // short periodic multiplicative
  785.             aC = -yp2 * C3c2 * app / n3;
  786.             aCbis = y2 * app * C3c2;
  787.             ac2g2f = y2 * app * 3.0 * sinI2;

  788.             double qe = 0.5 * n2 * y2 * C3c2 / n6;
  789.             eC = qe * epp / (1.0 + n3) * (3.0 - epp2 * (3.0 - epp2));
  790.             ecf = 3.0 * qe;
  791.             e2cf = 3.0 * epp * qe;
  792.             e3cf = epp2 * qe;
  793.             qe = 0.5 * n2 * y2 * 3.0 * (1.0 - cosI2) / n6;
  794.             ec2f2g = qe * epp;
  795.             ecfc2f2g = 3.0 * qe;
  796.             e2cfc2f2g = 3.0 * epp * qe;
  797.             e3cfc2f2g = epp2 * qe;
  798.             qe = -0.5 * yp2 * n2 * (1.0 - cosI2);
  799.             ec2gf = 3.0 * qe;
  800.             ec2g3f = qe;

  801.             double qi = epp * yp2 * cosI1 * sinI1;
  802.             ide = -epp * cosI1 / (n2 * sinI1);
  803.             isfs2f2g = qi;
  804.             icfc2f2g = 2.0 * qi;
  805.             qi = yp2 * cosI1 * sinI1;
  806.             ic2f2g = 1.5 * qi;

  807.             double qgl1 = 0.25 * yp2;
  808.             double qgl2 = 0.25 * yp2 * epp * n2 / (1.0 + n);
  809.             glf = qgl1 * -6.0 * C5c2;
  810.             gll = qgl1 * 6.0 * C5c2;
  811.             glsf = qgl1 * -6.0 * C5c2 * epp +
  812.                    qgl2 * 2.0 * C3c2;
  813.             glosf = qgl2 * 2.0 * C3c2;
  814.             qgl1 = qgl1 * (3.0 - 5.0 * cosI2);
  815.             qgl2 = qgl2 * 3.0 * (1.0 - cosI2);
  816.             gls2f2g = 3.0 * qgl1;
  817.             gls2gf = 3.0 * epp * qgl1 +
  818.                      qgl2;
  819.             glos2gf = -1.0 * qgl2;
  820.             gls2g3f = qgl1 * epp +
  821.                       1.0 / 3.0 * qgl2;
  822.             glos2g3f = qgl2;

  823.             final double qh = 3.0 * yp2 * cosI1;
  824.             hf = -qh;
  825.             hl = qh;
  826.             hsf = -epp * qh;
  827.             hcfs2g2f = 2.0 * epp * yp2 * cosI1;
  828.             hs2g2f = 1.5 * yp2 * cosI1;
  829.             hsfc2g2f = -epp * yp2 * cosI1;

  830.             final double qedl = -0.25 * yp2 * n3;
  831.             edls2g = 1.0 / 24.0 * epp * n3 / yp2 * qyp2_4;
  832.             edlcg = -0.25 * yp3 / yp2 * n3 * sinI1 -
  833.                     0.078125 * yp5 / yp2 * n3 * sinI1 * (4.0 + 9.0 * epp2) * cC;
  834.             edlc3g = 35.0 / 384.0 * yp5 / yp2 * n3 * epp2 * cD * sinI1;
  835.             edlsf = 2.0 * qedl * C3c2;
  836.             edls2gf = 3.0 * qedl * (1.0 - cosI2);
  837.             edls2g3f = 1.0 / 3.0 * qedl;

  838.             // secular rates of the mean semi-major axis and eccentricity
  839.             // Eq. 2.41 and Eq. 2.45 of Phipps' 1992 thesis
  840.             aRate = -4.0 * app / (3.0 * xnotDot);
  841.             eRate = -4.0 * epp * n * n / (3.0 * xnotDot);

  842.         }

  843.         /**
  844.          * Accurate computation of E - e sin(E).
  845.          *
  846.          * @param E eccentric anomaly
  847.          * @return E - e sin(E)
  848.          */
  849.         private UnivariateDerivative2 eMeSinE(final UnivariateDerivative2 E) {
  850.             UnivariateDerivative2 x = E.sin().multiply(1 - mean.getE());
  851.             final UnivariateDerivative2 mE2 = E.negate().multiply(E);
  852.             UnivariateDerivative2 term = E;
  853.             UnivariateDerivative2 d    = E.getField().getZero();
  854.             // the inequality test below IS intentional and should NOT be replaced by a check with a small tolerance
  855.             for (UnivariateDerivative2 x0 = d.add(Double.NaN); !Double.valueOf(x.getValue()).equals(Double.valueOf(x0.getValue()));) {
  856.                 d = d.add(2);
  857.                 term = term.multiply(mE2.divide(d.multiply(d.add(1))));
  858.                 x0 = x;
  859.                 x = x.subtract(term);
  860.             }
  861.             return x;
  862.         }

  863.         /**
  864.          * Gets eccentric anomaly from mean anomaly.
  865.          * <p>The algorithm used to solve the Kepler equation has been published in:
  866.          * "Procedures for  solving Kepler's Equation", A. W. Odell and R. H. Gooding,
  867.          * Celestial Mechanics 38 (1986) 307-334</p>
  868.          * <p>It has been copied from the OREKIT library (KeplerianOrbit class).</p>
  869.          *
  870.          * @param mk the mean anomaly (rad)
  871.          * @return the eccentric anomaly (rad)
  872.          */
  873.         private UnivariateDerivative2 getEccentricAnomaly(final UnivariateDerivative2 mk) {
  874.             final double k1 = 3 * FastMath.PI + 2;
  875.             final double k2 = FastMath.PI - 1;
  876.             final double k3 = 6 * FastMath.PI - 1;
  877.             final double A  = 3.0 * k2 * k2 / k1;
  878.             final double B  = k3 * k3 / (6.0 * k1);
  879.             // reduce M to [-PI PI] interval
  880.             final UnivariateDerivative2 reducedM = new UnivariateDerivative2(MathUtils.normalizeAngle(mk.getValue(), 0.0),
  881.                                                                              mk.getFirstDerivative(),
  882.                                                                              mk.getSecondDerivative());

  883.             // compute start value according to A. W. Odell and R. H. Gooding S12 starter
  884.             UnivariateDerivative2 ek;
  885.             if (FastMath.abs(reducedM.getValue()) < 1.0 / 6.0) {
  886.                 if (FastMath.abs(reducedM.getValue()) < Precision.SAFE_MIN) {
  887.                     // this is an Orekit change to the S12 starter.
  888.                     // If reducedM is 0.0, the derivative of cbrt is infinite which induces NaN appearing later in
  889.                     // the computation. As in this case E and M are almost equal, we initialize ek with reducedM
  890.                     ek = reducedM;
  891.                 } else {
  892.                     // this is the standard S12 starter
  893.                     ek = reducedM.add(reducedM.multiply(6).cbrt().subtract(reducedM).multiply(mean.getE()));
  894.                 }
  895.             } else {
  896.                 if (reducedM.getValue() < 0) {
  897.                     final UnivariateDerivative2 w = reducedM.add(FastMath.PI);
  898.                     ek = reducedM.add(w.multiply(-A).divide(w.subtract(B)).subtract(FastMath.PI).subtract(reducedM).multiply(mean.getE()));
  899.                 } else {
  900.                     final UnivariateDerivative2 minusW = reducedM.subtract(FastMath.PI);
  901.                     ek = reducedM.add(minusW.multiply(A).divide(minusW.add(B)).add(FastMath.PI).subtract(reducedM).multiply(mean.getE()));
  902.                 }
  903.             }

  904.             final double e1 = 1 - mean.getE();
  905.             final boolean noCancellationRisk = (e1 + ek.getValue() * ek.getValue() / 6) >= 0.1;

  906.             // perform two iterations, each consisting of one Halley step and one Newton-Raphson step
  907.             for (int j = 0; j < 2; ++j) {
  908.                 final UnivariateDerivative2 f;
  909.                 UnivariateDerivative2 fd;
  910.                 final UnivariateDerivative2 fdd  = ek.sin().multiply(mean.getE());
  911.                 final UnivariateDerivative2 fddd = ek.cos().multiply(mean.getE());
  912.                 if (noCancellationRisk) {
  913.                     f  = ek.subtract(fdd).subtract(reducedM);
  914.                     fd = fddd.subtract(1).negate();
  915.                 } else {
  916.                     f  = eMeSinE(ek).subtract(reducedM);
  917.                     final UnivariateDerivative2 s = ek.multiply(0.5).sin();
  918.                     fd = s.multiply(s).multiply(2 * mean.getE()).add(e1);
  919.                 }
  920.                 final UnivariateDerivative2 dee = f.multiply(fd).divide(f.multiply(0.5).multiply(fdd).subtract(fd.multiply(fd)));

  921.                 // update eccentric anomaly, using expressions that limit underflow problems
  922.                 final UnivariateDerivative2 w = fd.add(dee.multiply(0.5).multiply(fdd.add(dee.multiply(fdd).divide(3))));
  923.                 fd = fd.add(dee.multiply(fdd.add(dee.multiply(0.5).multiply(fdd))));
  924.                 ek = ek.subtract(f.subtract(dee.multiply(fd.subtract(w))).divide(fd));
  925.             }

  926.             // expand the result back to original range
  927.             ek = ek.add(mk.getValue() - reducedM.getValue());

  928.             // Returns the eccentric anomaly
  929.             return ek;
  930.         }

  931.         /**
  932.          * This method is used in Brouwer-Lyddane model to avoid singularity at the
  933.          * critical inclination (i = 63.4°).
  934.          * <p>
  935.          * This method, based on Warren Phipps's 1992 thesis (Eq. 2.47 and 2.48),
  936.          * approximate the factor (1.0 - 5.0 * cos²(inc))^-1 (causing the singularity)
  937.          * by a function, named T2 in the thesis.
  938.          * </p>
  939.          * @param cosInc cosine of the mean inclination
  940.          * @return an approximation of (1.0 - 5.0 * cos²(inc))^-1 term
  941.          */
  942.         private double T2(final double cosInc) {

  943.             // X = (1.0 - 5.0 * cos²(inc))
  944.             final double x  = 1.0 - 5.0 * cosInc * cosInc;
  945.             final double x2 = x * x;

  946.             // Eq. 2.48
  947.             double sum = 0.0;
  948.             for (int i = 0; i <= 12; i++) {
  949.                 final double sign = i % 2 == 0 ? +1.0 : -1.0;
  950.                 sum += sign * FastMath.pow(BETA, i) * FastMath.pow(x2, i) / CombinatoricsUtils.factorialDouble(i + 1);
  951.             }

  952.             // Right term of equation 2.47
  953.             double product = 1.0;
  954.             for (int i = 0; i <= 10; i++) {
  955.                 product *= 1 + FastMath.exp(FastMath.scalb(-1.0, i) * BETA * x2);
  956.             }

  957.             // Return (Eq. 2.47)
  958.             return BETA * x * sum * product;

  959.         }

  960.         /** Extrapolate an orbit up to a specific target date.
  961.          * @param date target date for the orbit
  962.          * @return propagated parameters
  963.          */
  964.         public UnivariateDerivative2[] propagateParameters(final AbsoluteDate date) {

  965.             // Empirical drag coefficient M2
  966.             final double m2 = M2Driver.getValue();

  967.             // Keplerian evolution
  968.             final UnivariateDerivative2 dt = new UnivariateDerivative2(date.durationFrom(mean.getDate()), 1.0, 0.0);
  969.             final UnivariateDerivative2 xnot = dt.multiply(xnotDot);

  970.             //____________________________________
  971.             // secular effects

  972.             // mean mean anomaly (with drag Eq. 2.38 of Phipps' 1992 thesis)
  973.             final UnivariateDerivative2 dtM2  = dt.multiply(m2);
  974.             final UnivariateDerivative2 dt2M2 = dt.multiply(dtM2);
  975.             final UnivariateDerivative2 lpp = new UnivariateDerivative2(MathUtils.normalizeAngle(mean.getMeanAnomaly() + lt * xnot.getValue() + dt2M2.getValue(),
  976.                                                                                                FastMath.PI),
  977.                                                                       lt * xnotDot + 2.0 * dtM2.getValue(),
  978.                                                                       2.0 * m2);
  979.             // mean argument of perigee
  980.             final UnivariateDerivative2 gpp = new UnivariateDerivative2(MathUtils.normalizeAngle(mean.getPerigeeArgument() + gt * xnot.getValue(),
  981.                                                                                                FastMath.PI),
  982.                                                                       gt * xnotDot,
  983.                                                                       0.0);
  984.             // mean longitude of ascending node
  985.             final UnivariateDerivative2 hpp = new UnivariateDerivative2(MathUtils.normalizeAngle(mean.getRightAscensionOfAscendingNode() + ht * xnot.getValue(),
  986.                                                                                                FastMath.PI),
  987.                                                                       ht * xnotDot,
  988.                                                                       0.0);

  989.             // ________________________________________________
  990.             // secular rates of the mean semi-major axis and eccentricity

  991.             // semi-major axis
  992.             final UnivariateDerivative2 appDrag = dt.multiply(aRate * m2);

  993.             // eccentricity
  994.             final UnivariateDerivative2 eppDrag = dt.multiply(eRate * m2);

  995.             //____________________________________
  996.             // Long periodical terms
  997.             final UnivariateDerivative2 cg1 = gpp.cos();
  998.             final UnivariateDerivative2 sg1 = gpp.sin();
  999.             final UnivariateDerivative2 c2g = cg1.multiply(cg1).subtract(sg1.multiply(sg1));
  1000.             final UnivariateDerivative2 s2g = cg1.multiply(sg1).add(sg1.multiply(cg1));
  1001.             final UnivariateDerivative2 c3g = c2g.multiply(cg1).subtract(s2g.multiply(sg1));
  1002.             final UnivariateDerivative2 sg2 = sg1.multiply(sg1);
  1003.             final UnivariateDerivative2 sg3 = sg1.multiply(sg2);


  1004.             // de eccentricity
  1005.             final UnivariateDerivative2 d1e = sg3.multiply(dei3sg).
  1006.                                               add(sg1.multiply(deisg)).
  1007.                                               add(sg2.multiply(de2sg)).
  1008.                                               add(de);

  1009.             // l' + g'
  1010.             final UnivariateDerivative2 lp_p_gp = s2g.multiply(dlgs2g).
  1011.                                                add(c3g.multiply(dlgc3g)).
  1012.                                                add(cg1.multiply(dlgcg)).
  1013.                                                add(lpp).
  1014.                                                add(gpp);

  1015.             // h'
  1016.             final UnivariateDerivative2 hp = sg2.multiply(cg1).multiply(dh2sgcg).
  1017.                                                add(sg1.multiply(cg1).multiply(dhsgcg)).
  1018.                                                add(cg1.multiply(dhcg)).
  1019.                                                add(hpp);

  1020.             // Short periodical terms
  1021.             // eccentric anomaly
  1022.             final UnivariateDerivative2 Ep = getEccentricAnomaly(lpp);
  1023.             final UnivariateDerivative2 cf1 = (Ep.cos().subtract(mean.getE())).divide(Ep.cos().multiply(-mean.getE()).add(1.0));
  1024.             final UnivariateDerivative2 sf1 = (Ep.sin().multiply(n)).divide(Ep.cos().multiply(-mean.getE()).add(1.0));
  1025.             final UnivariateDerivative2 f = FastMath.atan2(sf1, cf1);

  1026.             final UnivariateDerivative2 c2f = cf1.multiply(cf1).subtract(sf1.multiply(sf1));
  1027.             final UnivariateDerivative2 s2f = cf1.multiply(sf1).add(sf1.multiply(cf1));
  1028.             final UnivariateDerivative2 c3f = c2f.multiply(cf1).subtract(s2f.multiply(sf1));
  1029.             final UnivariateDerivative2 s3f = c2f.multiply(sf1).add(s2f.multiply(cf1));
  1030.             final UnivariateDerivative2 cf2 = cf1.multiply(cf1);
  1031.             final UnivariateDerivative2 cf3 = cf1.multiply(cf2);

  1032.             final UnivariateDerivative2 c2g1f = cf1.multiply(c2g).subtract(sf1.multiply(s2g));
  1033.             final UnivariateDerivative2 c2g2f = c2f.multiply(c2g).subtract(s2f.multiply(s2g));
  1034.             final UnivariateDerivative2 c2g3f = c3f.multiply(c2g).subtract(s3f.multiply(s2g));
  1035.             final UnivariateDerivative2 s2g1f = cf1.multiply(s2g).add(c2g.multiply(sf1));
  1036.             final UnivariateDerivative2 s2g2f = c2f.multiply(s2g).add(c2g.multiply(s2f));
  1037.             final UnivariateDerivative2 s2g3f = c3f.multiply(s2g).add(c2g.multiply(s3f));

  1038.             final UnivariateDerivative2 eE = (Ep.cos().multiply(-mean.getE()).add(1.0)).reciprocal();
  1039.             final UnivariateDerivative2 eE3 = eE.multiply(eE).multiply(eE);
  1040.             final UnivariateDerivative2 sigma = eE.multiply(n * n).multiply(eE).add(eE);

  1041.             // Semi-major axis (with drag Eq. 2.41 of Phipps' 1992 thesis)
  1042.             final UnivariateDerivative2 a = eE3.multiply(aCbis).add(appDrag.add(mean.getA())).
  1043.                                             add(aC).
  1044.                                             add(eE3.multiply(c2g2f).multiply(ac2g2f));

  1045.             // Eccentricity (with drag Eq. 2.45 of Phipps' 1992 thesis)
  1046.             final UnivariateDerivative2 e = d1e.add(eppDrag.add(mean.getE())).
  1047.                                             add(eC).
  1048.                                             add(cf1.multiply(ecf)).
  1049.                                             add(cf2.multiply(e2cf)).
  1050.                                             add(cf3.multiply(e3cf)).
  1051.                                             add(c2g2f.multiply(ec2f2g)).
  1052.                                             add(c2g2f.multiply(cf1).multiply(ecfc2f2g)).
  1053.                                             add(c2g2f.multiply(cf2).multiply(e2cfc2f2g)).
  1054.                                             add(c2g2f.multiply(cf3).multiply(e3cfc2f2g)).
  1055.                                             add(c2g1f.multiply(ec2gf)).
  1056.                                             add(c2g3f.multiply(ec2g3f));

  1057.             // Inclination
  1058.             final UnivariateDerivative2 i = d1e.multiply(ide).
  1059.                                             add(mean.getI()).
  1060.                                             add(sf1.multiply(s2g2f.multiply(isfs2f2g))).
  1061.                                             add(cf1.multiply(c2g2f.multiply(icfc2f2g))).
  1062.                                             add(c2g2f.multiply(ic2f2g));

  1063.             // Argument of perigee + True anomaly
  1064.             final UnivariateDerivative2 g_p_l = lp_p_gp.add(f.multiply(glf)).
  1065.                                                 add(lpp.multiply(gll)).
  1066.                                                 add(sf1.multiply(glsf)).
  1067.                                                 add(sigma.multiply(sf1).multiply(glosf)).
  1068.                                                 add(s2g2f.multiply(gls2f2g)).
  1069.                                                 add(s2g1f.multiply(gls2gf)).
  1070.                                                 add(sigma.multiply(s2g1f).multiply(glos2gf)).
  1071.                                                 add(s2g3f.multiply(gls2g3f)).
  1072.                                                 add(sigma.multiply(s2g3f).multiply(glos2g3f));


  1073.             // Longitude of ascending node
  1074.             final UnivariateDerivative2 h = hp.add(f.multiply(hf)).
  1075.                                             add(lpp.multiply(hl)).
  1076.                                             add(sf1.multiply(hsf)).
  1077.                                             add(cf1.multiply(s2g2f).multiply(hcfs2g2f)).
  1078.                                             add(s2g2f.multiply(hs2g2f)).
  1079.                                             add(c2g2f.multiply(sf1).multiply(hsfc2g2f));

  1080.             final UnivariateDerivative2 edl = s2g.multiply(edls2g).
  1081.                                             add(cg1.multiply(edlcg)).
  1082.                                             add(c3g.multiply(edlc3g)).
  1083.                                             add(sf1.multiply(edlsf)).
  1084.                                             add(s2g1f.multiply(edls2gf)).
  1085.                                             add(s2g3f.multiply(edls2g3f)).
  1086.                                             add(sf1.multiply(sigma).multiply(edlsf)).
  1087.                                             add(s2g1f.multiply(sigma).multiply(-edls2gf)).
  1088.                                             add(s2g3f.multiply(sigma).multiply(3.0 * edls2g3f));

  1089.             final UnivariateDerivative2 A = e.multiply(lpp.cos()).subtract(edl.multiply(lpp.sin()));
  1090.             final UnivariateDerivative2 B = e.multiply(lpp.sin()).add(edl.multiply(lpp.cos()));

  1091.             // True anomaly
  1092.             final UnivariateDerivative2 l = FastMath.atan2(B, A);

  1093.             // Argument of perigee
  1094.             final UnivariateDerivative2 g = g_p_l.subtract(l);

  1095.             return new UnivariateDerivative2[] { a, e, i, g, h, l };

  1096.         }

  1097.     }

  1098.     /** {@inheritDoc} */
  1099.     protected double getMass(final AbsoluteDate date) {
  1100.         return models.get(date).mass;
  1101.     }

  1102. }