EcksteinHechlerPropagator.java

  1. /* Copyright 2002-2015 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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 org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
  19. import org.apache.commons.math3.geometry.euclidean.threed.FieldVector3D;
  20. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  21. import org.apache.commons.math3.util.FastMath;
  22. import org.apache.commons.math3.util.MathUtils;
  23. import org.orekit.attitudes.AttitudeProvider;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.errors.OrekitMessages;
  26. import org.orekit.errors.PropagationException;
  27. import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider;
  28. import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider.UnnormalizedSphericalHarmonics;
  29. import org.orekit.orbits.CartesianOrbit;
  30. import org.orekit.orbits.CircularOrbit;
  31. import org.orekit.orbits.Orbit;
  32. import org.orekit.orbits.OrbitType;
  33. import org.orekit.orbits.PositionAngle;
  34. import org.orekit.propagation.SpacecraftState;
  35. import org.orekit.time.AbsoluteDate;
  36. import org.orekit.utils.TimeStampedPVCoordinates;

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

  74.     /** Eckstein-Hechler model. */
  75.     private EHModel model;

  76.     /** Current mass. */
  77.     private double mass;

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

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

  82.     /** Un-normalized zonal coefficients. */
  83.     private double[] ck0;

  84.     /** Build a propagator from orbit and potential provider.
  85.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  86.      * @param initialOrbit initial orbit
  87.      * @param provider for un-normalized zonal coefficients
  88.      * @exception OrekitException if the zonal coefficients cannot be retrieved
  89.      * @exception PropagationException if the mean parameters cannot be computed
  90.      */
  91.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  92.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  93.         throws PropagationException , OrekitException {
  94.         this(initialOrbit, DEFAULT_LAW, DEFAULT_MASS, provider,
  95.                 provider.onDate(initialOrbit.getDate()));
  96.     }

  97.     /**
  98.      * Private helper constructor.
  99.      * @param initialOrbit initial orbit
  100.      * @param attitude attitude provider
  101.      * @param mass spacecraft mass
  102.      * @param provider for un-normalized zonal coefficients
  103.      * @param harmonics {@code provider.onDate(initialOrbit.getDate())}
  104.      * @exception OrekitException if the zonal coefficients cannot be retrieved
  105.      */
  106.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  107.                                      final AttitudeProvider attitude,
  108.                                      final double mass,
  109.                                      final UnnormalizedSphericalHarmonicsProvider provider,
  110.                                      final UnnormalizedSphericalHarmonics harmonics)
  111.         throws OrekitException {
  112.         this(initialOrbit, attitude, mass, provider.getAe(), provider.getMu(),
  113.                 harmonics.getUnnormalizedCnm(2, 0),
  114.                 harmonics.getUnnormalizedCnm(3, 0),
  115.                 harmonics.getUnnormalizedCnm(4, 0),
  116.                 harmonics.getUnnormalizedCnm(5, 0),
  117.                 harmonics.getUnnormalizedCnm(6, 0));
  118.     }

  119.     /** Build a propagator from orbit and potential.
  120.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  121.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  122.      * are related to both the normalized coefficients
  123.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  124.      *  and the J<sub>n</sub> one as follows:</p>
  125.      * <pre>
  126.      *   C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  127.      *                      <span style="text-decoration: overline">C</span><sub>n,0</sub>
  128.      *   C<sub>n,0</sub> = -J<sub>n</sub>
  129.      * </pre>
  130.      * @param initialOrbit initial orbit
  131.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  132.      * @param mu central attraction coefficient (m³/s²)
  133.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  134.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  135.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  136.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  137.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  138.      * @exception PropagationException if the mean parameters cannot be computed
  139.      * @see org.orekit.utils.Constants
  140.      */
  141.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  142.                                      final double referenceRadius, final double mu,
  143.                                      final double c20, final double c30, final double c40,
  144.                                      final double c50, final double c60)
  145.         throws PropagationException {
  146.         this(initialOrbit, DEFAULT_LAW, DEFAULT_MASS, referenceRadius, mu, c20, c30, c40, c50, c60);
  147.     }

  148.     /** Build a propagator from orbit, mass and potential provider.
  149.      * <p>Attitude law is set to an unspecified non-null arbitrary value.</p>
  150.      * @param initialOrbit initial orbit
  151.      * @param mass spacecraft mass
  152.      * @param provider for un-normalized zonal coefficients
  153.      * @exception OrekitException if the zonal coefficients cannot be retrieved
  154.      * @exception PropagationException if the mean parameters cannot be computed
  155.      */
  156.     public EcksteinHechlerPropagator(final Orbit initialOrbit, final double mass,
  157.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  158.         throws PropagationException , OrekitException {
  159.         this(initialOrbit, DEFAULT_LAW, mass, provider, provider.onDate(initialOrbit.getDate()));
  160.     }

  161.     /** Build a propagator from orbit, mass and potential.
  162.      * <p>Attitude law is set to an unspecified non-null arbitrary value.</p>
  163.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  164.      * are related to both the normalized coefficients
  165.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  166.      *  and the J<sub>n</sub> one as follows:</p>
  167.      * <pre>
  168.      *   C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  169.      *                      <span style="text-decoration: overline">C</span><sub>n,0</sub>
  170.      *   C<sub>n,0</sub> = -J<sub>n</sub>
  171.      * </pre>
  172.      * @param initialOrbit initial orbit
  173.      * @param mass spacecraft mass
  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 c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  181.      * @exception PropagationException if the mean parameters cannot be computed
  182.      */
  183.     public EcksteinHechlerPropagator(final Orbit initialOrbit, final double mass,
  184.                                      final double referenceRadius, final double mu,
  185.                                      final double c20, final double c30, final double c40,
  186.                                      final double c50, final double c60)
  187.         throws PropagationException {
  188.         this(initialOrbit, DEFAULT_LAW, mass, referenceRadius, mu, c20, c30, c40, c50, c60);
  189.     }

  190.     /** Build a propagator from orbit, attitude provider and potential provider.
  191.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  192.      * @param initialOrbit initial orbit
  193.      * @param attitudeProv attitude provider
  194.      * @param provider for un-normalized zonal coefficients
  195.      * @exception OrekitException if the zonal coefficients cannot be retrieved
  196.      * @exception PropagationException if the mean parameters cannot be computed
  197.      */
  198.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  199.                                      final AttitudeProvider attitudeProv,
  200.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  201.         throws PropagationException , OrekitException {
  202.         this(initialOrbit, attitudeProv, DEFAULT_MASS, provider,
  203.                 provider.onDate(initialOrbit.getDate()));
  204.     }

  205.     /** Build a propagator from orbit, attitude provider and potential.
  206.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  207.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  208.      * are related to both the normalized coefficients
  209.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  210.      *  and the J<sub>n</sub> one as follows:</p>
  211.      * <pre>
  212.      *   C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  213.      *                     <span style="text-decoration: overline">C</span><sub>n,0</sub>
  214.      *   C<sub>n,0</sub> = -J<sub>n</sub>
  215.      * </pre>
  216.      * @param initialOrbit initial orbit
  217.      * @param attitudeProv attitude provider
  218.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  219.      * @param mu central attraction coefficient (m³/s²)
  220.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  221.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  222.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  223.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  224.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  225.      * @exception PropagationException if the mean parameters cannot be computed
  226.      */
  227.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  228.                                      final AttitudeProvider attitudeProv,
  229.                                      final double referenceRadius, final double mu,
  230.                                      final double c20, final double c30, final double c40,
  231.                                      final double c50, final double c60)
  232.         throws PropagationException {
  233.         this(initialOrbit, attitudeProv, DEFAULT_MASS, referenceRadius, mu, c20, c30, c40, c50, c60);
  234.     }

  235.     /** Build a propagator from orbit, attitude provider, mass and potential provider.
  236.      * @param initialOrbit initial orbit
  237.      * @param attitudeProv attitude provider
  238.      * @param mass spacecraft mass
  239.      * @param provider for un-normalized zonal coefficients
  240.      * @exception OrekitException if the zonal coefficients cannot be retrieved
  241.      * @exception PropagationException if the mean parameters cannot be computed
  242.      */
  243.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  244.                                      final AttitudeProvider attitudeProv,
  245.                                      final double mass,
  246.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  247.         throws PropagationException , OrekitException {
  248.         this(initialOrbit, attitudeProv, mass, provider,
  249.                 provider.onDate(initialOrbit.getDate()));
  250.     }

  251.     /** Build a propagator from orbit, attitude provider, mass and potential.
  252.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  253.      * are related to both the normalized coefficients
  254.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  255.      *  and the J<sub>n</sub> one as follows:</p>
  256.      * <pre>
  257.      *   C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  258.      *                      <span style="text-decoration: overline">C</span><sub>n,0</sub>
  259.      *   C<sub>n,0</sub> = -J<sub>n</sub>
  260.      * </pre>
  261.      * @param initialOrbit initial orbit
  262.      * @param attitudeProv attitude provider
  263.      * @param mass spacecraft mass
  264.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  265.      * @param mu central attraction coefficient (m³/s²)
  266.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  267.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  268.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  269.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  270.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  271.      * @exception PropagationException if the mean parameters cannot be computed
  272.      */
  273.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  274.                                      final AttitudeProvider attitudeProv,
  275.                                      final double mass,
  276.                                      final double referenceRadius, final double mu,
  277.                                      final double c20, final double c30, final double c40,
  278.                                      final double c50, final double c60)
  279.         throws PropagationException {

  280.         super(attitudeProv);
  281.         this.mass = mass;

  282.         try {

  283.             // store model coefficients
  284.             this.referenceRadius = referenceRadius;
  285.             this.mu  = mu;
  286.             this.ck0 = new double[] {
  287.                 0.0, 0.0, c20, c30, c40, c50, c60
  288.             };

  289.             // compute mean parameters
  290.             // transform into circular adapted parameters used by the Eckstein-Hechler model
  291.             resetInitialState(new SpacecraftState(initialOrbit,
  292.                                                   attitudeProv.getAttitude(initialOrbit,
  293.                                                                            initialOrbit.getDate(),
  294.                                                                            initialOrbit.getFrame()),
  295.                                                   mass));

  296.         } catch (OrekitException oe) {
  297.             throw new PropagationException(oe);
  298.         }
  299.     }

  300.     /** {@inheritDoc} */
  301.     public void resetInitialState(final SpacecraftState state)
  302.         throws PropagationException {
  303.         super.resetInitialState(state);
  304.         this.mass = state.getMass();
  305.         computeMeanParameters((CircularOrbit) OrbitType.CIRCULAR.convertType(state.getOrbit()));
  306.     }

  307.     /** Compute mean parameters according to the Eckstein-Hechler analytical model.
  308.      * @param osculating osculating orbit
  309.      * @exception PropagationException if orbit goes outside of supported range
  310.      * (trajectory inside the Brillouin sphere, too eccentric, equatorial, critical
  311.      * inclination) or if convergence cannot be reached
  312.      */
  313.     private void computeMeanParameters(final CircularOrbit osculating)
  314.         throws PropagationException {

  315.         // sanity check
  316.         if (osculating.getA() < referenceRadius) {
  317.             throw new PropagationException(OrekitMessages.TRAJECTORY_INSIDE_BRILLOUIN_SPHERE,
  318.                                            osculating.getA());
  319.         }

  320.         // rough initialization of the mean parameters
  321.         EHModel current = new EHModel(osculating);

  322.         // threshold for each parameter
  323.         final double epsilon         = 1.0e-13;
  324.         final double thresholdA      = epsilon * (1 + FastMath.abs(current.mean.getA()));
  325.         final double thresholdE      = epsilon * (1 + current.mean.getE());
  326.         final double thresholdAngles = epsilon * FastMath.PI;

  327.         int i = 0;
  328.         while (i++ < 100) {

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

  331.             // adapted parameters residuals
  332.             final double deltaA      = osculating.getA()          - parameters[0].getValue();
  333.             final double deltaEx     = osculating.getCircularEx() - parameters[1].getValue();
  334.             final double deltaEy     = osculating.getCircularEy() - parameters[2].getValue();
  335.             final double deltaI      = osculating.getI()          - parameters[3].getValue();
  336.             final double deltaRAAN   = MathUtils.normalizeAngle(osculating.getRightAscensionOfAscendingNode() -
  337.                                                                 parameters[4].getValue(),
  338.                                                                 0.0);
  339.             final double deltaAlphaM = MathUtils.normalizeAngle(osculating.getAlphaM() - parameters[5].getValue(), 0.0);

  340.             // update mean parameters
  341.             current = new EHModel(new CircularOrbit(current.mean.getA()          + deltaA,
  342.                                                     current.mean.getCircularEx() + deltaEx,
  343.                                                     current.mean.getCircularEy() + deltaEy,
  344.                                                     current.mean.getI()          + deltaI,
  345.                                                     current.mean.getRightAscensionOfAscendingNode() + deltaRAAN,
  346.                                                     current.mean.getAlphaM()     + deltaAlphaM,
  347.                                                     PositionAngle.MEAN,
  348.                                                     current.mean.getFrame(),
  349.                                                     current.mean.getDate(), mu));

  350.             // check convergence
  351.             if ((FastMath.abs(deltaA)      < thresholdA) &&
  352.                 (FastMath.abs(deltaEx)     < thresholdE) &&
  353.                 (FastMath.abs(deltaEy)     < thresholdE) &&
  354.                 (FastMath.abs(deltaI)      < thresholdAngles) &&
  355.                 (FastMath.abs(deltaRAAN)   < thresholdAngles) &&
  356.                 (FastMath.abs(deltaAlphaM) < thresholdAngles)) {
  357.                 model = current;
  358.                 return;
  359.             }

  360.         }

  361.         throw new PropagationException(OrekitMessages.UNABLE_TO_COMPUTE_ECKSTEIN_HECHLER_MEAN_PARAMETERS, i);

  362.     }

  363.     /** {@inheritDoc} */
  364.     public CartesianOrbit propagateOrbit(final AbsoluteDate date)
  365.         throws PropagationException {
  366.         // compute Cartesian parameters, taking derivatives into account
  367.         // to make sure velocity and acceleration are consistent
  368.         return new CartesianOrbit(toCartesian(date, model.propagateParameters(date)),
  369.                                   model.mean.getFrame(), mu);
  370.     }

  371.     /** Local class for Eckstein-Hechler model, with fixed mean parameters. */
  372.     private class EHModel {

  373.         /** Mean orbit. */
  374.         private final CircularOrbit mean;

  375.         // CHECKSTYLE: stop JavadocVariable check

  376.         // preprocessed values
  377.         private final double xnotDot;
  378.         private final double rdpom;
  379.         private final double rdpomp;
  380.         private final double eps1;
  381.         private final double eps2;
  382.         private final double xim;
  383.         private final double ommD;
  384.         private final double rdl;
  385.         private final double aMD;

  386.         private final double kh;
  387.         private final double kl;

  388.         private final double ax1;
  389.         private final double ay1;
  390.         private final double as1;
  391.         private final double ac2;
  392.         private final double axy3;
  393.         private final double as3;
  394.         private final double ac4;
  395.         private final double as5;
  396.         private final double ac6;

  397.         private final double ex1;
  398.         private final double exx2;
  399.         private final double exy2;
  400.         private final double ex3;
  401.         private final double ex4;

  402.         private final double ey1;
  403.         private final double eyx2;
  404.         private final double eyy2;
  405.         private final double ey3;
  406.         private final double ey4;

  407.         private final double rx1;
  408.         private final double ry1;
  409.         private final double r2;
  410.         private final double r3;
  411.         private final double rl;

  412.         private final double iy1;
  413.         private final double ix1;
  414.         private final double i2;
  415.         private final double i3;
  416.         private final double ih;

  417.         private final double lx1;
  418.         private final double ly1;
  419.         private final double l2;
  420.         private final double l3;
  421.         private final double ll;

  422.         // CHECKSTYLE: resume JavadocVariable check

  423.         /** Create a model for specified mean orbit.
  424.          * @param mean mean orbit
  425.          * @exception PropagationException if mean orbit is not within model supported domain
  426.          */
  427.         public EHModel(final CircularOrbit mean) throws PropagationException {

  428.             this.mean = mean;

  429.             // preliminary processing
  430.             double q = referenceRadius / mean.getA();
  431.             double ql = q * q;
  432.             final double g2 = ck0[2] * ql;
  433.             ql *= q;
  434.             final double g3 = ck0[3] * ql;
  435.             ql *= q;
  436.             final double g4 = ck0[4] * ql;
  437.             ql *= q;
  438.             final double g5 = ck0[5] * ql;
  439.             ql *= q;
  440.             final double g6 = ck0[6] * ql;

  441.             final double cosI1 = FastMath.cos(mean.getI());
  442.             final double sinI1 = FastMath.sin(mean.getI());
  443.             final double sinI2 = sinI1 * sinI1;
  444.             final double sinI4 = sinI2 * sinI2;
  445.             final double sinI6 = sinI2 * sinI4;

  446.             if (sinI2 < 1.0e-10) {
  447.                 throw new PropagationException(OrekitMessages.ALMOST_EQUATORIAL_ORBIT,
  448.                                                FastMath.toDegrees(mean.getI()));
  449.             }

  450.             if (FastMath.abs(sinI2 - 4.0 / 5.0) < 1.0e-3) {
  451.                 throw new PropagationException(OrekitMessages.ALMOST_CRITICALLY_INCLINED_ORBIT,
  452.                                                FastMath.toDegrees(mean.getI()));
  453.             }

  454.             if (mean.getE() > 0.1) {
  455.                 // if 0.005 < e < 0.1 no error is triggered, but accuracy is poor
  456.                 throw new PropagationException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL,
  457.                                                mean.getE());
  458.             }

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

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

  463.             q = 3.0 / (32.0 * rdpom);
  464.             eps1 = q * g4 * sinI2 * (30.0 - 35.0 * sinI2) -
  465.                     175.0 * q * g6 * sinI2 * (1.0 - 3.0 * sinI2 + 2.0625 * sinI4);
  466.             q = 3.0 * sinI1 / (8.0 * rdpom);
  467.             eps2 = q * g3 * (4.0 - 5.0 * sinI2) - q * g5 * (10.0 - 35.0 * sinI2 + 26.25 * sinI4);

  468.             xim = mean.getI();
  469.             ommD = cosI1 * (1.50    * g2 - 2.25 * g2 * g2 * (2.5 - 19.0 / 6.0 * sinI2) +
  470.                             0.9375  * g4 * (7.0 * sinI2 - 4.0) +
  471.                             3.28125 * g6 * (2.0 - 9.0 * sinI2 + 8.25 * sinI4));

  472.             rdl = 1.0 - 1.50 * g2 * (3.0 - 4.0 * sinI2);
  473.             aMD = rdl +
  474.                     2.25 * g2 * g2 * (9.0 - 263.0 / 12.0 * sinI2 + 341.0 / 24.0 * sinI4) +
  475.                     15.0 / 16.0 * g4 * (8.0 - 31.0 * sinI2 + 24.5 * sinI4) +
  476.                     105.0 / 32.0 * g6 * (-10.0 / 3.0 + 25.0 * sinI2 - 48.75 * sinI4 + 27.5 * sinI6);

  477.             final double qq = -1.5 * g2 / rdl;
  478.             final double qA   = 0.75 * g2 * g2 * sinI2;
  479.             final double qB   = 0.25 * g4 * sinI2;
  480.             final double qC   = 105.0 / 16.0 * g6 * sinI2;
  481.             final double qD   = -0.75 * g3 * sinI1;
  482.             final double qE   = 3.75 * g5 * sinI1;
  483.             kh = 0.375 / rdpom;
  484.             kl = kh / sinI1;

  485.             ax1 = qq * (2.0 - 3.5 * sinI2);
  486.             ay1 = qq * (2.0 - 2.5 * sinI2);
  487.             as1 = qD * (4.0 - 5.0 * sinI2) +
  488.                   qE * (2.625 * sinI4 - 3.5 * sinI2 + 1.0);
  489.             ac2 = qq * sinI2 +
  490.                   qA * 7.0 * (2.0 - 3.0 * sinI2) +
  491.                   qB * (15.0 - 17.5 * sinI2) +
  492.                   qC * (3.0 * sinI2 - 1.0 - 33.0 / 16.0 * sinI4);
  493.             axy3 = qq * 3.5 * sinI2;
  494.             as3 = qD * 5.0 / 3.0 * sinI2 +
  495.                   qE * 7.0 / 6.0 * sinI2 * (1.0 - 1.125 * sinI2);
  496.             ac4 = qA * sinI2 +
  497.                   qB * 4.375 * sinI2 +
  498.                   qC * 0.75 * (1.1 * sinI4 - sinI2);

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

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

  501.             ex1 = qq * (1.0 - 1.25 * sinI2);
  502.             exx2 = qq * 0.5 * (3.0 - 5.0 * sinI2);
  503.             exy2 = qq * (2.0 - 1.5 * sinI2);
  504.             ex3 = qq * 7.0 / 12.0 * sinI2;
  505.             ex4 = qq * 17.0 / 8.0 * sinI2;

  506.             ey1 = qq * (1.0 - 1.75 * sinI2);
  507.             eyx2 = qq * (1.0 - 3.0 * sinI2);
  508.             eyy2 = qq * (2.0 * sinI2 - 1.5);
  509.             ey3 = qq * 7.0 / 12.0 * sinI2;
  510.             ey4 = qq * 17.0 / 8.0 * sinI2;

  511.             q  = -qq * cosI1;
  512.             rx1 =  3.5 * q;
  513.             ry1 = -2.5 * q;
  514.             r2 = -0.5 * q;
  515.             r3 =  7.0 / 6.0 * q;
  516.             rl = g3 * cosI1 * (4.0 - 15.0 * sinI2) -
  517.                  2.5 * g5 * cosI1 * (4.0 - 42.0 * sinI2 + 52.5 * sinI4);

  518.             q = 0.5 * qq * sinI1 * cosI1;
  519.             iy1 =  q;
  520.             ix1 = -q;
  521.             i2 =  q;
  522.             i3 =  q * 7.0 / 3.0;
  523.             ih = -g3 * cosI1 * (4.0 - 5.0 * sinI2) +
  524.                  2.5 * g5 * cosI1 * (4.0 - 14.0 * sinI2 + 10.5 * sinI4);

  525.             lx1 = qq * (7.0 - 77.0 / 8.0 * sinI2);
  526.             ly1 = qq * (55.0 / 8.0 * sinI2 - 7.50);
  527.             l2 = qq * (1.25 * sinI2 - 0.5);
  528.             l3 = qq * (77.0 / 24.0 * sinI2 - 7.0 / 6.0);
  529.             ll = g3 * (53.0 * sinI2 - 4.0 - 57.5 * sinI4) +
  530.                  2.5 * g5 * (4.0 - 96.0 * sinI2 + 269.5 * sinI4 - 183.75 * sinI6);

  531.         }

  532.         /** Extrapolate an orbit up to a specific target date.
  533.          * @param date target date for the orbit
  534.          * @return propagated parameters
  535.          * @exception PropagationException if some parameters are out of bounds
  536.          */
  537.         public DerivativeStructure[] propagateParameters(final AbsoluteDate date)
  538.             throws PropagationException {

  539.             // keplerian evolution
  540.             final DerivativeStructure dt =
  541.                     new DerivativeStructure(1, 2, 0, date.durationFrom(mean.getDate()));
  542.             final DerivativeStructure xnot = dt.multiply(xnotDot);

  543.             // secular effects

  544.             // eccentricity
  545.             final DerivativeStructure x   = xnot.multiply(rdpom + rdpomp);
  546.             final DerivativeStructure cx  = x.cos();
  547.             final DerivativeStructure sx  = x.sin();
  548.             final DerivativeStructure exm = cx.multiply(mean.getCircularEx()).
  549.                                             add(sx.multiply(eps2 - (1.0 - eps1) * mean.getCircularEy()));
  550.             final DerivativeStructure eym = sx.multiply((1.0 + eps1) * mean.getCircularEx()).
  551.                                             add(cx.multiply(mean.getCircularEy() - eps2)).
  552.                                             add(eps2);

  553.             // no secular effect on inclination

  554.             // right ascension of ascending node
  555.             final DerivativeStructure omm =
  556.                     new DerivativeStructure(1, 2,
  557.                                             MathUtils.normalizeAngle(mean.getRightAscensionOfAscendingNode() + ommD * xnot.getValue(),
  558.                                                                      FastMath.PI),
  559.                                             ommD * xnotDot,
  560.                                             0.0);

  561.             // latitude argument
  562.             final DerivativeStructure xlm =
  563.                     new DerivativeStructure(1, 2,
  564.                                             MathUtils.normalizeAngle(mean.getAlphaM() + aMD * xnot.getValue(), FastMath.PI),
  565.                                             aMD * xnotDot,
  566.                                             0.0);

  567.             // periodical terms
  568.             final DerivativeStructure cl1 = xlm.cos();
  569.             final DerivativeStructure sl1 = xlm.sin();
  570.             final DerivativeStructure cl2 = cl1.multiply(cl1).subtract(sl1.multiply(sl1));
  571.             final DerivativeStructure sl2 = cl1.multiply(sl1).add(sl1.multiply(cl1));
  572.             final DerivativeStructure cl3 = cl2.multiply(cl1).subtract(sl2.multiply(sl1));
  573.             final DerivativeStructure sl3 = cl2.multiply(sl1).add(sl2.multiply(cl1));
  574.             final DerivativeStructure cl4 = cl3.multiply(cl1).subtract(sl3.multiply(sl1));
  575.             final DerivativeStructure sl4 = cl3.multiply(sl1).add(sl3.multiply(cl1));
  576.             final DerivativeStructure cl5 = cl4.multiply(cl1).subtract(sl4.multiply(sl1));
  577.             final DerivativeStructure sl5 = cl4.multiply(sl1).add(sl4.multiply(cl1));
  578.             final DerivativeStructure cl6 = cl5.multiply(cl1).subtract(sl5.multiply(sl1));

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

  581.             final DerivativeStructure exmCl1 = exm.multiply(cl1);
  582.             final DerivativeStructure exmSl1 = exm.multiply(sl1);
  583.             final DerivativeStructure eymCl1 = eym.multiply(cl1);
  584.             final DerivativeStructure eymSl1 = eym.multiply(sl1);
  585.             final DerivativeStructure exmCl2 = exm.multiply(cl2);
  586.             final DerivativeStructure exmSl2 = exm.multiply(sl2);
  587.             final DerivativeStructure eymCl2 = eym.multiply(cl2);
  588.             final DerivativeStructure eymSl2 = eym.multiply(sl2);
  589.             final DerivativeStructure exmCl3 = exm.multiply(cl3);
  590.             final DerivativeStructure exmSl3 = exm.multiply(sl3);
  591.             final DerivativeStructure eymCl3 = eym.multiply(cl3);
  592.             final DerivativeStructure eymSl3 = eym.multiply(sl3);
  593.             final DerivativeStructure exmCl4 = exm.multiply(cl4);
  594.             final DerivativeStructure exmSl4 = exm.multiply(sl4);
  595.             final DerivativeStructure eymCl4 = eym.multiply(cl4);
  596.             final DerivativeStructure eymSl4 = eym.multiply(sl4);

  597.             // semi major axis
  598.             final DerivativeStructure rda = exmCl1.multiply(ax1).
  599.                                             add(eymSl1.multiply(ay1)).
  600.                                             add(sl1.multiply(as1)).
  601.                                             add(cl2.multiply(ac2)).
  602.                                             add(exmCl3.add(eymSl3).multiply(axy3)).
  603.                                             add(sl3.multiply(as3)).
  604.                                             add(cl4.multiply(ac4)).
  605.                                             add(sl5.multiply(as5)).
  606.                                             add(cl6.multiply(ac6));

  607.             // eccentricity
  608.             final DerivativeStructure rdex = cl1.multiply(ex1).
  609.                                              add(exmCl2.multiply(exx2)).
  610.                                              add(eymSl2.multiply(exy2)).
  611.                                              add(cl3.multiply(ex3)).
  612.                                              add(exmCl4.add(eymSl4).multiply(ex4));
  613.             final DerivativeStructure rdey = sl1.multiply(ey1).
  614.                                              add(exmSl2.multiply(eyx2)).
  615.                                              add(eymCl2.multiply(eyy2)).
  616.                                              add(sl3.multiply(ey3)).
  617.                                              add(exmSl4.subtract(eymCl4).multiply(ey4));

  618.             // ascending node
  619.             final DerivativeStructure rdom = exmSl1.multiply(rx1).
  620.                                              add(eymCl1.multiply(ry1)).
  621.                                              add(sl2.multiply(r2)).
  622.                                              add(eymCl3.subtract(exmSl3).multiply(r3)).
  623.                                              add(ql.multiply(rl));

  624.             // inclination
  625.             final DerivativeStructure rdxi = eymSl1.multiply(iy1).
  626.                                              add(exmCl1.multiply(ix1)).
  627.                                              add(cl2.multiply(i2)).
  628.                                              add(exmCl3.add(eymSl3).multiply(i3)).
  629.                                              add(qh.multiply(ih));

  630.             // latitude argument
  631.             final DerivativeStructure rdxl = exmSl1.multiply(lx1).
  632.                                              add(eymCl1.multiply(ly1)).
  633.                                              add(sl2.multiply(l2)).
  634.                                              add(exmSl3.subtract(eymCl3).multiply(l3)).
  635.                                              add(ql.multiply(ll));

  636.             // osculating parameters
  637.             return new DerivativeStructure[] {
  638.                 rda.add(1.0).multiply(mean.getA()),
  639.                 rdex.add(exm),
  640.                 rdey.add(eym),
  641.                 rdxi.add(xim),
  642.                 rdom.add(omm),
  643.                 rdxl.add(xlm)
  644.             };

  645.         }

  646.     }

  647.     /** Convert circular parameters <em>with derivatives</em> to Cartesian coordinates.
  648.      * @param date date of the orbital parameters
  649.      * @param parameters circular parameters (a, ex, ey, i, raan, alphaM)
  650.      * @return Cartesian coordinates consistent with values and derivatives
  651.      */
  652.     private TimeStampedPVCoordinates toCartesian(final AbsoluteDate date, final DerivativeStructure[] parameters) {

  653.         // evaluate coordinates in the orbit canonical reference frame
  654.         final DerivativeStructure cosOmega = parameters[4].cos();
  655.         final DerivativeStructure sinOmega = parameters[4].sin();
  656.         final DerivativeStructure cosI     = parameters[3].cos();
  657.         final DerivativeStructure sinI     = parameters[3].sin();
  658.         final DerivativeStructure alphaE   = meanToEccentric(parameters[5], parameters[1], parameters[2]);
  659.         final DerivativeStructure cosAE    = alphaE.cos();
  660.         final DerivativeStructure sinAE    = alphaE.sin();
  661.         final DerivativeStructure ex2      = parameters[1].multiply(parameters[1]);
  662.         final DerivativeStructure ey2      = parameters[2].multiply(parameters[2]);
  663.         final DerivativeStructure exy      = parameters[1].multiply(parameters[2]);
  664.         final DerivativeStructure q        = ex2.add(ey2).subtract(1).negate().sqrt();
  665.         final DerivativeStructure beta     = q.add(1).reciprocal();
  666.         final DerivativeStructure bx2      = beta.multiply(ex2);
  667.         final DerivativeStructure by2      = beta.multiply(ey2);
  668.         final DerivativeStructure bxy      = beta.multiply(exy);
  669.         final DerivativeStructure u        = bxy.multiply(sinAE).subtract(parameters[1].add(by2.subtract(1).multiply(cosAE)));
  670.         final DerivativeStructure v        = bxy.multiply(cosAE).subtract(parameters[2].add(bx2.subtract(1).multiply(sinAE)));
  671.         final DerivativeStructure x        = parameters[0].multiply(u);
  672.         final DerivativeStructure y        = parameters[0].multiply(v);

  673.         // canonical orbit reference frame
  674.         final FieldVector3D<DerivativeStructure> p =
  675.                 new FieldVector3D<DerivativeStructure>(x.multiply(cosOmega).subtract(y.multiply(cosI.multiply(sinOmega))),
  676.                                                        x.multiply(sinOmega).add(y.multiply(cosI.multiply(cosOmega))),
  677.                                                        y.multiply(sinI));

  678.         // dispatch derivatives
  679.         final Vector3D p0 = new Vector3D(p.getX().getValue(),
  680.                                          p.getY().getValue(),
  681.                                          p.getZ().getValue());
  682.         final Vector3D p1 = new Vector3D(p.getX().getPartialDerivative(1),
  683.                                          p.getY().getPartialDerivative(1),
  684.                                          p.getZ().getPartialDerivative(1));
  685.         final Vector3D p2 = new Vector3D(p.getX().getPartialDerivative(2),
  686.                                          p.getY().getPartialDerivative(2),
  687.                                          p.getZ().getPartialDerivative(2));
  688.         return new TimeStampedPVCoordinates(date, p0, p1, p2);

  689.     }

  690.     /** Computes the eccentric latitude argument from the mean latitude argument.
  691.      * @param alphaM = M + Ω mean latitude argument (rad)
  692.      * @param ex e cos(Ω), first component of circular eccentricity vector
  693.      * @param ey e sin(Ω), second component of circular eccentricity vector
  694.      * @return the eccentric latitude argument.
  695.      */
  696.     private DerivativeStructure meanToEccentric(final DerivativeStructure alphaM,
  697.                                                 final DerivativeStructure ex,
  698.                                                 final DerivativeStructure ey) {
  699.         // Generalization of Kepler equation to circular parameters
  700.         // with alphaE = PA + E and
  701.         //      alphaM = PA + M = alphaE - ex.sin(alphaE) + ey.cos(alphaE)
  702.         DerivativeStructure alphaE        = alphaM;
  703.         DerivativeStructure shift         = alphaM.getField().getZero();
  704.         DerivativeStructure alphaEMalphaM = alphaM.getField().getZero();
  705.         DerivativeStructure cosAlphaE     = alphaE.cos();
  706.         DerivativeStructure sinAlphaE     = alphaE.sin();
  707.         int    iter          = 0;
  708.         do {
  709.             final DerivativeStructure f2 = ex.multiply(sinAlphaE).subtract(ey.multiply(cosAlphaE));
  710.             final DerivativeStructure f1 = alphaM.getField().getOne().subtract(ex.multiply(cosAlphaE)).subtract(ey.multiply(sinAlphaE));
  711.             final DerivativeStructure f0 = alphaEMalphaM.subtract(f2);

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

  714.             alphaEMalphaM  = alphaEMalphaM.subtract(shift);
  715.             alphaE         = alphaM.add(alphaEMalphaM);
  716.             cosAlphaE      = alphaE.cos();
  717.             sinAlphaE      = alphaE.sin();

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

  719.         return alphaE;

  720.     }

  721.     /** {@inheritDoc} */
  722.     protected double getMass(final AbsoluteDate date) {
  723.         return mass;
  724.     }

  725. }