Orbit.java

  1. /* Copyright 2002-2019 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.orbits;

  18. import java.io.Serializable;

  19. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  20. import org.hipparchus.linear.DecompositionSolver;
  21. import org.hipparchus.linear.MatrixUtils;
  22. import org.hipparchus.linear.QRDecomposition;
  23. import org.hipparchus.linear.RealMatrix;
  24. import org.hipparchus.util.FastMath;
  25. import org.hipparchus.util.MathArrays;
  26. import org.orekit.errors.OrekitIllegalArgumentException;
  27. import org.orekit.errors.OrekitInternalError;
  28. import org.orekit.errors.OrekitMessages;
  29. import org.orekit.frames.Frame;
  30. import org.orekit.frames.Transform;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.time.TimeInterpolable;
  33. import org.orekit.time.TimeShiftable;
  34. import org.orekit.time.TimeStamped;
  35. import org.orekit.utils.PVCoordinates;
  36. import org.orekit.utils.PVCoordinatesProvider;
  37. import org.orekit.utils.TimeStampedPVCoordinates;

  38. /**
  39.  * This class handles orbital parameters.

  40.  * <p>
  41.  * For user convenience, both the Cartesian and the equinoctial elements
  42.  * are provided by this class, regardless of the canonical representation
  43.  * implemented in the derived class (which may be classical Keplerian
  44.  * elements for example).
  45.  * </p>
  46.  * <p>
  47.  * The parameters are defined in a frame specified by the user. It is important
  48.  * to make sure this frame is consistent: it probably is inertial and centered
  49.  * on the central body. This information is used for example by some
  50.  * force models.
  51.  * </p>
  52.  * <p>
  53.  * Instance of this class are guaranteed to be immutable.
  54.  * </p>
  55.  * @author Luc Maisonobe
  56.  * @author Guylaine Prat
  57.  * @author Fabien Maussion
  58.  * @author V&eacute;ronique Pommier-Maurussane
  59.  */
  60. public abstract class Orbit
  61.     implements TimeStamped, TimeShiftable<Orbit>, TimeInterpolable<Orbit>,
  62.                Serializable, PVCoordinatesProvider {

  63.     /** Serializable UID. */
  64.     private static final long serialVersionUID = 438733454597999578L;

  65.     /** Frame in which are defined the orbital parameters. */
  66.     private final Frame frame;

  67.     /** Date of the orbital parameters. */
  68.     private final AbsoluteDate date;

  69.     /** Value of mu used to compute position and velocity (m³/s²). */
  70.     private final double mu;

  71.     /** Computed PVCoordinates. */
  72.     private transient TimeStampedPVCoordinates pvCoordinates;

  73.     /** Jacobian of the orbital parameters with mean angle with respect to the Cartesian coordinates. */
  74.     private transient double[][] jacobianMeanWrtCartesian;

  75.     /** Jacobian of the Cartesian coordinates with respect to the orbital parameters with mean angle. */
  76.     private transient double[][] jacobianWrtParametersMean;

  77.     /** Jacobian of the orbital parameters with eccentric angle with respect to the Cartesian coordinates. */
  78.     private transient double[][] jacobianEccentricWrtCartesian;

  79.     /** Jacobian of the Cartesian coordinates with respect to the orbital parameters with eccentric angle. */
  80.     private transient double[][] jacobianWrtParametersEccentric;

  81.     /** Jacobian of the orbital parameters with true angle with respect to the Cartesian coordinates. */
  82.     private transient double[][] jacobianTrueWrtCartesian;

  83.     /** Jacobian of the Cartesian coordinates with respect to the orbital parameters with true angle. */
  84.     private transient double[][] jacobianWrtParametersTrue;

  85.     /** Default constructor.
  86.      * Build a new instance with arbitrary default elements.
  87.      * @param frame the frame in which the parameters are defined
  88.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  89.      * @param date date of the orbital parameters
  90.      * @param mu central attraction coefficient (m^3/s^2)
  91.      * @exception IllegalArgumentException if frame is not a {@link
  92.      * Frame#isPseudoInertial pseudo-inertial frame}
  93.      */
  94.     protected Orbit(final Frame frame, final AbsoluteDate date, final double mu)
  95.         throws IllegalArgumentException {
  96.         ensurePseudoInertialFrame(frame);
  97.         this.date                      = date;
  98.         this.mu                        = mu;
  99.         this.pvCoordinates             = null;
  100.         this.frame                     = frame;
  101.         jacobianMeanWrtCartesian       = null;
  102.         jacobianWrtParametersMean      = null;
  103.         jacobianEccentricWrtCartesian  = null;
  104.         jacobianWrtParametersEccentric = null;
  105.         jacobianTrueWrtCartesian       = null;
  106.         jacobianWrtParametersTrue      = null;
  107.     }

  108.     /** Set the orbit from Cartesian parameters.
  109.      *
  110.      * <p> The acceleration provided in {@code pvCoordinates} is accessible using
  111.      * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods
  112.      * use {@code mu} and the position to compute the acceleration, including
  113.      * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}.
  114.      *
  115.      * @param pvCoordinates the position and velocity in the inertial frame
  116.      * @param frame the frame in which the {@link TimeStampedPVCoordinates} are defined
  117.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  118.      * @param mu central attraction coefficient (m^3/s^2)
  119.      * @exception IllegalArgumentException if frame is not a {@link
  120.      * Frame#isPseudoInertial pseudo-inertial frame}
  121.      */
  122.     protected Orbit(final TimeStampedPVCoordinates pvCoordinates, final Frame frame, final double mu)
  123.         throws IllegalArgumentException {
  124.         ensurePseudoInertialFrame(frame);
  125.         this.date = pvCoordinates.getDate();
  126.         this.mu = mu;
  127.         if (pvCoordinates.getAcceleration().getNormSq() == 0) {
  128.             // the acceleration was not provided,
  129.             // compute it from Newtonian attraction
  130.             final double r2 = pvCoordinates.getPosition().getNormSq();
  131.             final double r3 = r2 * FastMath.sqrt(r2);
  132.             this.pvCoordinates = new TimeStampedPVCoordinates(pvCoordinates.getDate(),
  133.                                                               pvCoordinates.getPosition(),
  134.                                                               pvCoordinates.getVelocity(),
  135.                                                               new Vector3D(-mu / r3, pvCoordinates.getPosition()));
  136.         } else {
  137.             this.pvCoordinates = pvCoordinates;
  138.         }
  139.         this.frame = frame;
  140.     }

  141.     /** Check if Cartesian coordinates include non-Keplerian acceleration.
  142.      * @param pva Cartesian coordinates
  143.      * @param mu central attraction coefficient
  144.      * @return true if Cartesian coordinates include non-Keplerian acceleration
  145.      */
  146.     protected static boolean hasNonKeplerianAcceleration(final PVCoordinates pva, final double mu) {

  147.         final Vector3D a = pva.getAcceleration();
  148.         if (a == null) {
  149.             return false;
  150.         }

  151.         final Vector3D p = pva.getPosition();
  152.         final double r2 = p.getNormSq();
  153.         final double r  = FastMath.sqrt(r2);
  154.         final Vector3D keplerianAcceleration = new Vector3D(-mu / (r * r2), p);
  155.         if (a.getNorm() > 1.0e-9 * keplerianAcceleration.getNorm()) {
  156.             // we have a relevant acceleration, we can compute derivatives
  157.             return true;
  158.         } else {
  159.             // the provided acceleration is either too small to be reliable (probably even 0), or NaN
  160.             return false;
  161.         }

  162.     }

  163.     /** Get the orbit type.
  164.      * @return orbit type
  165.      */
  166.     public abstract OrbitType getType();

  167.     /** Ensure the defining frame is a pseudo-inertial frame.
  168.      * @param frame frame to check
  169.      * @exception IllegalArgumentException if frame is not a {@link
  170.      * Frame#isPseudoInertial pseudo-inertial frame}
  171.      */
  172.     private static void ensurePseudoInertialFrame(final Frame frame)
  173.         throws IllegalArgumentException {
  174.         if (!frame.isPseudoInertial()) {
  175.             throw new OrekitIllegalArgumentException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME,
  176.                                                      frame.getName());
  177.         }
  178.     }

  179.     /** Get the frame in which the orbital parameters are defined.
  180.      * @return frame in which the orbital parameters are defined
  181.      */
  182.     public Frame getFrame() {
  183.         return frame;
  184.     }

  185.     /** Get the semi-major axis.
  186.      * <p>Note that the semi-major axis is considered negative for hyperbolic orbits.</p>
  187.      * @return semi-major axis (m)
  188.      */
  189.     public abstract double getA();

  190.     /** Get the semi-major axis derivative.
  191.      * <p>Note that the semi-major axis is considered negative for hyperbolic orbits.</p>
  192.      * <p>
  193.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  194.      * </p>
  195.      * @return semi-major axis  derivative (m/s)
  196.      * @see #hasDerivatives()
  197.      * @since 9.0
  198.      */
  199.     public abstract double getADot();

  200.     /** Get the first component of the equinoctial eccentricity vector derivative.
  201.      * @return first component of the equinoctial eccentricity vector derivative
  202.      */
  203.     public abstract double getEquinoctialEx();

  204.     /** Get the first component of the equinoctial eccentricity vector.
  205.      * <p>
  206.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  207.      * </p>
  208.      * @return first component of the equinoctial eccentricity vector
  209.      * @see #hasDerivatives()
  210.      * @since 9.0
  211.      */
  212.     public abstract double getEquinoctialExDot();

  213.     /** Get the second component of the equinoctial eccentricity vector derivative.
  214.      * @return second component of the equinoctial eccentricity vector derivative
  215.      */
  216.     public abstract double getEquinoctialEy();

  217.     /** Get the second component of the equinoctial eccentricity vector.
  218.      * <p>
  219.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  220.      * </p>
  221.      * @return second component of the equinoctial eccentricity vector
  222.      * @see #hasDerivatives()
  223.      * @since 9.0
  224.      */
  225.     public abstract double getEquinoctialEyDot();

  226.     /** Get the first component of the inclination vector.
  227.      * @return first component of the inclination vector
  228.      */
  229.     public abstract double getHx();

  230.     /** Get the first component of the inclination vector derivative.
  231.      * <p>
  232.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  233.      * </p>
  234.      * @return first component of the inclination vector derivative
  235.      * @see #hasDerivatives()
  236.      * @since 9.0
  237.      */
  238.     public abstract double getHxDot();

  239.     /** Get the second component of the inclination vector.
  240.      * @return second component of the inclination vector
  241.      */
  242.     public abstract double getHy();

  243.     /** Get the second component of the inclination vector derivative.
  244.      * <p>
  245.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  246.      * </p>
  247.      * @return second component of the inclination vector derivative
  248.      * @see #hasDerivatives()
  249.      * @since 9.0
  250.      */
  251.     public abstract double getHyDot();

  252.     /** Get the eccentric longitude argument.
  253.      * @return E + ω + Ω eccentric longitude argument (rad)
  254.      */
  255.     public abstract double getLE();

  256.     /** Get the eccentric longitude argument derivative.
  257.      * <p>
  258.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  259.      * </p>
  260.      * @return d(E + ω + Ω)/dt eccentric longitude argument derivative (rad/s)
  261.      * @see #hasDerivatives()
  262.      * @since 9.0
  263.      */
  264.     public abstract double getLEDot();

  265.     /** Get the true longitude argument.
  266.      * @return v + ω + Ω true longitude argument (rad)
  267.      */
  268.     public abstract double getLv();

  269.     /** Get the true longitude argument derivative.
  270.      * <p>
  271.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  272.      * </p>
  273.      * @return d(v + ω + Ω)/dt true longitude argument derivative (rad/s)
  274.      * @see #hasDerivatives()
  275.      * @since 9.0
  276.      */
  277.     public abstract double getLvDot();

  278.     /** Get the mean longitude argument.
  279.      * @return M + ω + Ω mean longitude argument (rad)
  280.      */
  281.     public abstract double getLM();

  282.     /** Get the mean longitude argument derivative.
  283.      * <p>
  284.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  285.      * </p>
  286.      * @return d(M + ω + Ω)/dt mean longitude argument derivative (rad/s)
  287.      * @see #hasDerivatives()
  288.      * @since 9.0
  289.      */
  290.     public abstract double getLMDot();

  291.     // Additional orbital elements

  292.     /** Get the eccentricity.
  293.      * @return eccentricity
  294.      */
  295.     public abstract double getE();

  296.     /** Get the eccentricity derivative.
  297.      * <p>
  298.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  299.      * </p>
  300.      * @return eccentricity derivative
  301.      * @see #hasDerivatives()
  302.      * @since 9.0
  303.      */
  304.     public abstract double getEDot();

  305.     /** Get the inclination.
  306.      * @return inclination (rad)
  307.      */
  308.     public abstract double getI();

  309.     /** Get the inclination derivative.
  310.      * <p>
  311.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  312.      * </p>
  313.      * @return inclination derivative (rad/s)
  314.      * @see #hasDerivatives()
  315.      * @since 9.0
  316.      */
  317.     public abstract double getIDot();

  318.     /** Check if orbit includes derivatives.
  319.      * @return true if orbit includes derivatives
  320.      * @see #getADot()
  321.      * @see #getEquinoctialExDot()
  322.      * @see #getEquinoctialEyDot()
  323.      * @see #getHxDot()
  324.      * @see #getHyDot()
  325.      * @see #getLEDot()
  326.      * @see #getLvDot()
  327.      * @see #getLMDot()
  328.      * @see #getEDot()
  329.      * @see #getIDot()
  330.      * @since 9.0
  331.      */
  332.     public boolean hasDerivatives() {
  333.         return !Double.isNaN(getADot());
  334.     }

  335.     /** Get the central acceleration constant.
  336.      * @return central acceleration constant
  337.      */
  338.     public double getMu() {
  339.         return mu;
  340.     }

  341.     /** Get the Keplerian period.
  342.      * <p>The Keplerian period is computed directly from semi major axis
  343.      * and central acceleration constant.</p>
  344.      * @return Keplerian period in seconds, or positive infinity for hyperbolic orbits
  345.      */
  346.     public double getKeplerianPeriod() {
  347.         final double a = getA();
  348.         return (a < 0) ? Double.POSITIVE_INFINITY : 2.0 * FastMath.PI * a * FastMath.sqrt(a / mu);
  349.     }

  350.     /** Get the Keplerian mean motion.
  351.      * <p>The Keplerian mean motion is computed directly from semi major axis
  352.      * and central acceleration constant.</p>
  353.      * @return Keplerian mean motion in radians per second
  354.      */
  355.     public double getKeplerianMeanMotion() {
  356.         final double absA = FastMath.abs(getA());
  357.         return FastMath.sqrt(mu / absA) / absA;
  358.     }

  359.     /** Get the date of orbital parameters.
  360.      * @return date of the orbital parameters
  361.      */
  362.     public AbsoluteDate getDate() {
  363.         return date;
  364.     }

  365.     /** Get the {@link TimeStampedPVCoordinates} in a specified frame.
  366.      * @param outputFrame frame in which the position/velocity coordinates shall be computed
  367.      * @return pvCoordinates in the specified output frame
  368.           * @see #getPVCoordinates()
  369.      */
  370.     public TimeStampedPVCoordinates getPVCoordinates(final Frame outputFrame) {
  371.         if (pvCoordinates == null) {
  372.             pvCoordinates = initPVCoordinates();
  373.         }

  374.         // If output frame requested is the same as definition frame,
  375.         // PV coordinates are returned directly
  376.         if (outputFrame == frame) {
  377.             return pvCoordinates;
  378.         }

  379.         // Else, PV coordinates are transformed to output frame
  380.         final Transform t = frame.getTransformTo(outputFrame, date);
  381.         return t.transformPVCoordinates(pvCoordinates);
  382.     }

  383.     /** {@inheritDoc} */
  384.     public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate otherDate, final Frame otherFrame) {
  385.         return shiftedBy(otherDate.durationFrom(getDate())).getPVCoordinates(otherFrame);
  386.     }


  387.     /** Get the {@link TimeStampedPVCoordinates} in definition frame.
  388.      * @return pvCoordinates in the definition frame
  389.      * @see #getPVCoordinates(Frame)
  390.      */
  391.     public TimeStampedPVCoordinates getPVCoordinates() {
  392.         if (pvCoordinates == null) {
  393.             pvCoordinates = initPVCoordinates();
  394.         }
  395.         return pvCoordinates;
  396.     }

  397.     /** Compute the position/velocity coordinates from the canonical parameters.
  398.      * @return computed position/velocity coordinates
  399.      */
  400.     protected abstract TimeStampedPVCoordinates initPVCoordinates();

  401.     /** Get a time-shifted orbit.
  402.      * <p>
  403.      * The orbit can be slightly shifted to close dates. The shifting model is a
  404.      * Keplerian one if no derivatives are available in the orbit, or Keplerian
  405.      * plus quadratic effect of the non-Keplerian acceleration if derivatives are
  406.      * available. Shifting is <em>not</em> intended as a replacement for proper
  407.      * orbit propagation but should be sufficient for small time shifts or coarse
  408.      * accuracy.
  409.      * </p>
  410.      * @param dt time shift in seconds
  411.      * @return a new orbit, shifted with respect to the instance (which is immutable)
  412.      */
  413.     public abstract Orbit shiftedBy(double dt);

  414.     /** Compute the Jacobian of the orbital parameters with respect to the Cartesian parameters.
  415.      * <p>
  416.      * Element {@code jacobian[i][j]} is the derivative of parameter i of the orbit with
  417.      * respect to Cartesian coordinate j. This means each row corresponds to one orbital parameter
  418.      * whereas columns 0 to 5 correspond to the Cartesian coordinates x, y, z, xDot, yDot and zDot.
  419.      * </p>
  420.      * @param type type of the position angle to use
  421.      * @param jacobian placeholder 6x6 (or larger) matrix to be filled with the Jacobian, if matrix
  422.      * is larger than 6x6, only the 6x6 upper left corner will be modified
  423.      */
  424.     public void getJacobianWrtCartesian(final PositionAngle type, final double[][] jacobian) {

  425.         final double[][] cachedJacobian;
  426.         synchronized (this) {
  427.             switch (type) {
  428.                 case MEAN :
  429.                     if (jacobianMeanWrtCartesian == null) {
  430.                         // first call, we need to compute the Jacobian and cache it
  431.                         jacobianMeanWrtCartesian = computeJacobianMeanWrtCartesian();
  432.                     }
  433.                     cachedJacobian = jacobianMeanWrtCartesian;
  434.                     break;
  435.                 case ECCENTRIC :
  436.                     if (jacobianEccentricWrtCartesian == null) {
  437.                         // first call, we need to compute the Jacobian and cache it
  438.                         jacobianEccentricWrtCartesian = computeJacobianEccentricWrtCartesian();
  439.                     }
  440.                     cachedJacobian = jacobianEccentricWrtCartesian;
  441.                     break;
  442.                 case TRUE :
  443.                     if (jacobianTrueWrtCartesian == null) {
  444.                         // first call, we need to compute the Jacobian and cache it
  445.                         jacobianTrueWrtCartesian = computeJacobianTrueWrtCartesian();
  446.                     }
  447.                     cachedJacobian = jacobianTrueWrtCartesian;
  448.                     break;
  449.                 default :
  450.                     throw new OrekitInternalError(null);
  451.             }
  452.         }

  453.         // fill the user provided array
  454.         for (int i = 0; i < cachedJacobian.length; ++i) {
  455.             System.arraycopy(cachedJacobian[i], 0, jacobian[i], 0, cachedJacobian[i].length);
  456.         }

  457.     }

  458.     /** Compute the Jacobian of the Cartesian parameters with respect to the orbital parameters.
  459.      * <p>
  460.      * Element {@code jacobian[i][j]} is the derivative of Cartesian coordinate i of the orbit with
  461.      * respect to orbital parameter j. This means each row corresponds to one Cartesian coordinate
  462.      * x, y, z, xdot, ydot, zdot whereas columns 0 to 5 correspond to the orbital parameters.
  463.      * </p>
  464.      * @param type type of the position angle to use
  465.      * @param jacobian placeholder 6x6 (or larger) matrix to be filled with the Jacobian, if matrix
  466.      * is larger than 6x6, only the 6x6 upper left corner will be modified
  467.      */
  468.     public void getJacobianWrtParameters(final PositionAngle type, final double[][] jacobian) {

  469.         final double[][] cachedJacobian;
  470.         synchronized (this) {
  471.             switch (type) {
  472.                 case MEAN :
  473.                     if (jacobianWrtParametersMean == null) {
  474.                         // first call, we need to compute the Jacobian and cache it
  475.                         jacobianWrtParametersMean = createInverseJacobian(type);
  476.                     }
  477.                     cachedJacobian = jacobianWrtParametersMean;
  478.                     break;
  479.                 case ECCENTRIC :
  480.                     if (jacobianWrtParametersEccentric == null) {
  481.                         // first call, we need to compute the Jacobian and cache it
  482.                         jacobianWrtParametersEccentric = createInverseJacobian(type);
  483.                     }
  484.                     cachedJacobian = jacobianWrtParametersEccentric;
  485.                     break;
  486.                 case TRUE :
  487.                     if (jacobianWrtParametersTrue == null) {
  488.                         // first call, we need to compute the Jacobian and cache it
  489.                         jacobianWrtParametersTrue = createInverseJacobian(type);
  490.                     }
  491.                     cachedJacobian = jacobianWrtParametersTrue;
  492.                     break;
  493.                 default :
  494.                     throw new OrekitInternalError(null);
  495.             }
  496.         }

  497.         // fill the user-provided array
  498.         for (int i = 0; i < cachedJacobian.length; ++i) {
  499.             System.arraycopy(cachedJacobian[i], 0, jacobian[i], 0, cachedJacobian[i].length);
  500.         }

  501.     }

  502.     /** Create an inverse Jacobian.
  503.      * @param type type of the position angle to use
  504.      * @return inverse Jacobian
  505.      */
  506.     private double[][] createInverseJacobian(final PositionAngle type) {

  507.         // get the direct Jacobian
  508.         final double[][] directJacobian = new double[6][6];
  509.         getJacobianWrtCartesian(type, directJacobian);

  510.         // invert the direct Jacobian
  511.         final RealMatrix matrix = MatrixUtils.createRealMatrix(directJacobian);
  512.         final DecompositionSolver solver = new QRDecomposition(matrix).getSolver();
  513.         return solver.getInverse().getData();

  514.     }

  515.     /** Compute the Jacobian of the orbital parameters with mean angle with respect to the Cartesian parameters.
  516.      * <p>
  517.      * Element {@code jacobian[i][j]} is the derivative of parameter i of the orbit with
  518.      * respect to Cartesian coordinate j. This means each row correspond to one orbital parameter
  519.      * whereas columns 0 to 5 correspond to the Cartesian coordinates x, y, z, xDot, yDot and zDot.
  520.      * </p>
  521.      * @return 6x6 Jacobian matrix
  522.      * @see #computeJacobianEccentricWrtCartesian()
  523.      * @see #computeJacobianTrueWrtCartesian()
  524.      */
  525.     protected abstract double[][] computeJacobianMeanWrtCartesian();

  526.     /** Compute the Jacobian of the orbital parameters with eccentric angle with respect to the Cartesian parameters.
  527.      * <p>
  528.      * Element {@code jacobian[i][j]} is the derivative of parameter i of the orbit with
  529.      * respect to Cartesian coordinate j. This means each row correspond to one orbital parameter
  530.      * whereas columns 0 to 5 correspond to the Cartesian coordinates x, y, z, xDot, yDot and zDot.
  531.      * </p>
  532.      * @return 6x6 Jacobian matrix
  533.      * @see #computeJacobianMeanWrtCartesian()
  534.      * @see #computeJacobianTrueWrtCartesian()
  535.      */
  536.     protected abstract double[][] computeJacobianEccentricWrtCartesian();

  537.     /** Compute the Jacobian of the orbital parameters with true angle with respect to the Cartesian parameters.
  538.      * <p>
  539.      * Element {@code jacobian[i][j]} is the derivative of parameter i of the orbit with
  540.      * respect to Cartesian coordinate j. This means each row correspond to one orbital parameter
  541.      * whereas columns 0 to 5 correspond to the Cartesian coordinates x, y, z, xDot, yDot and zDot.
  542.      * </p>
  543.      * @return 6x6 Jacobian matrix
  544.      * @see #computeJacobianMeanWrtCartesian()
  545.      * @see #computeJacobianEccentricWrtCartesian()
  546.      */
  547.     protected abstract double[][] computeJacobianTrueWrtCartesian();

  548.     /** Add the contribution of the Keplerian motion to parameters derivatives
  549.      * <p>
  550.      * This method is used by integration-based propagators to evaluate the part of Keplerian
  551.      * motion to evolution of the orbital state.
  552.      * </p>
  553.      * @param type type of the position angle in the state
  554.      * @param gm attraction coefficient to use
  555.      * @param pDot array containing orbital state derivatives to update (the Keplerian
  556.      * part must be <em>added</em> to the array components, as the array may already
  557.      * contain some non-zero elements corresponding to non-Keplerian parts)
  558.      */
  559.     public abstract void addKeplerContribution(PositionAngle type, double gm, double[] pDot);

  560.         /** Fill a Jacobian half row with a single vector.
  561.      * @param a coefficient of the vector
  562.      * @param v vector
  563.      * @param row Jacobian matrix row
  564.      * @param j index of the first element to set (row[j], row[j+1] and row[j+2] will all be set)
  565.      */
  566.     protected static void fillHalfRow(final double a, final Vector3D v, final double[] row, final int j) {
  567.         row[j]     = a * v.getX();
  568.         row[j + 1] = a * v.getY();
  569.         row[j + 2] = a * v.getZ();
  570.     }

  571.     /** Fill a Jacobian half row with a linear combination of vectors.
  572.      * @param a1 coefficient of the first vector
  573.      * @param v1 first vector
  574.      * @param a2 coefficient of the second vector
  575.      * @param v2 second vector
  576.      * @param row Jacobian matrix row
  577.      * @param j index of the first element to set (row[j], row[j+1] and row[j+2] will all be set)
  578.      */
  579.     protected static void fillHalfRow(final double a1, final Vector3D v1, final double a2, final Vector3D v2,
  580.                                       final double[] row, final int j) {
  581.         row[j]     = MathArrays.linearCombination(a1, v1.getX(), a2, v2.getX());
  582.         row[j + 1] = MathArrays.linearCombination(a1, v1.getY(), a2, v2.getY());
  583.         row[j + 2] = MathArrays.linearCombination(a1, v1.getZ(), a2, v2.getZ());
  584.     }

  585.     /** Fill a Jacobian half row with a linear combination of vectors.
  586.      * @param a1 coefficient of the first vector
  587.      * @param v1 first vector
  588.      * @param a2 coefficient of the second vector
  589.      * @param v2 second vector
  590.      * @param a3 coefficient of the third vector
  591.      * @param v3 third vector
  592.      * @param row Jacobian matrix row
  593.      * @param j index of the first element to set (row[j], row[j+1] and row[j+2] will all be set)
  594.      */
  595.     protected static void fillHalfRow(final double a1, final Vector3D v1, final double a2, final Vector3D v2,
  596.                                       final double a3, final Vector3D v3,
  597.                                       final double[] row, final int j) {
  598.         row[j]     = MathArrays.linearCombination(a1, v1.getX(), a2, v2.getX(), a3, v3.getX());
  599.         row[j + 1] = MathArrays.linearCombination(a1, v1.getY(), a2, v2.getY(), a3, v3.getY());
  600.         row[j + 2] = MathArrays.linearCombination(a1, v1.getZ(), a2, v2.getZ(), a3, v3.getZ());
  601.     }

  602.     /** Fill a Jacobian half row with a linear combination of vectors.
  603.      * @param a1 coefficient of the first vector
  604.      * @param v1 first vector
  605.      * @param a2 coefficient of the second vector
  606.      * @param v2 second vector
  607.      * @param a3 coefficient of the third vector
  608.      * @param v3 third vector
  609.      * @param a4 coefficient of the fourth vector
  610.      * @param v4 fourth vector
  611.      * @param row Jacobian matrix row
  612.      * @param j index of the first element to set (row[j], row[j+1] and row[j+2] will all be set)
  613.      */
  614.     protected static void fillHalfRow(final double a1, final Vector3D v1, final double a2, final Vector3D v2,
  615.                                       final double a3, final Vector3D v3, final double a4, final Vector3D v4,
  616.                                       final double[] row, final int j) {
  617.         row[j]     = MathArrays.linearCombination(a1, v1.getX(), a2, v2.getX(), a3, v3.getX(), a4, v4.getX());
  618.         row[j + 1] = MathArrays.linearCombination(a1, v1.getY(), a2, v2.getY(), a3, v3.getY(), a4, v4.getY());
  619.         row[j + 2] = MathArrays.linearCombination(a1, v1.getZ(), a2, v2.getZ(), a3, v3.getZ(), a4, v4.getZ());
  620.     }

  621.     /** Fill a Jacobian half row with a linear combination of vectors.
  622.      * @param a1 coefficient of the first vector
  623.      * @param v1 first vector
  624.      * @param a2 coefficient of the second vector
  625.      * @param v2 second vector
  626.      * @param a3 coefficient of the third vector
  627.      * @param v3 third vector
  628.      * @param a4 coefficient of the fourth vector
  629.      * @param v4 fourth vector
  630.      * @param a5 coefficient of the fifth vector
  631.      * @param v5 fifth vector
  632.      * @param row Jacobian matrix row
  633.      * @param j index of the first element to set (row[j], row[j+1] and row[j+2] will all be set)
  634.      */
  635.     protected static void fillHalfRow(final double a1, final Vector3D v1, final double a2, final Vector3D v2,
  636.                                       final double a3, final Vector3D v3, final double a4, final Vector3D v4,
  637.                                       final double a5, final Vector3D v5,
  638.                                       final double[] row, final int j) {
  639.         final double[] a = new double[] {
  640.             a1, a2, a3, a4, a5
  641.         };
  642.         row[j]     = MathArrays.linearCombination(a, new double[] {
  643.             v1.getX(), v2.getX(), v3.getX(), v4.getX(), v5.getX()
  644.         });
  645.         row[j + 1] = MathArrays.linearCombination(a, new double[] {
  646.             v1.getY(), v2.getY(), v3.getY(), v4.getY(), v5.getY()
  647.         });
  648.         row[j + 2] = MathArrays.linearCombination(a, new double[] {
  649.             v1.getZ(), v2.getZ(), v3.getZ(), v4.getZ(), v5.getZ()
  650.         });
  651.     }

  652.     /** Fill a Jacobian half row with a linear combination of vectors.
  653.      * @param a1 coefficient of the first vector
  654.      * @param v1 first vector
  655.      * @param a2 coefficient of the second vector
  656.      * @param v2 second vector
  657.      * @param a3 coefficient of the third vector
  658.      * @param v3 third vector
  659.      * @param a4 coefficient of the fourth vector
  660.      * @param v4 fourth vector
  661.      * @param a5 coefficient of the fifth vector
  662.      * @param v5 fifth vector
  663.      * @param a6 coefficient of the sixth vector
  664.      * @param v6 sixth vector
  665.      * @param row Jacobian matrix row
  666.      * @param j index of the first element to set (row[j], row[j+1] and row[j+2] will all be set)
  667.      */
  668.     protected static void fillHalfRow(final double a1, final Vector3D v1, final double a2, final Vector3D v2,
  669.                                       final double a3, final Vector3D v3, final double a4, final Vector3D v4,
  670.                                       final double a5, final Vector3D v5, final double a6, final Vector3D v6,
  671.                                       final double[] row, final int j) {
  672.         final double[] a = new double[] {
  673.             a1, a2, a3, a4, a5, a6
  674.         };
  675.         row[j]     = MathArrays.linearCombination(a, new double[] {
  676.             v1.getX(), v2.getX(), v3.getX(), v4.getX(), v5.getX(), v6.getX()
  677.         });
  678.         row[j + 1] = MathArrays.linearCombination(a, new double[] {
  679.             v1.getY(), v2.getY(), v3.getY(), v4.getY(), v5.getY(), v6.getY()
  680.         });
  681.         row[j + 2] = MathArrays.linearCombination(a, new double[] {
  682.             v1.getZ(), v2.getZ(), v3.getZ(), v4.getZ(), v5.getZ(), v6.getZ()
  683.         });
  684.     }

  685. }