PartialDerivativesEquations.java

  1. /* Copyright 2010-2011 Centre National d'Études Spatiales
  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.numerical;

  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.List;
  21. import java.util.SortedSet;
  22. import java.util.TreeSet;

  23. import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
  24. import org.apache.commons.math3.geometry.euclidean.threed.FieldRotation;
  25. import org.apache.commons.math3.geometry.euclidean.threed.FieldVector3D;
  26. import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
  27. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  28. import org.apache.commons.math3.util.FastMath;
  29. import org.apache.commons.math3.util.Precision;
  30. import org.orekit.errors.OrekitException;
  31. import org.orekit.errors.OrekitMessages;
  32. import org.orekit.forces.ForceModel;
  33. import org.orekit.propagation.SpacecraftState;
  34. import org.orekit.propagation.integration.AdditionalEquations;

  35. /** Set of {@link AdditionalEquations additional equations} computing the partial derivatives
  36.  * of the state (orbit) with respect to initial state and force models parameters.
  37.  * <p>
  38.  * This set of equations are automatically added to a {@link NumericalPropagator numerical propagator}
  39.  * in order to compute partial derivatives of the orbit along with the orbit itself. This is
  40.  * useful for example in orbit determination applications.
  41.  * </p>
  42.  * @author V&eacute;ronique Pommier-Maurussane
  43.  */
  44. public class PartialDerivativesEquations implements AdditionalEquations {

  45.     /** Selected parameters for Jacobian computation. */
  46.     private NumericalPropagator propagator;

  47.     /** Derivatives providers. */
  48.     private final List<ForceModel> derivativesProviders;

  49.     /** List of parameters selected for Jacobians computation. */
  50.     private List<ParameterConfiguration> selectedParameters;

  51.     /** Name. */
  52.     private String name;

  53.     /** State vector dimension without additional parameters
  54.      * (either 6 or 7 depending on mass derivatives being included or not). */
  55.     private int stateDim;

  56.     /** Parameters vector dimension. */
  57.     private int paramDim;

  58.     /** Step used for finite difference computation with respect to spacecraft position. */
  59.     private double hPos;

  60.     /** Boolean for force models / selected parameters consistency. */
  61.     private boolean dirty = false;

  62.     /** Jacobian of acceleration with respect to spacecraft position. */
  63.     private transient double[][] dAccdPos;

  64.     /** Jacobian of acceleration with respect to spacecraft velocity. */
  65.     private transient double[][] dAccdVel;

  66.     /** Jacobian of acceleration with respect to spacecraft mass. */
  67.     private transient double[]   dAccdM;

  68.     /** Jacobian of acceleration with respect to one force model parameter (array reused for all parameters). */
  69.     private transient double[]   dAccdParam;

  70.     /** Simple constructor.
  71.      * <p>
  72.      * Upon construction, this set of equations is <em>automatically</em> added to
  73.      * the propagator by calling its {@link
  74.      * NumericalPropagator#addAdditionalEquations(AdditionalEquations)} method. So
  75.      * there is no need to call this method explicitly for these equations.
  76.      * </p>
  77.      * @param name name of the partial derivatives equations
  78.      * @param propagator the propagator that will handle the orbit propagation
  79.      * @exception OrekitException if a set of equations with the same name is already present
  80.      */
  81.     public PartialDerivativesEquations(final String name, final NumericalPropagator propagator)
  82.         throws OrekitException {
  83.         this.name = name;
  84.         derivativesProviders = new ArrayList<ForceModel>();
  85.         dirty = true;
  86.         this.propagator = propagator;
  87.         selectedParameters = new ArrayList<ParameterConfiguration>();
  88.         stateDim = -1;
  89.         paramDim = -1;
  90.         hPos     = Double.NaN;
  91.         propagator.addAdditionalEquations(this);
  92.     }

  93.     /** {@inheritDoc} */
  94.     public String getName() {
  95.         return name;
  96.     }

  97.     /** Get the names of the available parameters in the propagator.
  98.      * <p>
  99.      * The names returned depend on the force models set up in the propagator,
  100.      * including the Newtonian attraction from the central body.
  101.      * </p>
  102.      * @return available parameters
  103.      */
  104.     public List<String> getAvailableParameters() {
  105.         final List<String> available = new ArrayList<String>();
  106.         available.addAll(propagator.getNewtonianAttractionForceModel().getParametersNames());
  107.         for (final ForceModel model : propagator.getForceModels()) {
  108.             available.addAll(model.getParametersNames());
  109.         }
  110.         return available;
  111.     }

  112.     /** Select the parameters to consider for Jacobian processing.
  113.      * <p>Parameters names have to be consistent with some
  114.      * {@link ForceModel} added elsewhere.</p>
  115.      * @param parameters parameters to consider for Jacobian processing
  116.      * @see NumericalPropagator#addForceModel(ForceModel)
  117.      * @see #setInitialJacobians(SpacecraftState, double[][], double[][])
  118.      * @see ForceModel
  119.      * @see org.apache.commons.math3.ode.Parameterizable

  120.      */
  121.     public void selectParameters(final String ... parameters) {

  122.         selectedParameters.clear();
  123.         for (String param : parameters) {
  124.             selectedParameters.add(new ParameterConfiguration(param, Double.NaN));
  125.         }

  126.         dirty = true;

  127.     }

  128.     /** Select the parameters to consider for Jacobian processing.
  129.      * <p>Parameters names have to be consistent with some
  130.      * {@link ForceModel} added elsewhere.</p>
  131.      * @param parameter parameter to consider for Jacobian processing
  132.      * @param hP step to use for computing Jacobian column with respect to the specified parameter
  133.      * @see NumericalPropagator#addForceModel(ForceModel)
  134.      * @see #setInitialJacobians(SpacecraftState, double[][], double[][])
  135.      * @see ForceModel
  136.      * @see org.apache.commons.math3.ode.Parameterizable
  137.      */
  138.     public void selectParamAndStep(final String parameter, final double hP) {
  139.         selectedParameters.add(new ParameterConfiguration(parameter, hP));
  140.         dirty = true;
  141.     }

  142.     /** Set the initial value of the Jacobian with respect to state and parameter.
  143.      * <p>
  144.      * This method is equivalent to call {@link #setInitialJacobians(SpacecraftState,
  145.      * double[][], double[][])} with dYdY0 set to the identity matrix and dYdP set
  146.      * to a zero matrix.
  147.      * </p>
  148.      * <p>
  149.      * The returned state must be added to the propagator (it is not done
  150.      * automatically, as the user may need to add more states to it).
  151.      * </p>
  152.      * @param s0 initial state
  153.      * @param stateDimension state dimension, must be either 6 for orbit only or 7 for orbit and mass
  154.      * @param paramDimension parameters dimension
  155.      * @return state with initial Jacobians added
  156.      * @exception OrekitException if the partial equation has not been registered in
  157.      * the propagator or if matrices dimensions are incorrect
  158.      * @see #selectedParameters
  159.      * @see #selectParamAndStep(String, double)
  160.      */
  161.     public SpacecraftState setInitialJacobians(final SpacecraftState s0, final int stateDimension, final int paramDimension)
  162.         throws OrekitException {
  163.         final double[][] dYdY0 = new double[stateDimension][stateDimension];
  164.         final double[][] dYdP  = new double[stateDimension][paramDimension];
  165.         for (int i = 0; i < stateDimension; ++i) {
  166.             dYdY0[i][i] = 1.0;
  167.         }
  168.         return setInitialJacobians(s0, dYdY0, dYdP);
  169.     }

  170.     /** Set the initial value of the Jacobian with respect to state and parameter.
  171.      * <p>
  172.      * The returned state must be added to the propagator (it is not done
  173.      * automatically, as the user may need to add more states to it).
  174.      * </p>
  175.      * @param s1 current state
  176.      * @param dY1dY0 Jacobian of current state at time t<sub>1</sub> with respect
  177.      * to state at some previous time t<sub>0</sub> (may be either 6x6 for orbit
  178.      * only or 7x7 for orbit and mass)
  179.      * @param dY1dP Jacobian of current state at time t<sub>1</sub> with respect
  180.      * to parameters (may be null if no parameters are selected)
  181.      * @return state with initial Jacobians added
  182.      * @exception OrekitException if the partial equation has not been registered in
  183.      * the propagator or if matrices dimensions are incorrect
  184.      * @see #selectedParameters
  185.      * @see #selectParamAndStep(String, double)
  186.      */
  187.     public SpacecraftState setInitialJacobians(final SpacecraftState s1,
  188.                                                final double[][] dY1dY0, final double[][] dY1dP)
  189.         throws OrekitException {

  190.         // Check dimensions
  191.         stateDim = dY1dY0.length;
  192.         if ((stateDim < 6) || (stateDim > 7) || (stateDim != dY1dY0[0].length)) {
  193.             throw new OrekitException(OrekitMessages.STATE_JACOBIAN_NEITHER_6X6_NOR_7X7,
  194.                                       stateDim, dY1dY0[0].length);
  195.         }
  196.         if ((dY1dP != null) && (stateDim != dY1dP.length)) {
  197.             throw new OrekitException(OrekitMessages.STATE_AND_PARAMETERS_JACOBIANS_ROWS_MISMATCH,
  198.                                       stateDim, dY1dP.length);
  199.         }

  200.         paramDim = (dY1dP == null) ? 0 : dY1dP[0].length;

  201.         // store the matrices as a single dimension array
  202.         final JacobiansMapper mapper = getMapper();
  203.         final double[] p = new double[mapper.getAdditionalStateDimension()];
  204.         mapper.setInitialJacobians(s1, dY1dY0, dY1dP, p);

  205.         // set value in propagator
  206.         return s1.addAdditionalState(name, p);

  207.     }

  208.     /** Get a mapper between two-dimensional Jacobians and one-dimensional additional state.
  209.      * @return a mapper between two-dimensional Jacobians and one-dimensional additional state,
  210.      * with the same name as the instance
  211.      * @exception OrekitException if the initial Jacobians have not been initialized yet
  212.      * @see #setInitialJacobians(SpacecraftState, int, int)
  213.      * @see #setInitialJacobians(SpacecraftState, double[][], double[][])
  214.      */
  215.     public JacobiansMapper getMapper() throws OrekitException {
  216.         if (stateDim < 0) {
  217.             throw new OrekitException(OrekitMessages.STATE_JACOBIAN_NOT_INITIALIZED);
  218.         }
  219.         return new JacobiansMapper(name, stateDim, paramDim,
  220.                                    propagator.getOrbitType(),
  221.                                    propagator.getPositionAngleType());
  222.     }

  223.     /** {@inheritDoc} */
  224.     public double[] computeDerivatives(final SpacecraftState s, final double[] pDot)
  225.         throws OrekitException {

  226.         final int dim = 3;

  227.         // Lazy initialization
  228.         if (dirty) {

  229.             // if step has not been set by user, set a default value
  230.             if (Double.isNaN(hPos)) {
  231.                 hPos = FastMath.sqrt(Precision.EPSILON) * s.getPVCoordinates().getPosition().getNorm();
  232.             }

  233.              // set up derivatives providers
  234.             derivativesProviders.clear();
  235.             derivativesProviders.addAll(propagator.getForceModels());
  236.             derivativesProviders.add(propagator.getNewtonianAttractionForceModel());

  237.             // check all parameters are handled by at least one Jacobian provider
  238.             for (final ParameterConfiguration param : selectedParameters) {
  239.                 final String parameterName = param.getParameterName();
  240.                 boolean found = false;
  241.                 for (final ForceModel provider : derivativesProviders) {
  242.                     if (provider.isSupported(parameterName)) {
  243.                         param.setProvider(provider);
  244.                         found = true;
  245.                     }
  246.                 }
  247.                 if (!found) {

  248.                     // build the list of supported parameters, avoiding duplication
  249.                     final SortedSet<String> set = new TreeSet<String>();
  250.                     for (final ForceModel provider : derivativesProviders) {
  251.                         for (final String forceModelParameter : provider.getParametersNames()) {
  252.                             set.add(forceModelParameter);
  253.                         }
  254.                     }
  255.                     final StringBuilder builder = new StringBuilder();
  256.                     for (final String forceModelParameter : set) {
  257.                         if (builder.length() > 0) {
  258.                             builder.append(", ");
  259.                         }
  260.                         builder.append(forceModelParameter);
  261.                     }

  262.                     throw new OrekitException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME,
  263.                                               parameterName, builder.toString());

  264.                 }
  265.             }

  266.             // check the numbers of parameters and matrix size agree
  267.             if (selectedParameters.size() != paramDim) {
  268.                 throw new OrekitException(OrekitMessages.INITIAL_MATRIX_AND_PARAMETERS_NUMBER_MISMATCH,
  269.                                           paramDim, selectedParameters.size());
  270.             }

  271.             dAccdParam = new double[dim];
  272.             dAccdPos   = new double[dim][dim];
  273.             dAccdVel   = new double[dim][dim];
  274.             dAccdM     = (stateDim > 6) ? new double[dim] : null;

  275.             dirty = false;

  276.         }

  277.         // initialize acceleration Jacobians to zero
  278.         for (final double[] row : dAccdPos) {
  279.             Arrays.fill(row, 0.0);
  280.         }
  281.         for (final double[] row : dAccdVel) {
  282.             Arrays.fill(row, 0.0);
  283.         }
  284.         if (dAccdM != null) {
  285.             Arrays.fill(dAccdM, 0.0);
  286.         }

  287.         // prepare derivation variables, 3 for position, 3 for velocity and optionally 1 for mass
  288.         final int nbVars = (dAccdM == null) ? 6 : 7;

  289.         // position corresponds three free parameters
  290.         final Vector3D position = s.getPVCoordinates().getPosition();
  291.         final FieldVector3D<DerivativeStructure> dsP = new FieldVector3D<DerivativeStructure>(new DerivativeStructure(nbVars, 1, 0, position.getX()),
  292.                                               new DerivativeStructure(nbVars, 1, 1, position.getY()),
  293.                                               new DerivativeStructure(nbVars, 1, 2, position.getZ()));

  294.         // velocity corresponds three free parameters
  295.         final Vector3D velocity = s.getPVCoordinates().getPosition();
  296.         final FieldVector3D<DerivativeStructure> dsV = new FieldVector3D<DerivativeStructure>(new DerivativeStructure(nbVars, 1, 3, velocity.getX()),
  297.                                               new DerivativeStructure(nbVars, 1, 4, velocity.getY()),
  298.                                               new DerivativeStructure(nbVars, 1, 5, velocity.getZ()));

  299.         // mass corresponds either to a constant or to one free parameter
  300.         final DerivativeStructure dsM = (dAccdM == null) ?
  301.                                         new DerivativeStructure(nbVars, 1,    s.getMass()) :
  302.                                         new DerivativeStructure(nbVars, 1, 6, s.getMass());

  303.         // TODO:  we should compute attitude partial derivatives with respect to position/velocity
  304.         final Rotation rotation = s.getAttitude().getRotation();
  305.         final FieldRotation<DerivativeStructure> dsR =
  306.                 new FieldRotation<DerivativeStructure>(new DerivativeStructure(nbVars, 1, rotation.getQ0()),
  307.                                new DerivativeStructure(nbVars, 1, rotation.getQ1()),
  308.                                new DerivativeStructure(nbVars, 1, rotation.getQ2()),
  309.                                new DerivativeStructure(nbVars, 1, rotation.getQ3()),
  310.                                false);

  311.         // compute acceleration Jacobians
  312.         for (final ForceModel derivativesProvider : derivativesProviders) {
  313.             final FieldVector3D<DerivativeStructure> acceleration =
  314.                     derivativesProvider.accelerationDerivatives(s.getDate(), s.getFrame(),
  315.                                                                 dsP, dsV, dsR, dsM);
  316.             addToRow(acceleration.getX(), 0);
  317.             addToRow(acceleration.getY(), 1);
  318.             addToRow(acceleration.getZ(), 2);
  319.         }

  320.         // the variational equations of the complete state Jacobian matrix have the
  321.         // following form for 7x7, i.e. when mass partial derivatives are also considered
  322.         // (when mass is not considered, only the A, B, D and E matrices are used along
  323.         // with their derivatives):

  324.         // [       |        |       ]   [                 |                  |               ]   [    |     |    ]
  325.         // [ Adot  |  Bdot  |  Cdot ]   [  dVel/dPos = 0  |  dVel/dVel = Id  |   dVel/dm = 0 ]   [ A  |  B  |  C ]
  326.         // [       |        |       ]   [                 |                  |               ]   [    |     |    ]
  327.         // --------+--------+--- ----   ------------------+------------------+----------------   -----+-----+-----
  328.         // [       |        |       ]   [                 |                  |               ]   [    |     |    ]
  329.         // [ Ddot  |  Edot  |  Fdot ] = [    dAcc/dPos    |     dAcc/dVel    |    dAcc/dm    ] * [ D  |  E  |  F ]
  330.         // [       |        |       ]   [                 |                  |               ]   [    |     |    ]
  331.         // --------+--------+--- ----   ------------------+------------------+----------------   -----+-----+-----
  332.         // [ Gdot  |  Hdot  |  Idot ]   [ dmDot/dPos = 0  |  dmDot/dVel = 0  |  dmDot/dm = 0 ]   [ G  |  H  |  I ]

  333.         // The A, B, D and E sub-matrices and their derivatives (Adot ...) are 3x3 matrices,
  334.         // the C and F sub-matrices and their derivatives (Cdot ...) are 3x1 matrices,
  335.         // the G and H sub-matrices and their derivatives (Gdot ...) are 1x3 matrices,
  336.         // the I sub-matrix and its derivative (Idot) is a 1x1 matrix.

  337.         // The expanded multiplication above can be rewritten to take into account
  338.         // the fixed values found in the sub-matrices in the left factor. This leads to:

  339.         //     [ Adot ] = [ D ]
  340.         //     [ Bdot ] = [ E ]
  341.         //     [ Cdot ] = [ F ]
  342.         //     [ Ddot ] = [ dAcc/dPos ] * [ A ] + [ dAcc/dVel ] * [ D ] + [ dAcc/dm ] * [ G ]
  343.         //     [ Edot ] = [ dAcc/dPos ] * [ B ] + [ dAcc/dVel ] * [ E ] + [ dAcc/dm ] * [ H ]
  344.         //     [ Fdot ] = [ dAcc/dPos ] * [ C ] + [ dAcc/dVel ] * [ F ] + [ dAcc/dm ] * [ I ]
  345.         //     [ Gdot ] = [ 0 ]
  346.         //     [ Hdot ] = [ 0 ]
  347.         //     [ Idot ] = [ 0 ]

  348.         // The following loops compute these expressions taking care of the mapping of the
  349.         // (A, B, ... I) matrices into the single dimension array p and of the mapping of the
  350.         // (Adot, Bdot, ... Idot) matrices into the single dimension array pDot.

  351.         // copy D, E and F into Adot, Bdot and Cdot
  352.         final double[] p = s.getAdditionalState(getName());
  353.         System.arraycopy(p, dim * stateDim, pDot, 0, dim * stateDim);

  354.         // compute Ddot, Edot and Fdot
  355.         for (int i = 0; i < dim; ++i) {
  356.             final double[] dAdPi = dAccdPos[i];
  357.             final double[] dAdVi = dAccdVel[i];
  358.             for (int j = 0; j < stateDim; ++j) {
  359.                 pDot[(dim + i) * stateDim + j] =
  360.                     dAdPi[0] * p[j]                + dAdPi[1] * p[j +     stateDim] + dAdPi[2] * p[j + 2 * stateDim] +
  361.                     dAdVi[0] * p[j + 3 * stateDim] + dAdVi[1] * p[j + 4 * stateDim] + dAdVi[2] * p[j + 5 * stateDim] +
  362.                     ((dAccdM == null) ? 0.0 : dAccdM[i] * p[j + 6 * stateDim]);
  363.             }
  364.         }

  365.         if (dAccdM != null) {
  366.             // set Gdot, Hdot and Idot to 0
  367.             Arrays.fill(pDot, 6 * stateDim, 7 * stateDim, 0.0);
  368.         }

  369.         for (int k = 0; k < paramDim; ++k) {

  370.             // compute the acceleration gradient with respect to current parameter
  371.             final ParameterConfiguration param = selectedParameters.get(k);
  372.             final ForceModel provider = param.getProvider();
  373.             final FieldVector3D<DerivativeStructure> accDer =
  374.                     provider.accelerationDerivatives(s, param.getParameterName());
  375.             dAccdParam[0] = accDer.getX().getPartialDerivative(1);
  376.             dAccdParam[1] = accDer.getY().getPartialDerivative(1);
  377.             dAccdParam[2] = accDer.getZ().getPartialDerivative(1);

  378.             // the variational equations of the parameters Jacobian matrix are computed
  379.             // one column at a time, they have the following form:
  380.             // [      ]   [                 |                  |               ]   [   ]   [                  ]
  381.             // [ Jdot ]   [  dVel/dPos = 0  |  dVel/dVel = Id  |   dVel/dm = 0 ]   [ J ]   [  dVel/dParam = 0 ]
  382.             // [      ]   [                 |                  |               ]   [   ]   [                  ]
  383.             // --------   ------------------+------------------+----------------   -----   --------------------
  384.             // [      ]   [                 |                  |               ]   [   ]   [                  ]
  385.             // [ Kdot ] = [    dAcc/dPos    |     dAcc/dVel    |    dAcc/dm    ] * [ K ] + [    dAcc/dParam   ]
  386.             // [      ]   [                 |                  |               ]   [   ]   [                  ]
  387.             // --------   ------------------+------------------+----------------   -----   --------------------
  388.             // [ Ldot ]   [ dmDot/dPos = 0  |  dmDot/dVel = 0  |  dmDot/dm = 0 ]   [ L ]   [ dmDot/dParam = 0 ]

  389.             // The J and K sub-columns and their derivatives (Jdot ...) are 3 elements columns,
  390.             // the L sub-colums and its derivative (Ldot) are 1 elements columns.

  391.             // The expanded multiplication and addition above can be rewritten to take into
  392.             // account the fixed values found in the sub-matrices in the left factor. This leads to:

  393.             //     [ Jdot ] = [ K ]
  394.             //     [ Kdot ] = [ dAcc/dPos ] * [ J ] + [ dAcc/dVel ] * [ K ] + [ dAcc/dm ] * [ L ] + [ dAcc/dParam ]
  395.             //     [ Ldot ] = [ 0 ]

  396.             // The following loops compute these expressions taking care of the mapping of the
  397.             // (J, K, L) columns into the single dimension array p and of the mapping of the
  398.             // (Jdot, Kdot, Ldot) columns into the single dimension array pDot.

  399.             // copy K into Jdot
  400.             final int columnTop = stateDim * stateDim + k;
  401.             pDot[columnTop]                = p[columnTop + 3 * paramDim];
  402.             pDot[columnTop +     paramDim] = p[columnTop + 4 * paramDim];
  403.             pDot[columnTop + 2 * paramDim] = p[columnTop + 5 * paramDim];

  404.             // compute Kdot
  405.             for (int i = 0; i < dim; ++i) {
  406.                 final double[] dAdPi = dAccdPos[i];
  407.                 final double[] dAdVi = dAccdVel[i];
  408.                 pDot[columnTop + (dim + i) * paramDim] =
  409.                     dAccdParam[i] +
  410.                     dAdPi[0] * p[columnTop]                + dAdPi[1] * p[columnTop +     paramDim] + dAdPi[2] * p[columnTop + 2 * paramDim] +
  411.                     dAdVi[0] * p[columnTop + 3 * paramDim] + dAdVi[1] * p[columnTop + 4 * paramDim] + dAdVi[2] * p[columnTop + 5 * paramDim] +
  412.                     ((dAccdM == null) ? 0.0 : dAccdM[i] * p[columnTop + 6 * paramDim]);
  413.             }

  414.             if (dAccdM != null) {
  415.                 // set Ldot to 0
  416.                 pDot[columnTop + 6 * paramDim] = 0;
  417.             }

  418.         }

  419.         // these equations have no effect of the main state itself
  420.         return null;

  421.     }

  422.     /** Fill Jacobians rows when mass is needed.
  423.      * @param accelerationComponent component of acceleration (along either x, y or z)
  424.      * @param index component index (0 for x, 1 for y, 2 for z)
  425.      */
  426.     private void addToRow(final DerivativeStructure accelerationComponent, final int index) {

  427.         if (dAccdM == null) {

  428.             // free parameters 0, 1, 2 are for position
  429.             dAccdPos[index][0] += accelerationComponent.getPartialDerivative(1, 0, 0, 0, 0, 0);
  430.             dAccdPos[index][1] += accelerationComponent.getPartialDerivative(0, 1, 0, 0, 0, 0);
  431.             dAccdPos[index][2] += accelerationComponent.getPartialDerivative(0, 0, 1, 0, 0, 0);

  432.             // free parameters 3, 4, 5 are for velocity
  433.             dAccdVel[index][0] += accelerationComponent.getPartialDerivative(0, 0, 0, 1, 0, 0);
  434.             dAccdVel[index][1] += accelerationComponent.getPartialDerivative(0, 0, 0, 0, 1, 0);
  435.             dAccdVel[index][2] += accelerationComponent.getPartialDerivative(0, 0, 0, 0, 0, 1);

  436.         } else {

  437.             // free parameters 0, 1, 2 are for position
  438.             dAccdPos[index][0] += accelerationComponent.getPartialDerivative(1, 0, 0, 0, 0, 0, 0);
  439.             dAccdPos[index][1] += accelerationComponent.getPartialDerivative(0, 1, 0, 0, 0, 0, 0);
  440.             dAccdPos[index][2] += accelerationComponent.getPartialDerivative(0, 0, 1, 0, 0, 0, 0);

  441.             // free parameters 3, 4, 5 are for velocity
  442.             dAccdVel[index][0] += accelerationComponent.getPartialDerivative(0, 0, 0, 1, 0, 0, 0);
  443.             dAccdVel[index][1] += accelerationComponent.getPartialDerivative(0, 0, 0, 0, 1, 0, 0);
  444.             dAccdVel[index][2] += accelerationComponent.getPartialDerivative(0, 0, 0, 0, 0, 1, 0);

  445.             // free parameter 6 is for mass
  446.             dAccdM[index]      += accelerationComponent.getPartialDerivative(0, 0, 0, 0, 0, 0, 1);

  447.         }

  448.     }

  449. }