EcksteinHechlerPropagator.java

  1. /* Copyright 2002-2020 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.io.Serializable;

  19. import org.hipparchus.analysis.differentiation.DSFactory;
  20. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.hipparchus.util.FastMath;
  24. import org.hipparchus.util.MathUtils;
  25. import org.orekit.annotation.DefaultDataContext;
  26. import org.orekit.attitudes.AttitudeProvider;
  27. import org.orekit.data.DataContext;
  28. import org.orekit.errors.OrekitException;
  29. import org.orekit.errors.OrekitMessages;
  30. import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider;
  31. import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider.UnnormalizedSphericalHarmonics;
  32. import org.orekit.orbits.CartesianOrbit;
  33. import org.orekit.orbits.CircularOrbit;
  34. import org.orekit.orbits.Orbit;
  35. import org.orekit.orbits.OrbitType;
  36. import org.orekit.orbits.PositionAngle;
  37. import org.orekit.propagation.Propagator;
  38. import org.orekit.propagation.SpacecraftState;
  39. import org.orekit.time.AbsoluteDate;
  40. import org.orekit.utils.TimeSpanMap;
  41. import org.orekit.utils.TimeStampedPVCoordinates;

  42. /** This class propagates a {@link org.orekit.propagation.SpacecraftState}
  43.  *  using the analytical Eckstein-Hechler model.
  44.  * <p>The Eckstein-Hechler model is suited for near circular orbits
  45.  * (e &lt; 0.1, with poor accuracy between 0.005 and 0.1) and inclination
  46.  * neither equatorial (direct or retrograde) nor critical (direct or
  47.  * retrograde).</p>
  48.  * <p>
  49.  * Note that before version 7.0, there was a large inconsistency in the generated
  50.  * orbits, and it was fixed as of version 7.0 of Orekit, with a visible side effect.
  51.  * The problems is that if the circular parameters produced by the Eckstein-Hechler
  52.  * model are used to build an orbit considered to be osculating, the velocity deduced
  53.  * from this orbit was <em>inconsistent with the position evolution</em>! The reason is
  54.  * that the model includes non-Keplerian effects but it does not include a corresponding
  55.  * circular/Cartesian conversion. As a consequence, all subsequent computation involving
  56.  * velocity were wrong. This includes attitude modes like yaw compensation and Doppler
  57.  * effect. As this effect was considered serious enough and as accurate velocities were
  58.  * considered important, the propagator now generates {@link CartesianOrbit Cartesian
  59.  * orbits} which are built in a special way to ensure consistency throughout propagation.
  60.  * A side effect is that if circular parameters are rebuilt by user from these propagated
  61.  * Cartesian orbit, the circular parameters will generally <em>not</em> match the initial
  62.  * orbit (differences in semi-major axis can exceed 120 m). The position however <em>will</em>
  63.  * match to sub-micrometer level, and this position will be identical to the positions
  64.  * that were generated by previous versions (in other words, the internals of the models
  65.  * have not been changed, only the output parameters have been changed). The correctness
  66.  * of the initialization has been assessed and is good, as it allows the subsequent orbit
  67.  * to remain close to a numerical reference orbit.
  68.  * </p>
  69.  * <p>
  70.  * If users need a more definitive initialization of an Eckstein-Hechler propagator, they
  71.  * should consider using a {@link org.orekit.propagation.conversion.PropagatorConverter
  72.  * propagator converter} to initialize their Eckstein-Hechler propagator using a complete
  73.  * sample instead of just a single initial orbit.
  74.  * </p>
  75.  * @see Orbit
  76.  * @author Guylaine Prat
  77.  */
  78. public class EcksteinHechlerPropagator extends AbstractAnalyticalPropagator {

  79.     /** Initial Eckstein-Hechler model. */
  80.     private EHModel initialModel;

  81.     /** All models. */
  82.     private transient TimeSpanMap<EHModel> models;

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

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

  87.     /** Un-normalized zonal coefficients. */
  88.     private double[] ck0;

  89.     /** Build a propagator from orbit and potential provider.
  90.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  91.      *
  92.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  93.      *
  94.      * @param initialOrbit initial orbit
  95.      * @param provider for un-normalized zonal coefficients
  96.      * @see #EcksteinHechlerPropagator(Orbit, AttitudeProvider,
  97.      * UnnormalizedSphericalHarmonicsProvider)
  98.      */
  99.     @DefaultDataContext
  100.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  101.                                      final UnnormalizedSphericalHarmonicsProvider provider) {
  102.         this(initialOrbit, Propagator.getDefaultLaw(DataContext.getDefault().getFrames()),
  103.                 DEFAULT_MASS, provider, provider.onDate(initialOrbit.getDate()));
  104.     }

  105.     /**
  106.      * Private helper constructor.
  107.      * @param initialOrbit initial orbit
  108.      * @param attitude attitude provider
  109.      * @param mass spacecraft mass
  110.      * @param provider for un-normalized zonal coefficients
  111.      * @param harmonics {@code provider.onDate(initialOrbit.getDate())}
  112.      */
  113.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  114.                                      final AttitudeProvider attitude,
  115.                                      final double mass,
  116.                                      final UnnormalizedSphericalHarmonicsProvider provider,
  117.                                      final UnnormalizedSphericalHarmonics harmonics) {
  118.         this(initialOrbit, attitude, mass, provider.getAe(), provider.getMu(),
  119.              harmonics.getUnnormalizedCnm(2, 0),
  120.              harmonics.getUnnormalizedCnm(3, 0),
  121.              harmonics.getUnnormalizedCnm(4, 0),
  122.              harmonics.getUnnormalizedCnm(5, 0),
  123.              harmonics.getUnnormalizedCnm(6, 0));
  124.     }

  125.     /** Build a propagator from orbit and potential.
  126.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  127.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  128.      * are related to both the normalized coefficients
  129.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  130.      *  and the J<sub>n</sub> one as follows:</p>
  131.      *
  132.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  133.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  134.      *
  135.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  136.      *
  137.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  138.      *
  139.      * @param initialOrbit initial orbit
  140.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  141.      * @param mu central attraction coefficient (m³/s²)
  142.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  143.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  144.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  145.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  146.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  147.      * @see org.orekit.utils.Constants
  148.      * @see #EcksteinHechlerPropagator(Orbit, AttitudeProvider, double, double, double,
  149.      * double, double, double, double, double)
  150.      */
  151.     @DefaultDataContext
  152.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  153.                                      final double referenceRadius, final double mu,
  154.                                      final double c20, final double c30, final double c40,
  155.                                      final double c50, final double c60) {
  156.         this(initialOrbit, Propagator.getDefaultLaw(DataContext.getDefault().getFrames()),
  157.                 DEFAULT_MASS, referenceRadius, mu, c20, c30, c40, c50, c60);
  158.     }

  159.     /** Build a propagator from orbit, mass and potential provider.
  160.      * <p>Attitude law is set to an unspecified non-null arbitrary value.</p>
  161.      *
  162.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  163.      *
  164.      * @param initialOrbit initial orbit
  165.      * @param mass spacecraft mass
  166.      * @param provider for un-normalized zonal coefficients
  167.      * @see #EcksteinHechlerPropagator(Orbit, AttitudeProvider, double,
  168.      * UnnormalizedSphericalHarmonicsProvider)
  169.      */
  170.     @DefaultDataContext
  171.     public EcksteinHechlerPropagator(final Orbit initialOrbit, final double mass,
  172.                                      final UnnormalizedSphericalHarmonicsProvider provider) {
  173.         this(initialOrbit, Propagator.getDefaultLaw(DataContext.getDefault().getFrames()),
  174.                 mass, provider, provider.onDate(initialOrbit.getDate()));
  175.     }

  176.     /** Build a propagator from orbit, mass and potential.
  177.      * <p>Attitude law is set to an unspecified non-null arbitrary value.</p>
  178.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  179.      * are related to both the normalized coefficients
  180.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  181.      *  and the J<sub>n</sub> one as follows:</p>
  182.      *
  183.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  184.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  185.      *
  186.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  187.      *
  188.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  189.      *
  190.      * @param initialOrbit initial orbit
  191.      * @param mass spacecraft mass
  192.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  193.      * @param mu central attraction coefficient (m³/s²)
  194.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  195.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  196.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  197.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  198.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  199.      * @see #EcksteinHechlerPropagator(Orbit, AttitudeProvider, double, double, double,
  200.      * double, double, double, double, double)
  201.      */
  202.     @DefaultDataContext
  203.     public EcksteinHechlerPropagator(final Orbit initialOrbit, final double mass,
  204.                                      final double referenceRadius, final double mu,
  205.                                      final double c20, final double c30, final double c40,
  206.                                      final double c50, final double c60) {
  207.         this(initialOrbit, Propagator.getDefaultLaw(DataContext.getDefault().getFrames()),
  208.                 mass, referenceRadius, mu, c20, c30, c40, c50, c60);
  209.     }

  210.     /** Build a propagator from orbit, attitude provider and potential provider.
  211.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  212.      * @param initialOrbit initial orbit
  213.      * @param attitudeProv attitude provider
  214.      * @param provider for un-normalized zonal coefficients
  215.      */
  216.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  217.                                      final AttitudeProvider attitudeProv,
  218.                                      final UnnormalizedSphericalHarmonicsProvider provider) {
  219.         this(initialOrbit, attitudeProv, DEFAULT_MASS, provider, provider.onDate(initialOrbit.getDate()));
  220.     }

  221.     /** Build a propagator from orbit, attitude provider and potential.
  222.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  223.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  224.      * are related to both the normalized coefficients
  225.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  226.      *  and the J<sub>n</sub> one as follows:</p>
  227.      *
  228.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  229.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  230.      *
  231.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  232.      *
  233.      * @param initialOrbit initial orbit
  234.      * @param attitudeProv attitude provider
  235.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  236.      * @param mu central attraction coefficient (m³/s²)
  237.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  238.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  239.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  240.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  241.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  242.      */
  243.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  244.                                      final AttitudeProvider attitudeProv,
  245.                                      final double referenceRadius, final double mu,
  246.                                      final double c20, final double c30, final double c40,
  247.                                      final double c50, final double c60) {
  248.         this(initialOrbit, attitudeProv, DEFAULT_MASS, referenceRadius, mu, c20, c30, c40, c50, c60);
  249.     }

  250.     /** Build a propagator from orbit, attitude provider, mass and potential provider.
  251.      * @param initialOrbit initial orbit
  252.      * @param attitudeProv attitude provider
  253.      * @param mass spacecraft mass
  254.      * @param provider for un-normalized zonal coefficients
  255.      */
  256.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  257.                                      final AttitudeProvider attitudeProv,
  258.                                      final double mass,
  259.                                      final UnnormalizedSphericalHarmonicsProvider provider) {
  260.         this(initialOrbit, attitudeProv, mass, provider, provider.onDate(initialOrbit.getDate()));
  261.     }

  262.     /** Build a propagator from orbit, attitude provider, mass and potential.
  263.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  264.      * are related to both the normalized coefficients
  265.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  266.      *  and the J<sub>n</sub> one as follows:</p>
  267.      *
  268.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  269.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  270.      *
  271.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  272.      *
  273.      * @param initialOrbit initial orbit
  274.      * @param attitudeProv attitude provider
  275.      * @param mass spacecraft mass
  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 c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  283.      */
  284.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  285.                                      final AttitudeProvider attitudeProv,
  286.                                      final double mass,
  287.                                      final double referenceRadius, final double mu,
  288.                                      final double c20, final double c30, final double c40,
  289.                                      final double c50, final double c60) {

  290.         super(attitudeProv);

  291.         // store model coefficients
  292.         this.referenceRadius = referenceRadius;
  293.         this.mu  = mu;
  294.         this.ck0 = new double[] {
  295.             0.0, 0.0, c20, c30, c40, c50, c60
  296.         };

  297.         // compute mean parameters
  298.         // transform into circular adapted parameters used by the Eckstein-Hechler model
  299.         resetInitialState(new SpacecraftState(initialOrbit,
  300.                                               attitudeProv.getAttitude(initialOrbit,
  301.                                                                        initialOrbit.getDate(),
  302.                                                                        initialOrbit.getFrame()),
  303.                                               mass));

  304.     }

  305.     /** {@inheritDoc} */
  306.     public void resetInitialState(final SpacecraftState state) {
  307.         super.resetInitialState(state);
  308.         this.initialModel = computeMeanParameters((CircularOrbit) OrbitType.CIRCULAR.convertType(state.getOrbit()),
  309.                                                   state.getMass());
  310.         this.models       = new TimeSpanMap<EHModel>(initialModel);
  311.     }

  312.     /** {@inheritDoc} */
  313.     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
  314.         final EHModel newModel = computeMeanParameters((CircularOrbit) OrbitType.CIRCULAR.convertType(state.getOrbit()),
  315.                                                        state.getMass());
  316.         if (forward) {
  317.             models.addValidAfter(newModel, state.getDate());
  318.         } else {
  319.             models.addValidBefore(newModel, state.getDate());
  320.         }
  321.         stateChanged(state);
  322.     }

  323.     /** Compute mean parameters according to the Eckstein-Hechler analytical model.
  324.      * @param osculating osculating orbit
  325.      * @param mass constant mass
  326.      * @return Eckstein-Hechler mean model
  327.      */
  328.     private EHModel computeMeanParameters(final CircularOrbit osculating, final double mass) {

  329.         // sanity check
  330.         if (osculating.getA() < referenceRadius) {
  331.             throw new OrekitException(OrekitMessages.TRAJECTORY_INSIDE_BRILLOUIN_SPHERE,
  332.                                            osculating.getA());
  333.         }

  334.         // rough initialization of the mean parameters
  335.         EHModel current = new EHModel(osculating, mass, referenceRadius, mu, ck0);

  336.         // threshold for each parameter
  337.         final double epsilon         = 1.0e-13;
  338.         final double thresholdA      = epsilon * (1 + FastMath.abs(current.mean.getA()));
  339.         final double thresholdE      = epsilon * (1 + current.mean.getE());
  340.         final double thresholdAngles = epsilon * FastMath.PI;

  341.         int i = 0;
  342.         while (i++ < 100) {

  343.             // recompute the osculating parameters from the current mean parameters
  344.             final DerivativeStructure[] parameters = current.propagateParameters(current.mean.getDate());

  345.             // adapted parameters residuals
  346.             final double deltaA      = osculating.getA()          - parameters[0].getValue();
  347.             final double deltaEx     = osculating.getCircularEx() - parameters[1].getValue();
  348.             final double deltaEy     = osculating.getCircularEy() - parameters[2].getValue();
  349.             final double deltaI      = osculating.getI()          - parameters[3].getValue();
  350.             final double deltaRAAN   = MathUtils.normalizeAngle(osculating.getRightAscensionOfAscendingNode() -
  351.                                                                 parameters[4].getValue(),
  352.                                                                 0.0);
  353.             final double deltaAlphaM = MathUtils.normalizeAngle(osculating.getAlphaM() - parameters[5].getValue(), 0.0);

  354.             // update mean parameters
  355.             current = new EHModel(new CircularOrbit(current.mean.getA()          + deltaA,
  356.                                                     current.mean.getCircularEx() + deltaEx,
  357.                                                     current.mean.getCircularEy() + deltaEy,
  358.                                                     current.mean.getI()          + deltaI,
  359.                                                     current.mean.getRightAscensionOfAscendingNode() + deltaRAAN,
  360.                                                     current.mean.getAlphaM()     + deltaAlphaM,
  361.                                                     PositionAngle.MEAN,
  362.                                                     current.mean.getFrame(),
  363.                                                     current.mean.getDate(), mu),
  364.                                   mass, referenceRadius, mu, ck0);

  365.             // check convergence
  366.             if ((FastMath.abs(deltaA)      < thresholdA) &&
  367.                 (FastMath.abs(deltaEx)     < thresholdE) &&
  368.                 (FastMath.abs(deltaEy)     < thresholdE) &&
  369.                 (FastMath.abs(deltaI)      < thresholdAngles) &&
  370.                 (FastMath.abs(deltaRAAN)   < thresholdAngles) &&
  371.                 (FastMath.abs(deltaAlphaM) < thresholdAngles)) {
  372.                 return current;
  373.             }

  374.         }

  375.         throw new OrekitException(OrekitMessages.UNABLE_TO_COMPUTE_ECKSTEIN_HECHLER_MEAN_PARAMETERS, i);

  376.     }

  377.     /** {@inheritDoc} */
  378.     public CartesianOrbit propagateOrbit(final AbsoluteDate date) {
  379.         // compute Cartesian parameters, taking derivatives into account
  380.         // to make sure velocity and acceleration are consistent
  381.         final EHModel current = models.get(date);
  382.         return new CartesianOrbit(toCartesian(date, current.propagateParameters(date)),
  383.                                   current.mean.getFrame(), mu);
  384.     }

  385.     /** Local class for Eckstein-Hechler model, with fixed mean parameters. */
  386.     private static class EHModel implements Serializable {

  387.         /** Serializable UID. */
  388.         private static final long serialVersionUID = 20160115L;

  389.         /** Factory for derivatives. */
  390.         private static final DSFactory FACTORY = new DSFactory(1, 2);

  391.         /** Mean orbit. */
  392.         private final CircularOrbit mean;

  393.         /** Constant mass. */
  394.         private final double mass;

  395.         // CHECKSTYLE: stop JavadocVariable check

  396.         // preprocessed values
  397.         private final double xnotDot;
  398.         private final double rdpom;
  399.         private final double rdpomp;
  400.         private final double eps1;
  401.         private final double eps2;
  402.         private final double xim;
  403.         private final double ommD;
  404.         private final double rdl;
  405.         private final double aMD;

  406.         private final double kh;
  407.         private final double kl;

  408.         private final double ax1;
  409.         private final double ay1;
  410.         private final double as1;
  411.         private final double ac2;
  412.         private final double axy3;
  413.         private final double as3;
  414.         private final double ac4;
  415.         private final double as5;
  416.         private final double ac6;

  417.         private final double ex1;
  418.         private final double exx2;
  419.         private final double exy2;
  420.         private final double ex3;
  421.         private final double ex4;

  422.         private final double ey1;
  423.         private final double eyx2;
  424.         private final double eyy2;
  425.         private final double ey3;
  426.         private final double ey4;

  427.         private final double rx1;
  428.         private final double ry1;
  429.         private final double r2;
  430.         private final double r3;
  431.         private final double rl;

  432.         private final double iy1;
  433.         private final double ix1;
  434.         private final double i2;
  435.         private final double i3;
  436.         private final double ih;

  437.         private final double lx1;
  438.         private final double ly1;
  439.         private final double l2;
  440.         private final double l3;
  441.         private final double ll;

  442.         // CHECKSTYLE: resume JavadocVariable check

  443.         /** Create a model for specified mean orbit.
  444.          * @param mean mean orbit
  445.          * @param mass constant mass
  446.          * @param referenceRadius reference radius of the central body attraction model (m)
  447.          * @param mu central attraction coefficient (m³/s²)
  448.          * @param ck0 un-normalized zonal coefficients
  449.          */
  450.         EHModel(final CircularOrbit mean, final double mass,
  451.                 final double referenceRadius, final double mu, final double[] ck0) {

  452.             this.mean            = mean;
  453.             this.mass            = mass;

  454.             // preliminary processing
  455.             double q = referenceRadius / mean.getA();
  456.             double ql = q * q;
  457.             final double g2 = ck0[2] * ql;
  458.             ql *= q;
  459.             final double g3 = ck0[3] * ql;
  460.             ql *= q;
  461.             final double g4 = ck0[4] * ql;
  462.             ql *= q;
  463.             final double g5 = ck0[5] * ql;
  464.             ql *= q;
  465.             final double g6 = ck0[6] * ql;

  466.             final double cosI1 = FastMath.cos(mean.getI());
  467.             final double sinI1 = FastMath.sin(mean.getI());
  468.             final double sinI2 = sinI1 * sinI1;
  469.             final double sinI4 = sinI2 * sinI2;
  470.             final double sinI6 = sinI2 * sinI4;

  471.             if (sinI2 < 1.0e-10) {
  472.                 throw new OrekitException(OrekitMessages.ALMOST_EQUATORIAL_ORBIT,
  473.                                           FastMath.toDegrees(mean.getI()));
  474.             }

  475.             if (FastMath.abs(sinI2 - 4.0 / 5.0) < 1.0e-3) {
  476.                 throw new OrekitException(OrekitMessages.ALMOST_CRITICALLY_INCLINED_ORBIT,
  477.                                           FastMath.toDegrees(mean.getI()));
  478.             }

  479.             if (mean.getE() > 0.1) {
  480.                 // if 0.005 < e < 0.1 no error is triggered, but accuracy is poor
  481.                 throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL,
  482.                                           mean.getE());
  483.             }

  484.             xnotDot = FastMath.sqrt(mu / mean.getA()) / mean.getA();

  485.             rdpom = -0.75 * g2 * (4.0 - 5.0 * sinI2);
  486.             rdpomp = 7.5 * g4 * (1.0 - 31.0 / 8.0 * sinI2 + 49.0 / 16.0 * sinI4) -
  487.                     13.125 * g6 * (1.0 - 8.0 * sinI2 + 129.0 / 8.0 * sinI4 - 297.0 / 32.0 * sinI6);

  488.             q = 3.0 / (32.0 * rdpom);
  489.             eps1 = q * g4 * sinI2 * (30.0 - 35.0 * sinI2) -
  490.                     175.0 * q * g6 * sinI2 * (1.0 - 3.0 * sinI2 + 2.0625 * sinI4);
  491.             q = 3.0 * sinI1 / (8.0 * rdpom);
  492.             eps2 = q * g3 * (4.0 - 5.0 * sinI2) - q * g5 * (10.0 - 35.0 * sinI2 + 26.25 * sinI4);

  493.             xim = mean.getI();
  494.             ommD = cosI1 * (1.50    * g2 - 2.25 * g2 * g2 * (2.5 - 19.0 / 6.0 * sinI2) +
  495.                             0.9375  * g4 * (7.0 * sinI2 - 4.0) +
  496.                             3.28125 * g6 * (2.0 - 9.0 * sinI2 + 8.25 * sinI4));

  497.             rdl = 1.0 - 1.50 * g2 * (3.0 - 4.0 * sinI2);
  498.             aMD = rdl +
  499.                     2.25 * g2 * g2 * (9.0 - 263.0 / 12.0 * sinI2 + 341.0 / 24.0 * sinI4) +
  500.                     15.0 / 16.0 * g4 * (8.0 - 31.0 * sinI2 + 24.5 * sinI4) +
  501.                     105.0 / 32.0 * g6 * (-10.0 / 3.0 + 25.0 * sinI2 - 48.75 * sinI4 + 27.5 * sinI6);

  502.             final double qq = -1.5 * g2 / rdl;
  503.             final double qA   = 0.75 * g2 * g2 * sinI2;
  504.             final double qB   = 0.25 * g4 * sinI2;
  505.             final double qC   = 105.0 / 16.0 * g6 * sinI2;
  506.             final double qD   = -0.75 * g3 * sinI1;
  507.             final double qE   = 3.75 * g5 * sinI1;
  508.             kh = 0.375 / rdpom;
  509.             kl = kh / sinI1;

  510.             ax1 = qq * (2.0 - 3.5 * sinI2);
  511.             ay1 = qq * (2.0 - 2.5 * sinI2);
  512.             as1 = qD * (4.0 - 5.0 * sinI2) +
  513.                   qE * (2.625 * sinI4 - 3.5 * sinI2 + 1.0);
  514.             ac2 = qq * sinI2 +
  515.                   qA * 7.0 * (2.0 - 3.0 * sinI2) +
  516.                   qB * (15.0 - 17.5 * sinI2) +
  517.                   qC * (3.0 * sinI2 - 1.0 - 33.0 / 16.0 * sinI4);
  518.             axy3 = qq * 3.5 * sinI2;
  519.             as3 = qD * 5.0 / 3.0 * sinI2 +
  520.                   qE * 7.0 / 6.0 * sinI2 * (1.0 - 1.125 * sinI2);
  521.             ac4 = qA * sinI2 +
  522.                   qB * 4.375 * sinI2 +
  523.                   qC * 0.75 * (1.1 * sinI4 - sinI2);

  524.             as5 = qE * 21.0 / 80.0 * sinI4;

  525.             ac6 = qC * -11.0 / 80.0 * sinI4;

  526.             ex1 = qq * (1.0 - 1.25 * sinI2);
  527.             exx2 = qq * 0.5 * (3.0 - 5.0 * sinI2);
  528.             exy2 = qq * (2.0 - 1.5 * sinI2);
  529.             ex3 = qq * 7.0 / 12.0 * sinI2;
  530.             ex4 = qq * 17.0 / 8.0 * sinI2;

  531.             ey1 = qq * (1.0 - 1.75 * sinI2);
  532.             eyx2 = qq * (1.0 - 3.0 * sinI2);
  533.             eyy2 = qq * (2.0 * sinI2 - 1.5);
  534.             ey3 = qq * 7.0 / 12.0 * sinI2;
  535.             ey4 = qq * 17.0 / 8.0 * sinI2;

  536.             q  = -qq * cosI1;
  537.             rx1 =  3.5 * q;
  538.             ry1 = -2.5 * q;
  539.             r2 = -0.5 * q;
  540.             r3 =  7.0 / 6.0 * q;
  541.             rl = g3 * cosI1 * (4.0 - 15.0 * sinI2) -
  542.                  2.5 * g5 * cosI1 * (4.0 - 42.0 * sinI2 + 52.5 * sinI4);

  543.             q = 0.5 * qq * sinI1 * cosI1;
  544.             iy1 =  q;
  545.             ix1 = -q;
  546.             i2 =  q;
  547.             i3 =  q * 7.0 / 3.0;
  548.             ih = -g3 * cosI1 * (4.0 - 5.0 * sinI2) +
  549.                  2.5 * g5 * cosI1 * (4.0 - 14.0 * sinI2 + 10.5 * sinI4);

  550.             lx1 = qq * (7.0 - 77.0 / 8.0 * sinI2);
  551.             ly1 = qq * (55.0 / 8.0 * sinI2 - 7.50);
  552.             l2 = qq * (1.25 * sinI2 - 0.5);
  553.             l3 = qq * (77.0 / 24.0 * sinI2 - 7.0 / 6.0);
  554.             ll = g3 * (53.0 * sinI2 - 4.0 - 57.5 * sinI4) +
  555.                  2.5 * g5 * (4.0 - 96.0 * sinI2 + 269.5 * sinI4 - 183.75 * sinI6);

  556.         }

  557.         /** Extrapolate an orbit up to a specific target date.
  558.          * @param date target date for the orbit
  559.          * @return propagated parameters
  560.          */
  561.         public DerivativeStructure[] propagateParameters(final AbsoluteDate date) {

  562.             // Keplerian evolution
  563.             final DerivativeStructure dt = FACTORY.variable(0, date.durationFrom(mean.getDate()));
  564.             final DerivativeStructure xnot = dt.multiply(xnotDot);

  565.             // secular effects

  566.             // eccentricity
  567.             final DerivativeStructure x   = xnot.multiply(rdpom + rdpomp);
  568.             final DerivativeStructure cx  = x.cos();
  569.             final DerivativeStructure sx  = x.sin();
  570.             final DerivativeStructure exm = cx.multiply(mean.getCircularEx()).
  571.                                             add(sx.multiply(eps2 - (1.0 - eps1) * mean.getCircularEy()));
  572.             final DerivativeStructure eym = sx.multiply((1.0 + eps1) * mean.getCircularEx()).
  573.                                             add(cx.multiply(mean.getCircularEy() - eps2)).
  574.                                             add(eps2);

  575.             // no secular effect on inclination

  576.             // right ascension of ascending node
  577.             final DerivativeStructure omm =
  578.                             FACTORY.build(MathUtils.normalizeAngle(mean.getRightAscensionOfAscendingNode() + ommD * xnot.getValue(),
  579.                                                            FastMath.PI),
  580.                                   ommD * xnotDot,
  581.                                   0.0);

  582.             // latitude argument
  583.             final DerivativeStructure xlm =
  584.                             FACTORY.build(MathUtils.normalizeAngle(mean.getAlphaM() + aMD * xnot.getValue(), FastMath.PI),
  585.                                   aMD * xnotDot,
  586.                                   0.0);

  587.             // periodical terms
  588.             final DerivativeStructure cl1 = xlm.cos();
  589.             final DerivativeStructure sl1 = xlm.sin();
  590.             final DerivativeStructure cl2 = cl1.multiply(cl1).subtract(sl1.multiply(sl1));
  591.             final DerivativeStructure sl2 = cl1.multiply(sl1).add(sl1.multiply(cl1));
  592.             final DerivativeStructure cl3 = cl2.multiply(cl1).subtract(sl2.multiply(sl1));
  593.             final DerivativeStructure sl3 = cl2.multiply(sl1).add(sl2.multiply(cl1));
  594.             final DerivativeStructure cl4 = cl3.multiply(cl1).subtract(sl3.multiply(sl1));
  595.             final DerivativeStructure sl4 = cl3.multiply(sl1).add(sl3.multiply(cl1));
  596.             final DerivativeStructure cl5 = cl4.multiply(cl1).subtract(sl4.multiply(sl1));
  597.             final DerivativeStructure sl5 = cl4.multiply(sl1).add(sl4.multiply(cl1));
  598.             final DerivativeStructure cl6 = cl5.multiply(cl1).subtract(sl5.multiply(sl1));

  599.             final DerivativeStructure qh  = eym.subtract(eps2).multiply(kh);
  600.             final DerivativeStructure ql  = exm.multiply(kl);

  601.             final DerivativeStructure exmCl1 = exm.multiply(cl1);
  602.             final DerivativeStructure exmSl1 = exm.multiply(sl1);
  603.             final DerivativeStructure eymCl1 = eym.multiply(cl1);
  604.             final DerivativeStructure eymSl1 = eym.multiply(sl1);
  605.             final DerivativeStructure exmCl2 = exm.multiply(cl2);
  606.             final DerivativeStructure exmSl2 = exm.multiply(sl2);
  607.             final DerivativeStructure eymCl2 = eym.multiply(cl2);
  608.             final DerivativeStructure eymSl2 = eym.multiply(sl2);
  609.             final DerivativeStructure exmCl3 = exm.multiply(cl3);
  610.             final DerivativeStructure exmSl3 = exm.multiply(sl3);
  611.             final DerivativeStructure eymCl3 = eym.multiply(cl3);
  612.             final DerivativeStructure eymSl3 = eym.multiply(sl3);
  613.             final DerivativeStructure exmCl4 = exm.multiply(cl4);
  614.             final DerivativeStructure exmSl4 = exm.multiply(sl4);
  615.             final DerivativeStructure eymCl4 = eym.multiply(cl4);
  616.             final DerivativeStructure eymSl4 = eym.multiply(sl4);

  617.             // semi major axis
  618.             final DerivativeStructure rda = exmCl1.multiply(ax1).
  619.                                             add(eymSl1.multiply(ay1)).
  620.                                             add(sl1.multiply(as1)).
  621.                                             add(cl2.multiply(ac2)).
  622.                                             add(exmCl3.add(eymSl3).multiply(axy3)).
  623.                                             add(sl3.multiply(as3)).
  624.                                             add(cl4.multiply(ac4)).
  625.                                             add(sl5.multiply(as5)).
  626.                                             add(cl6.multiply(ac6));

  627.             // eccentricity
  628.             final DerivativeStructure rdex = cl1.multiply(ex1).
  629.                                              add(exmCl2.multiply(exx2)).
  630.                                              add(eymSl2.multiply(exy2)).
  631.                                              add(cl3.multiply(ex3)).
  632.                                              add(exmCl4.add(eymSl4).multiply(ex4));
  633.             final DerivativeStructure rdey = sl1.multiply(ey1).
  634.                                              add(exmSl2.multiply(eyx2)).
  635.                                              add(eymCl2.multiply(eyy2)).
  636.                                              add(sl3.multiply(ey3)).
  637.                                              add(exmSl4.subtract(eymCl4).multiply(ey4));

  638.             // ascending node
  639.             final DerivativeStructure rdom = exmSl1.multiply(rx1).
  640.                                              add(eymCl1.multiply(ry1)).
  641.                                              add(sl2.multiply(r2)).
  642.                                              add(eymCl3.subtract(exmSl3).multiply(r3)).
  643.                                              add(ql.multiply(rl));

  644.             // inclination
  645.             final DerivativeStructure rdxi = eymSl1.multiply(iy1).
  646.                                              add(exmCl1.multiply(ix1)).
  647.                                              add(cl2.multiply(i2)).
  648.                                              add(exmCl3.add(eymSl3).multiply(i3)).
  649.                                              add(qh.multiply(ih));

  650.             // latitude argument
  651.             final DerivativeStructure rdxl = exmSl1.multiply(lx1).
  652.                                              add(eymCl1.multiply(ly1)).
  653.                                              add(sl2.multiply(l2)).
  654.                                              add(exmSl3.subtract(eymCl3).multiply(l3)).
  655.                                              add(ql.multiply(ll));

  656.             // osculating parameters
  657.             return new DerivativeStructure[] {
  658.                 rda.add(1.0).multiply(mean.getA()),
  659.                 rdex.add(exm),
  660.                 rdey.add(eym),
  661.                 rdxi.add(xim),
  662.                 rdom.add(omm),
  663.                 rdxl.add(xlm)
  664.             };

  665.         }

  666.     }

  667.     /** Convert circular parameters <em>with derivatives</em> to Cartesian coordinates.
  668.      * @param date date of the orbital parameters
  669.      * @param parameters circular parameters (a, ex, ey, i, raan, alphaM)
  670.      * @return Cartesian coordinates consistent with values and derivatives
  671.      */
  672.     private TimeStampedPVCoordinates toCartesian(final AbsoluteDate date, final DerivativeStructure[] parameters) {

  673.         // evaluate coordinates in the orbit canonical reference frame
  674.         final DerivativeStructure cosOmega = parameters[4].cos();
  675.         final DerivativeStructure sinOmega = parameters[4].sin();
  676.         final DerivativeStructure cosI     = parameters[3].cos();
  677.         final DerivativeStructure sinI     = parameters[3].sin();
  678.         final DerivativeStructure alphaE   = meanToEccentric(parameters[5], parameters[1], parameters[2]);
  679.         final DerivativeStructure cosAE    = alphaE.cos();
  680.         final DerivativeStructure sinAE    = alphaE.sin();
  681.         final DerivativeStructure ex2      = parameters[1].multiply(parameters[1]);
  682.         final DerivativeStructure ey2      = parameters[2].multiply(parameters[2]);
  683.         final DerivativeStructure exy      = parameters[1].multiply(parameters[2]);
  684.         final DerivativeStructure q        = ex2.add(ey2).subtract(1).negate().sqrt();
  685.         final DerivativeStructure beta     = q.add(1).reciprocal();
  686.         final DerivativeStructure bx2      = beta.multiply(ex2);
  687.         final DerivativeStructure by2      = beta.multiply(ey2);
  688.         final DerivativeStructure bxy      = beta.multiply(exy);
  689.         final DerivativeStructure u        = bxy.multiply(sinAE).subtract(parameters[1].add(by2.subtract(1).multiply(cosAE)));
  690.         final DerivativeStructure v        = bxy.multiply(cosAE).subtract(parameters[2].add(bx2.subtract(1).multiply(sinAE)));
  691.         final DerivativeStructure x        = parameters[0].multiply(u);
  692.         final DerivativeStructure y        = parameters[0].multiply(v);

  693.         // canonical orbit reference frame
  694.         final FieldVector3D<DerivativeStructure> p =
  695.                 new FieldVector3D<>(x.multiply(cosOmega).subtract(y.multiply(cosI.multiply(sinOmega))),
  696.                                     x.multiply(sinOmega).add(y.multiply(cosI.multiply(cosOmega))),
  697.                                     y.multiply(sinI));

  698.         // dispatch derivatives
  699.         final Vector3D p0 = new Vector3D(p.getX().getValue(),
  700.                                          p.getY().getValue(),
  701.                                          p.getZ().getValue());
  702.         final Vector3D p1 = new Vector3D(p.getX().getPartialDerivative(1),
  703.                                          p.getY().getPartialDerivative(1),
  704.                                          p.getZ().getPartialDerivative(1));
  705.         final Vector3D p2 = new Vector3D(p.getX().getPartialDerivative(2),
  706.                                          p.getY().getPartialDerivative(2),
  707.                                          p.getZ().getPartialDerivative(2));
  708.         return new TimeStampedPVCoordinates(date, p0, p1, p2);

  709.     }

  710.     /** Computes the eccentric latitude argument from the mean latitude argument.
  711.      * @param alphaM = M + Ω mean latitude argument (rad)
  712.      * @param ex e cos(Ω), first component of circular eccentricity vector
  713.      * @param ey e sin(Ω), second component of circular eccentricity vector
  714.      * @return the eccentric latitude argument.
  715.      */
  716.     private DerivativeStructure meanToEccentric(final DerivativeStructure alphaM,
  717.                                                 final DerivativeStructure ex,
  718.                                                 final DerivativeStructure ey) {
  719.         // Generalization of Kepler equation to circular parameters
  720.         // with alphaE = PA + E and
  721.         //      alphaM = PA + M = alphaE - ex.sin(alphaE) + ey.cos(alphaE)
  722.         DerivativeStructure alphaE        = alphaM;
  723.         DerivativeStructure shift         = alphaM.getField().getZero();
  724.         DerivativeStructure alphaEMalphaM = alphaM.getField().getZero();
  725.         DerivativeStructure cosAlphaE     = alphaE.cos();
  726.         DerivativeStructure sinAlphaE     = alphaE.sin();
  727.         int                 iter          = 0;
  728.         do {
  729.             final DerivativeStructure f2 = ex.multiply(sinAlphaE).subtract(ey.multiply(cosAlphaE));
  730.             final DerivativeStructure f1 = alphaM.getField().getOne().subtract(ex.multiply(cosAlphaE)).subtract(ey.multiply(sinAlphaE));
  731.             final DerivativeStructure f0 = alphaEMalphaM.subtract(f2);

  732.             final DerivativeStructure f12 = f1.multiply(2);
  733.             shift = f0.multiply(f12).divide(f1.multiply(f12).subtract(f0.multiply(f2)));

  734.             alphaEMalphaM  = alphaEMalphaM.subtract(shift);
  735.             alphaE         = alphaM.add(alphaEMalphaM);
  736.             cosAlphaE      = alphaE.cos();
  737.             sinAlphaE      = alphaE.sin();

  738.         } while ((++iter < 50) && (FastMath.abs(shift.getValue()) > 1.0e-12));

  739.         return alphaE;

  740.     }

  741.     /** {@inheritDoc} */
  742.     protected double getMass(final AbsoluteDate date) {
  743.         return models.get(date).mass;
  744.     }

  745. }