EcksteinHechlerPropagator.java

  1. /* Copyright 2002-2018 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 java.io.NotSerializableException;
  19. import java.io.Serializable;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import java.util.SortedSet;

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

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

  82.     /** Serializable UID. */
  83.     private static final long serialVersionUID = 20151202L;

  84.     /** Initial Eckstein-Hechler model. */
  85.     private EHModel initialModel;

  86.     /** All models. */
  87.     private transient TimeSpanMap<EHModel> models;

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

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

  92.     /** Un-normalized zonal coefficients. */
  93.     private double[] ck0;

  94.     /** Build a propagator from orbit and potential provider.
  95.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  96.      * @param initialOrbit initial orbit
  97.      * @param provider for un-normalized zonal coefficients
  98.      * @exception OrekitException if the zonal coefficients cannot be retrieved or
  99.      * if the mean parameters cannot be computed
  100.      */
  101.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  102.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  103.         throws OrekitException {
  104.         this(initialOrbit, DEFAULT_LAW, DEFAULT_MASS, provider,
  105.              provider.onDate(initialOrbit.getDate()));
  106.     }

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

  129.     /** Build a propagator from orbit and potential.
  130.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  131.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  132.      * are related to both the normalized coefficients
  133.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  134.      *  and the J<sub>n</sub> one as follows:</p>
  135.      *
  136.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  137.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  138.      *
  139.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  140.      *
  141.      * @param initialOrbit initial orbit
  142.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  143.      * @param mu central attraction coefficient (m³/s²)
  144.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  145.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  146.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  147.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  148.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  149.      * @exception OrekitException if the mean parameters cannot be computed
  150.      * @see org.orekit.utils.Constants
  151.      */
  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.         throws OrekitException {
  157.         this(initialOrbit, DEFAULT_LAW, 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.      * @param initialOrbit initial orbit
  162.      * @param mass spacecraft mass
  163.      * @param provider for un-normalized zonal coefficients
  164.      * @exception OrekitException if the zonal coefficients cannot be retrieved or
  165.      * if the mean parameters cannot be computed
  166.      */
  167.     public EcksteinHechlerPropagator(final Orbit initialOrbit, final double mass,
  168.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  169.         throws OrekitException {
  170.         this(initialOrbit, DEFAULT_LAW, mass, provider, provider.onDate(initialOrbit.getDate()));
  171.     }

  172.     /** Build a propagator from orbit, mass and potential.
  173.      * <p>Attitude law is set to an unspecified non-null arbitrary value.</p>
  174.      * <p>The C<sub>n,0</sub> coefficients are the denormalized zonal coefficients, they
  175.      * are related to both the normalized coefficients
  176.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  177.      *  and the J<sub>n</sub> one as follows:</p>
  178.      *
  179.      * <p> C<sub>n,0</sub> = [(2-δ<sub>0,m</sub>)(2n+1)(n-m)!/(n+m)!]<sup>½</sup>
  180.      * <span style="text-decoration: overline">C</span><sub>n,0</sub>
  181.      *
  182.      * <p> C<sub>n,0</sub> = -J<sub>n</sub>
  183.      *
  184.      * @param initialOrbit initial orbit
  185.      * @param mass spacecraft mass
  186.      * @param referenceRadius reference radius of the Earth for the potential model (m)
  187.      * @param mu central attraction coefficient (m³/s²)
  188.      * @param c20 un-normalized zonal coefficient (about -1.08e-3 for Earth)
  189.      * @param c30 un-normalized zonal coefficient (about +2.53e-6 for Earth)
  190.      * @param c40 un-normalized zonal coefficient (about +1.62e-6 for Earth)
  191.      * @param c50 un-normalized zonal coefficient (about +2.28e-7 for Earth)
  192.      * @param c60 un-normalized zonal coefficient (about -5.41e-7 for Earth)
  193.      * @exception OrekitException if the mean parameters cannot be computed
  194.      */
  195.     public EcksteinHechlerPropagator(final Orbit initialOrbit, final double mass,
  196.                                      final double referenceRadius, final double mu,
  197.                                      final double c20, final double c30, final double c40,
  198.                                      final double c50, final double c60)
  199.         throws OrekitException {
  200.         this(initialOrbit, DEFAULT_LAW, mass, referenceRadius, mu, c20, c30, c40, c50, c60);
  201.     }

  202.     /** Build a propagator from orbit, attitude provider and potential provider.
  203.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  204.      * @param initialOrbit initial orbit
  205.      * @param attitudeProv attitude provider
  206.      * @param provider for un-normalized zonal coefficients
  207.      * @exception OrekitException if the zonal coefficients cannot be retrieved or
  208.      * if the mean parameters cannot be computed
  209.      */
  210.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  211.                                      final AttitudeProvider attitudeProv,
  212.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  213.         throws OrekitException {
  214.         this(initialOrbit, attitudeProv, DEFAULT_MASS, provider, provider.onDate(initialOrbit.getDate()));
  215.     }

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

  247.     /** Build a propagator from orbit, attitude provider, mass and potential provider.
  248.      * @param initialOrbit initial orbit
  249.      * @param attitudeProv attitude provider
  250.      * @param mass spacecraft mass
  251.      * @param provider for un-normalized zonal coefficients
  252.      * @exception OrekitException if the zonal coefficients cannot be retrieved or
  253.      * if the mean parameters cannot be computed
  254.      */
  255.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  256.                                      final AttitudeProvider attitudeProv,
  257.                                      final double mass,
  258.                                      final UnnormalizedSphericalHarmonicsProvider provider)
  259.         throws OrekitException {
  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.      * @exception OrekitException if the mean parameters cannot be computed
  284.      */
  285.     public EcksteinHechlerPropagator(final Orbit initialOrbit,
  286.                                      final AttitudeProvider attitudeProv,
  287.                                      final double mass,
  288.                                      final double referenceRadius, final double mu,
  289.                                      final double c20, final double c30, final double c40,
  290.                                      final double c50, final double c60)
  291.         throws OrekitException {

  292.         super(attitudeProv);

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

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

  306.     }

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

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

  326.     /** Compute mean parameters according to the Eckstein-Hechler analytical model.
  327.      * @param osculating osculating orbit
  328.      * @param mass constant mass
  329.      * @return Eckstein-Hechler mean model
  330.      * @exception OrekitException if orbit goes outside of supported range
  331.      * (trajectory inside the Brillouin sphere, too eccentric, equatorial, critical
  332.      * inclination) or if convergence cannot be reached
  333.      */
  334.     private EHModel computeMeanParameters(final CircularOrbit osculating, final double mass)
  335.         throws OrekitException {

  336.         // sanity check
  337.         if (osculating.getA() < referenceRadius) {
  338.             throw new OrekitException(OrekitMessages.TRAJECTORY_INSIDE_BRILLOUIN_SPHERE,
  339.                                            osculating.getA());
  340.         }

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

  343.         // threshold for each parameter
  344.         final double epsilon         = 1.0e-13;
  345.         final double thresholdA      = epsilon * (1 + FastMath.abs(current.mean.getA()));
  346.         final double thresholdE      = epsilon * (1 + current.mean.getE());
  347.         final double thresholdAngles = epsilon * FastMath.PI;

  348.         int i = 0;
  349.         while (i++ < 100) {

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

  352.             // adapted parameters residuals
  353.             final double deltaA      = osculating.getA()          - parameters[0].getValue();
  354.             final double deltaEx     = osculating.getCircularEx() - parameters[1].getValue();
  355.             final double deltaEy     = osculating.getCircularEy() - parameters[2].getValue();
  356.             final double deltaI      = osculating.getI()          - parameters[3].getValue();
  357.             final double deltaRAAN   = MathUtils.normalizeAngle(osculating.getRightAscensionOfAscendingNode() -
  358.                                                                 parameters[4].getValue(),
  359.                                                                 0.0);
  360.             final double deltaAlphaM = MathUtils.normalizeAngle(osculating.getAlphaM() - parameters[5].getValue(), 0.0);

  361.             // update mean parameters
  362.             current = new EHModel(new CircularOrbit(current.mean.getA()          + deltaA,
  363.                                                     current.mean.getCircularEx() + deltaEx,
  364.                                                     current.mean.getCircularEy() + deltaEy,
  365.                                                     current.mean.getI()          + deltaI,
  366.                                                     current.mean.getRightAscensionOfAscendingNode() + deltaRAAN,
  367.                                                     current.mean.getAlphaM()     + deltaAlphaM,
  368.                                                     PositionAngle.MEAN,
  369.                                                     current.mean.getFrame(),
  370.                                                     current.mean.getDate(), mu),
  371.                                   mass, referenceRadius, mu, ck0);

  372.             // check convergence
  373.             if ((FastMath.abs(deltaA)      < thresholdA) &&
  374.                 (FastMath.abs(deltaEx)     < thresholdE) &&
  375.                 (FastMath.abs(deltaEy)     < thresholdE) &&
  376.                 (FastMath.abs(deltaI)      < thresholdAngles) &&
  377.                 (FastMath.abs(deltaRAAN)   < thresholdAngles) &&
  378.                 (FastMath.abs(deltaAlphaM) < thresholdAngles)) {
  379.                 return current;
  380.             }

  381.         }

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

  383.     }

  384.     /** {@inheritDoc} */
  385.     public CartesianOrbit propagateOrbit(final AbsoluteDate date)
  386.         throws OrekitException {
  387.         // compute Cartesian parameters, taking derivatives into account
  388.         // to make sure velocity and acceleration are consistent
  389.         final EHModel current = models.get(date);
  390.         return new CartesianOrbit(toCartesian(date, current.propagateParameters(date)),
  391.                                   current.mean.getFrame(), mu);
  392.     }

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

  395.         /** Serializable UID. */
  396.         private static final long serialVersionUID = 20160115L;

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

  399.         /** Mean orbit. */
  400.         private final CircularOrbit mean;

  401.         /** Constant mass. */
  402.         private final double mass;

  403.         // CHECKSTYLE: stop JavadocVariable check

  404.         // preprocessed values
  405.         private final double xnotDot;
  406.         private final double rdpom;
  407.         private final double rdpomp;
  408.         private final double eps1;
  409.         private final double eps2;
  410.         private final double xim;
  411.         private final double ommD;
  412.         private final double rdl;
  413.         private final double aMD;

  414.         private final double kh;
  415.         private final double kl;

  416.         private final double ax1;
  417.         private final double ay1;
  418.         private final double as1;
  419.         private final double ac2;
  420.         private final double axy3;
  421.         private final double as3;
  422.         private final double ac4;
  423.         private final double as5;
  424.         private final double ac6;

  425.         private final double ex1;
  426.         private final double exx2;
  427.         private final double exy2;
  428.         private final double ex3;
  429.         private final double ex4;

  430.         private final double ey1;
  431.         private final double eyx2;
  432.         private final double eyy2;
  433.         private final double ey3;
  434.         private final double ey4;

  435.         private final double rx1;
  436.         private final double ry1;
  437.         private final double r2;
  438.         private final double r3;
  439.         private final double rl;

  440.         private final double iy1;
  441.         private final double ix1;
  442.         private final double i2;
  443.         private final double i3;
  444.         private final double ih;

  445.         private final double lx1;
  446.         private final double ly1;
  447.         private final double l2;
  448.         private final double l3;
  449.         private final double ll;

  450.         // CHECKSTYLE: resume JavadocVariable check

  451.         /** Create a model for specified mean orbit.
  452.          * @param mean mean orbit
  453.          * @param mass constant mass
  454.          * @param referenceRadius reference radius of the central body attraction model (m)
  455.          * @param mu central attraction coefficient (m³/s²)
  456.          * @param ck0 un-normalized zonal coefficients
  457.          * @exception OrekitException if mean orbit is not within model supported domain
  458.          */
  459.         EHModel(final CircularOrbit mean, final double mass,
  460.                 final double referenceRadius, final double mu, final double[] ck0)
  461.             throws OrekitException {

  462.             this.mean            = mean;
  463.             this.mass            = mass;

  464.             // preliminary processing
  465.             double q = referenceRadius / mean.getA();
  466.             double ql = q * q;
  467.             final double g2 = ck0[2] * ql;
  468.             ql *= q;
  469.             final double g3 = ck0[3] * ql;
  470.             ql *= q;
  471.             final double g4 = ck0[4] * ql;
  472.             ql *= q;
  473.             final double g5 = ck0[5] * ql;
  474.             ql *= q;
  475.             final double g6 = ck0[6] * ql;

  476.             final double cosI1 = FastMath.cos(mean.getI());
  477.             final double sinI1 = FastMath.sin(mean.getI());
  478.             final double sinI2 = sinI1 * sinI1;
  479.             final double sinI4 = sinI2 * sinI2;
  480.             final double sinI6 = sinI2 * sinI4;

  481.             if (sinI2 < 1.0e-10) {
  482.                 throw new OrekitException(OrekitMessages.ALMOST_EQUATORIAL_ORBIT,
  483.                                           FastMath.toDegrees(mean.getI()));
  484.             }

  485.             if (FastMath.abs(sinI2 - 4.0 / 5.0) < 1.0e-3) {
  486.                 throw new OrekitException(OrekitMessages.ALMOST_CRITICALLY_INCLINED_ORBIT,
  487.                                           FastMath.toDegrees(mean.getI()));
  488.             }

  489.             if (mean.getE() > 0.1) {
  490.                 // if 0.005 < e < 0.1 no error is triggered, but accuracy is poor
  491.                 throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL,
  492.                                           mean.getE());
  493.             }

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

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

  498.             q = 3.0 / (32.0 * rdpom);
  499.             eps1 = q * g4 * sinI2 * (30.0 - 35.0 * sinI2) -
  500.                     175.0 * q * g6 * sinI2 * (1.0 - 3.0 * sinI2 + 2.0625 * sinI4);
  501.             q = 3.0 * sinI1 / (8.0 * rdpom);
  502.             eps2 = q * g3 * (4.0 - 5.0 * sinI2) - q * g5 * (10.0 - 35.0 * sinI2 + 26.25 * sinI4);

  503.             xim = mean.getI();
  504.             ommD = cosI1 * (1.50    * g2 - 2.25 * g2 * g2 * (2.5 - 19.0 / 6.0 * sinI2) +
  505.                             0.9375  * g4 * (7.0 * sinI2 - 4.0) +
  506.                             3.28125 * g6 * (2.0 - 9.0 * sinI2 + 8.25 * sinI4));

  507.             rdl = 1.0 - 1.50 * g2 * (3.0 - 4.0 * sinI2);
  508.             aMD = rdl +
  509.                     2.25 * g2 * g2 * (9.0 - 263.0 / 12.0 * sinI2 + 341.0 / 24.0 * sinI4) +
  510.                     15.0 / 16.0 * g4 * (8.0 - 31.0 * sinI2 + 24.5 * sinI4) +
  511.                     105.0 / 32.0 * g6 * (-10.0 / 3.0 + 25.0 * sinI2 - 48.75 * sinI4 + 27.5 * sinI6);

  512.             final double qq = -1.5 * g2 / rdl;
  513.             final double qA   = 0.75 * g2 * g2 * sinI2;
  514.             final double qB   = 0.25 * g4 * sinI2;
  515.             final double qC   = 105.0 / 16.0 * g6 * sinI2;
  516.             final double qD   = -0.75 * g3 * sinI1;
  517.             final double qE   = 3.75 * g5 * sinI1;
  518.             kh = 0.375 / rdpom;
  519.             kl = kh / sinI1;

  520.             ax1 = qq * (2.0 - 3.5 * sinI2);
  521.             ay1 = qq * (2.0 - 2.5 * sinI2);
  522.             as1 = qD * (4.0 - 5.0 * sinI2) +
  523.                   qE * (2.625 * sinI4 - 3.5 * sinI2 + 1.0);
  524.             ac2 = qq * sinI2 +
  525.                   qA * 7.0 * (2.0 - 3.0 * sinI2) +
  526.                   qB * (15.0 - 17.5 * sinI2) +
  527.                   qC * (3.0 * sinI2 - 1.0 - 33.0 / 16.0 * sinI4);
  528.             axy3 = qq * 3.5 * sinI2;
  529.             as3 = qD * 5.0 / 3.0 * sinI2 +
  530.                   qE * 7.0 / 6.0 * sinI2 * (1.0 - 1.125 * sinI2);
  531.             ac4 = qA * sinI2 +
  532.                   qB * 4.375 * sinI2 +
  533.                   qC * 0.75 * (1.1 * sinI4 - sinI2);

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

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

  536.             ex1 = qq * (1.0 - 1.25 * sinI2);
  537.             exx2 = qq * 0.5 * (3.0 - 5.0 * sinI2);
  538.             exy2 = qq * (2.0 - 1.5 * sinI2);
  539.             ex3 = qq * 7.0 / 12.0 * sinI2;
  540.             ex4 = qq * 17.0 / 8.0 * sinI2;

  541.             ey1 = qq * (1.0 - 1.75 * sinI2);
  542.             eyx2 = qq * (1.0 - 3.0 * sinI2);
  543.             eyy2 = qq * (2.0 * sinI2 - 1.5);
  544.             ey3 = qq * 7.0 / 12.0 * sinI2;
  545.             ey4 = qq * 17.0 / 8.0 * sinI2;

  546.             q  = -qq * cosI1;
  547.             rx1 =  3.5 * q;
  548.             ry1 = -2.5 * q;
  549.             r2 = -0.5 * q;
  550.             r3 =  7.0 / 6.0 * q;
  551.             rl = g3 * cosI1 * (4.0 - 15.0 * sinI2) -
  552.                  2.5 * g5 * cosI1 * (4.0 - 42.0 * sinI2 + 52.5 * sinI4);

  553.             q = 0.5 * qq * sinI1 * cosI1;
  554.             iy1 =  q;
  555.             ix1 = -q;
  556.             i2 =  q;
  557.             i3 =  q * 7.0 / 3.0;
  558.             ih = -g3 * cosI1 * (4.0 - 5.0 * sinI2) +
  559.                  2.5 * g5 * cosI1 * (4.0 - 14.0 * sinI2 + 10.5 * sinI4);

  560.             lx1 = qq * (7.0 - 77.0 / 8.0 * sinI2);
  561.             ly1 = qq * (55.0 / 8.0 * sinI2 - 7.50);
  562.             l2 = qq * (1.25 * sinI2 - 0.5);
  563.             l3 = qq * (77.0 / 24.0 * sinI2 - 7.0 / 6.0);
  564.             ll = g3 * (53.0 * sinI2 - 4.0 - 57.5 * sinI4) +
  565.                  2.5 * g5 * (4.0 - 96.0 * sinI2 + 269.5 * sinI4 - 183.75 * sinI6);

  566.         }

  567.         /** Extrapolate an orbit up to a specific target date.
  568.          * @param date target date for the orbit
  569.          * @return propagated parameters
  570.          * @exception OrekitException if some parameters are out of bounds
  571.          */
  572.         public DerivativeStructure[] propagateParameters(final AbsoluteDate date)
  573.             throws OrekitException {

  574.             // Keplerian evolution
  575.             final DerivativeStructure dt = FACTORY.variable(0, date.durationFrom(mean.getDate()));
  576.             final DerivativeStructure xnot = dt.multiply(xnotDot);

  577.             // secular effects

  578.             // eccentricity
  579.             final DerivativeStructure x   = xnot.multiply(rdpom + rdpomp);
  580.             final DerivativeStructure cx  = x.cos();
  581.             final DerivativeStructure sx  = x.sin();
  582.             final DerivativeStructure exm = cx.multiply(mean.getCircularEx()).
  583.                                             add(sx.multiply(eps2 - (1.0 - eps1) * mean.getCircularEy()));
  584.             final DerivativeStructure eym = sx.multiply((1.0 + eps1) * mean.getCircularEx()).
  585.                                             add(cx.multiply(mean.getCircularEy() - eps2)).
  586.                                             add(eps2);

  587.             // no secular effect on inclination

  588.             // right ascension of ascending node
  589.             final DerivativeStructure omm =
  590.                             FACTORY.build(MathUtils.normalizeAngle(mean.getRightAscensionOfAscendingNode() + ommD * xnot.getValue(),
  591.                                                            FastMath.PI),
  592.                                   ommD * xnotDot,
  593.                                   0.0);

  594.             // latitude argument
  595.             final DerivativeStructure xlm =
  596.                             FACTORY.build(MathUtils.normalizeAngle(mean.getAlphaM() + aMD * xnot.getValue(), FastMath.PI),
  597.                                   aMD * xnotDot,
  598.                                   0.0);

  599.             // periodical terms
  600.             final DerivativeStructure cl1 = xlm.cos();
  601.             final DerivativeStructure sl1 = xlm.sin();
  602.             final DerivativeStructure cl2 = cl1.multiply(cl1).subtract(sl1.multiply(sl1));
  603.             final DerivativeStructure sl2 = cl1.multiply(sl1).add(sl1.multiply(cl1));
  604.             final DerivativeStructure cl3 = cl2.multiply(cl1).subtract(sl2.multiply(sl1));
  605.             final DerivativeStructure sl3 = cl2.multiply(sl1).add(sl2.multiply(cl1));
  606.             final DerivativeStructure cl4 = cl3.multiply(cl1).subtract(sl3.multiply(sl1));
  607.             final DerivativeStructure sl4 = cl3.multiply(sl1).add(sl3.multiply(cl1));
  608.             final DerivativeStructure cl5 = cl4.multiply(cl1).subtract(sl4.multiply(sl1));
  609.             final DerivativeStructure sl5 = cl4.multiply(sl1).add(sl4.multiply(cl1));
  610.             final DerivativeStructure cl6 = cl5.multiply(cl1).subtract(sl5.multiply(sl1));

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

  613.             final DerivativeStructure exmCl1 = exm.multiply(cl1);
  614.             final DerivativeStructure exmSl1 = exm.multiply(sl1);
  615.             final DerivativeStructure eymCl1 = eym.multiply(cl1);
  616.             final DerivativeStructure eymSl1 = eym.multiply(sl1);
  617.             final DerivativeStructure exmCl2 = exm.multiply(cl2);
  618.             final DerivativeStructure exmSl2 = exm.multiply(sl2);
  619.             final DerivativeStructure eymCl2 = eym.multiply(cl2);
  620.             final DerivativeStructure eymSl2 = eym.multiply(sl2);
  621.             final DerivativeStructure exmCl3 = exm.multiply(cl3);
  622.             final DerivativeStructure exmSl3 = exm.multiply(sl3);
  623.             final DerivativeStructure eymCl3 = eym.multiply(cl3);
  624.             final DerivativeStructure eymSl3 = eym.multiply(sl3);
  625.             final DerivativeStructure exmCl4 = exm.multiply(cl4);
  626.             final DerivativeStructure exmSl4 = exm.multiply(sl4);
  627.             final DerivativeStructure eymCl4 = eym.multiply(cl4);
  628.             final DerivativeStructure eymSl4 = eym.multiply(sl4);

  629.             // semi major axis
  630.             final DerivativeStructure rda = exmCl1.multiply(ax1).
  631.                                             add(eymSl1.multiply(ay1)).
  632.                                             add(sl1.multiply(as1)).
  633.                                             add(cl2.multiply(ac2)).
  634.                                             add(exmCl3.add(eymSl3).multiply(axy3)).
  635.                                             add(sl3.multiply(as3)).
  636.                                             add(cl4.multiply(ac4)).
  637.                                             add(sl5.multiply(as5)).
  638.                                             add(cl6.multiply(ac6));

  639.             // eccentricity
  640.             final DerivativeStructure rdex = cl1.multiply(ex1).
  641.                                              add(exmCl2.multiply(exx2)).
  642.                                              add(eymSl2.multiply(exy2)).
  643.                                              add(cl3.multiply(ex3)).
  644.                                              add(exmCl4.add(eymSl4).multiply(ex4));
  645.             final DerivativeStructure rdey = sl1.multiply(ey1).
  646.                                              add(exmSl2.multiply(eyx2)).
  647.                                              add(eymCl2.multiply(eyy2)).
  648.                                              add(sl3.multiply(ey3)).
  649.                                              add(exmSl4.subtract(eymCl4).multiply(ey4));

  650.             // ascending node
  651.             final DerivativeStructure rdom = exmSl1.multiply(rx1).
  652.                                              add(eymCl1.multiply(ry1)).
  653.                                              add(sl2.multiply(r2)).
  654.                                              add(eymCl3.subtract(exmSl3).multiply(r3)).
  655.                                              add(ql.multiply(rl));

  656.             // inclination
  657.             final DerivativeStructure rdxi = eymSl1.multiply(iy1).
  658.                                              add(exmCl1.multiply(ix1)).
  659.                                              add(cl2.multiply(i2)).
  660.                                              add(exmCl3.add(eymSl3).multiply(i3)).
  661.                                              add(qh.multiply(ih));

  662.             // latitude argument
  663.             final DerivativeStructure rdxl = exmSl1.multiply(lx1).
  664.                                              add(eymCl1.multiply(ly1)).
  665.                                              add(sl2.multiply(l2)).
  666.                                              add(exmSl3.subtract(eymCl3).multiply(l3)).
  667.                                              add(ql.multiply(ll));

  668.             // osculating parameters
  669.             return new DerivativeStructure[] {
  670.                 rda.add(1.0).multiply(mean.getA()),
  671.                 rdex.add(exm),
  672.                 rdey.add(eym),
  673.                 rdxi.add(xim),
  674.                 rdom.add(omm),
  675.                 rdxl.add(xlm)
  676.             };

  677.         }

  678.     }

  679.     /** Convert circular parameters <em>with derivatives</em> to Cartesian coordinates.
  680.      * @param date date of the orbital parameters
  681.      * @param parameters circular parameters (a, ex, ey, i, raan, alphaM)
  682.      * @return Cartesian coordinates consistent with values and derivatives
  683.      */
  684.     private TimeStampedPVCoordinates toCartesian(final AbsoluteDate date, final DerivativeStructure[] parameters) {

  685.         // evaluate coordinates in the orbit canonical reference frame
  686.         final DerivativeStructure cosOmega = parameters[4].cos();
  687.         final DerivativeStructure sinOmega = parameters[4].sin();
  688.         final DerivativeStructure cosI     = parameters[3].cos();
  689.         final DerivativeStructure sinI     = parameters[3].sin();
  690.         final DerivativeStructure alphaE   = meanToEccentric(parameters[5], parameters[1], parameters[2]);
  691.         final DerivativeStructure cosAE    = alphaE.cos();
  692.         final DerivativeStructure sinAE    = alphaE.sin();
  693.         final DerivativeStructure ex2      = parameters[1].multiply(parameters[1]);
  694.         final DerivativeStructure ey2      = parameters[2].multiply(parameters[2]);
  695.         final DerivativeStructure exy      = parameters[1].multiply(parameters[2]);
  696.         final DerivativeStructure q        = ex2.add(ey2).subtract(1).negate().sqrt();
  697.         final DerivativeStructure beta     = q.add(1).reciprocal();
  698.         final DerivativeStructure bx2      = beta.multiply(ex2);
  699.         final DerivativeStructure by2      = beta.multiply(ey2);
  700.         final DerivativeStructure bxy      = beta.multiply(exy);
  701.         final DerivativeStructure u        = bxy.multiply(sinAE).subtract(parameters[1].add(by2.subtract(1).multiply(cosAE)));
  702.         final DerivativeStructure v        = bxy.multiply(cosAE).subtract(parameters[2].add(bx2.subtract(1).multiply(sinAE)));
  703.         final DerivativeStructure x        = parameters[0].multiply(u);
  704.         final DerivativeStructure y        = parameters[0].multiply(v);

  705.         // canonical orbit reference frame
  706.         final FieldVector3D<DerivativeStructure> p =
  707.                 new FieldVector3D<>(x.multiply(cosOmega).subtract(y.multiply(cosI.multiply(sinOmega))),
  708.                                     x.multiply(sinOmega).add(y.multiply(cosI.multiply(cosOmega))),
  709.                                     y.multiply(sinI));

  710.         // dispatch derivatives
  711.         final Vector3D p0 = new Vector3D(p.getX().getValue(),
  712.                                          p.getY().getValue(),
  713.                                          p.getZ().getValue());
  714.         final Vector3D p1 = new Vector3D(p.getX().getPartialDerivative(1),
  715.                                          p.getY().getPartialDerivative(1),
  716.                                          p.getZ().getPartialDerivative(1));
  717.         final Vector3D p2 = new Vector3D(p.getX().getPartialDerivative(2),
  718.                                          p.getY().getPartialDerivative(2),
  719.                                          p.getZ().getPartialDerivative(2));
  720.         return new TimeStampedPVCoordinates(date, p0, p1, p2);

  721.     }

  722.     /** Computes the eccentric latitude argument from the mean latitude argument.
  723.      * @param alphaM = M + Ω mean latitude argument (rad)
  724.      * @param ex e cos(Ω), first component of circular eccentricity vector
  725.      * @param ey e sin(Ω), second component of circular eccentricity vector
  726.      * @return the eccentric latitude argument.
  727.      */
  728.     private DerivativeStructure meanToEccentric(final DerivativeStructure alphaM,
  729.                                                 final DerivativeStructure ex,
  730.                                                 final DerivativeStructure ey) {
  731.         // Generalization of Kepler equation to circular parameters
  732.         // with alphaE = PA + E and
  733.         //      alphaM = PA + M = alphaE - ex.sin(alphaE) + ey.cos(alphaE)
  734.         DerivativeStructure alphaE        = alphaM;
  735.         DerivativeStructure shift         = alphaM.getField().getZero();
  736.         DerivativeStructure alphaEMalphaM = alphaM.getField().getZero();
  737.         DerivativeStructure cosAlphaE     = alphaE.cos();
  738.         DerivativeStructure sinAlphaE     = alphaE.sin();
  739.         int                 iter          = 0;
  740.         do {
  741.             final DerivativeStructure f2 = ex.multiply(sinAlphaE).subtract(ey.multiply(cosAlphaE));
  742.             final DerivativeStructure f1 = alphaM.getField().getOne().subtract(ex.multiply(cosAlphaE)).subtract(ey.multiply(sinAlphaE));
  743.             final DerivativeStructure f0 = alphaEMalphaM.subtract(f2);

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

  746.             alphaEMalphaM  = alphaEMalphaM.subtract(shift);
  747.             alphaE         = alphaM.add(alphaEMalphaM);
  748.             cosAlphaE      = alphaE.cos();
  749.             sinAlphaE      = alphaE.sin();

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

  751.         return alphaE;

  752.     }

  753.     /** {@inheritDoc} */
  754.     protected double getMass(final AbsoluteDate date) {
  755.         return models.get(date).mass;
  756.     }

  757.     /** Replace the instance with a data transfer object for serialization.
  758.      * @return data transfer object that will be serialized
  759.      * @exception NotSerializableException if an additional state provider is not serializable
  760.      */
  761.     private Object writeReplace() throws NotSerializableException {
  762.         try {
  763.             // managed states providers
  764.             final List<AdditionalStateProvider> serializableProviders = new ArrayList<AdditionalStateProvider>();
  765.             for (final AdditionalStateProvider provider : getAdditionalStateProviders()) {
  766.                 if (provider instanceof Serializable) {
  767.                     serializableProviders.add(provider);
  768.                 } else {
  769.                     throw new NotSerializableException(provider.getClass().getName());
  770.                 }
  771.             }

  772.             // states transitions
  773.             final AbsoluteDate[]  transitionDates;
  774.             final CircularOrbit[] allOrbits;
  775.             final double[]        allMasses;
  776.             final SortedSet<TimeSpanMap.Transition<EHModel>> transitions = models.getTransitions();
  777.             if (transitions.size() == 1  && transitions.first().getBefore() == transitions.first().getAfter()) {
  778.                 // the single entry is a dummy one, without a real transition
  779.                 // we ignore it completely
  780.                 transitionDates = null;
  781.                 allOrbits       = null;
  782.                 allMasses       = null;
  783.             } else {
  784.                 transitionDates = new AbsoluteDate[transitions.size()];
  785.                 allOrbits       = new CircularOrbit[transitions.size() + 1];
  786.                 allMasses       = new double[transitions.size() + 1];
  787.                 int i = 0;
  788.                 for (final TimeSpanMap.Transition<EHModel> transition : transitions) {
  789.                     if (i == 0) {
  790.                         // model before the first transition
  791.                         allOrbits[i] = transition.getBefore().mean;
  792.                         allMasses[i] = transition.getBefore().mass;
  793.                     }
  794.                     transitionDates[i] = transition.getDate();
  795.                     allOrbits[++i]     = transition.getAfter().mean;
  796.                     allMasses[i]       = transition.getAfter().mass;
  797.                 }
  798.             }

  799.             return new DataTransferObject(getInitialState().getOrbit(), initialModel.mass,
  800.                                           referenceRadius, mu, ck0, getAttitudeProvider(),
  801.                                           transitionDates, allOrbits, allMasses,
  802.                                           serializableProviders.toArray(new AdditionalStateProvider[serializableProviders.size()]));
  803.         } catch (OrekitException orekitException) {
  804.             // this should never happen
  805.             throw new OrekitInternalError(null);
  806.         }

  807.     }

  808.     /** Internal class used only for serialization. */
  809.     private static class DataTransferObject implements Serializable {

  810.         /** Serializable UID. */
  811.         private static final long serialVersionUID = 20151202L;

  812.         /** Initial orbit. */
  813.         private final Orbit orbit;

  814.         /** Attitude provider. */
  815.         private final AttitudeProvider attitudeProvider;

  816.         /** Mass and gravity field. */
  817.         private double[] g;

  818.         /** Transition dates (may be null). */
  819.         private final AbsoluteDate[] transitionDates;

  820.         /** Orbits before and after transitions (may be null). */
  821.         private final CircularOrbit[] allOrbits;

  822.         /** Masses before and after transitions (may be null). */
  823.         private final double[] allMasses;

  824.         /** Providers for additional states. */
  825.         private final AdditionalStateProvider[] providers;

  826.         /** Simple constructor.
  827.          * @param orbit initial orbit
  828.          * @param mass spacecraft mass
  829.          * @param referenceRadius reference radius of the Earth for the potential model (m)
  830.          * @param mu central attraction coefficient (m³/s²)
  831.          * @param ck0 un-normalized zonal coefficients
  832.          * @param attitudeProvider attitude provider
  833.          * @param transitionDates transition dates (may be null)
  834.          * @param allOrbits orbits before and after transitions (may be null)
  835.          * @param allMasses masses before and after transitions (may be null)
  836.          * @param providers providers for additional states
  837.          */
  838.         DataTransferObject(final Orbit orbit, final double mass,
  839.                            final double referenceRadius, final double mu,
  840.                            final double[] ck0,
  841.                            final AttitudeProvider attitudeProvider,
  842.                            final AbsoluteDate[] transitionDates,
  843.                            final CircularOrbit[] allOrbits,
  844.                            final double[] allMasses,
  845.                            final AdditionalStateProvider[] providers) {
  846.             this.orbit            = orbit;
  847.             this.attitudeProvider = attitudeProvider;
  848.             this.g = new double[] {
  849.                 mass, referenceRadius, mu,
  850.                 ck0[2], ck0[3], ck0[4], ck0[5], ck0[6] // ck0[0] and ck0[1] are both zero so not serialized
  851.             };
  852.             this.transitionDates  = transitionDates;
  853.             this.allOrbits        = allOrbits;
  854.             this.allMasses        = allMasses;
  855.             this.providers        = providers;
  856.         }

  857.         /** Replace the deserialized data transfer object with a {@link EcksteinHechlerPropagator}.
  858.          * @return replacement {@link EcksteinHechlerPropagator}
  859.          */
  860.         private Object readResolve() {
  861.             try {
  862.                 final EcksteinHechlerPropagator propagator =
  863.                                 new EcksteinHechlerPropagator(orbit, attitudeProvider,
  864.                                                               g[0], g[1], g[2],              // mass, referenceRadius, mu
  865.                                                               g[3], g[4], g[5], g[6], g[7]); // c20, c30, c40, c50, c60
  866.                 for (final AdditionalStateProvider provider : providers) {
  867.                     propagator.addAdditionalStateProvider(provider);

  868.                 }
  869.                 if (transitionDates != null) {
  870.                     // override the state transitions
  871.                     final double[] ck0 = new double[] {
  872.                         0, 0, g[3], g[4], g[5], g[6], g[7]
  873.                     };
  874.                     propagator.models = new TimeSpanMap<EHModel>(new EHModel(allOrbits[0], allMasses[0],
  875.                                                                              g[1], g[2], ck0));
  876.                     for (int i = 0; i < transitionDates.length; ++i) {
  877.                         propagator.models.addValidAfter(new EHModel(allOrbits[i + 1], allMasses[i + 1],
  878.                                                                     g[1], g[2], ck0),
  879.                                                         transitionDates[i]);
  880.                     }
  881.                 }

  882.                 return propagator;
  883.             } catch (OrekitException oe) {
  884.                 throw new OrekitInternalError(oe);
  885.             }
  886.         }

  887.     }

  888. }