StateTransitionMatrixGenerator.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.propagation.numerical;

  18. import org.hipparchus.analysis.differentiation.Gradient;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.orekit.attitudes.AttitudeProvider;
  21. import org.orekit.forces.ForceModel;
  22. import org.orekit.propagation.FieldSpacecraftState;

  23. import java.util.List;

  24. /** Generator for State Transition Matrix.
  25.  * The state is made up of the Cartesian position and velocity vectors.
  26.  * @author Luc Maisonobe
  27.  * @author Melina Vanel
  28.  * @since 11.1
  29.  */
  30. class StateTransitionMatrixGenerator extends AbstractStateTransitionMatrixGenerator {

  31.     /**
  32.      * State dimension.
  33.      */
  34.     public static final int STATE_DIMENSION = 2 * SPACE_DIMENSION;

  35.     /**
  36.      * Simple constructor.
  37.      *
  38.      * @param stmName          name of the Cartesian STM additional state
  39.      * @param forceModels      force models used in propagation
  40.      * @param attitudeProvider attitude provider used in propagation
  41.      */
  42.     StateTransitionMatrixGenerator(final String stmName, final List<ForceModel> forceModels,
  43.                                    final AttitudeProvider attitudeProvider) {
  44.         super(stmName, forceModels, attitudeProvider, STATE_DIMENSION);
  45.     }

  46.     /** {@inheritDoc} */
  47.     @Override
  48.     protected void multiplyMatrix(final double[] factor, final double[] x, final double[] y, final int columns) {
  49.         staticMultiplyMatrix(factor, x, y, columns);
  50.     }

  51.     /** Compute evolution matrix product.
  52.      * <p>
  53.      * This method computes \(Y = F \times X\) where the factor matrix is:
  54.      * \[F = \begin{matrix}
  55.      *               0         &             0         &             0         &             1         &             0         &             0        \\
  56.      *               0         &             0         &             0         &             0         &             1         &             0        \\
  57.      *               0         &             0         &             0         &             0         &             0         &             1        \\
  58.      *  \sum \frac{da_x}{dp_x} & \sum\frac{da_x}{dp_y} & \sum\frac{da_x}{dp_z} & \sum\frac{da_x}{dv_x} & \sum\frac{da_x}{dv_y} & \sum\frac{da_x}{dv_z}\\
  59.      *  \sum \frac{da_y}{dp_x} & \sum\frac{da_y}{dp_y} & \sum\frac{da_y}{dp_z} & \sum\frac{da_y}{dv_x} & \sum\frac{da_y}{dv_y} & \sum\frac{da_y}{dv_z}\\
  60.      *  \sum \frac{da_z}{dp_x} & \sum\frac{da_z}{dp_y} & \sum\frac{da_z}{dp_z} & \sum\frac{da_z}{dv_x} & \sum\frac{da_z}{dv_y} & \sum\frac{da_z}{dv_z}
  61.      * \end{matrix}\]
  62.      * </p>
  63.      * @param factor factor matrix
  64.      * @param x right factor of the multiplication, as a flatten array in row major order
  65.      * @param y placeholder where to put the result, as a flatten array in row major order
  66.      * @param columns number of columns of both x and y (so their dimensions are 6 x columns)
  67.      */
  68.     static void staticMultiplyMatrix(final double[] factor, final double[] x, final double[] y, final int columns) {

  69.         final int n = SPACE_DIMENSION * columns;

  70.         // handle first three rows by a simple copy
  71.         System.arraycopy(x, n, y, 0, n);

  72.         // regular multiplication for the last three rows
  73.         for (int j = 0; j < columns; ++j) {
  74.             y[n + j              ] = factor[ 0] * x[j              ] + factor[ 1] * x[j +     columns] + factor[ 2] * x[j + 2 * columns] +
  75.                     factor[ 3] * x[j + 3 * columns] + factor[ 4] * x[j + 4 * columns] + factor[ 5] * x[j + 5 * columns];
  76.             y[n + j +     columns] = factor[ 6] * x[j              ] + factor[ 7] * x[j +     columns] + factor[ 8] * x[j + 2 * columns] +
  77.                     factor[ 9] * x[j + 3 * columns] + factor[10] * x[j + 4 * columns] + factor[11] * x[j + 5 * columns];
  78.             y[n + j + 2 * columns] = factor[12] * x[j              ] + factor[13] * x[j +     columns] + factor[14] * x[j + 2 * columns] +
  79.                     factor[15] * x[j + 3 * columns] + factor[16] * x[j + 4 * columns] + factor[17] * x[j + 5 * columns];
  80.         }

  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     Gradient[] computeRatesPartialsAndUpdateFactor(final ForceModel forceModel,
  85.                                                    final FieldSpacecraftState<Gradient> fieldState,
  86.                                                    final Gradient[] parameters, final double[] factor) {
  87.         final FieldVector3D<Gradient> acceleration = forceModel.acceleration(fieldState, parameters);
  88.         final double[]                       gradX        = acceleration.getX().getGradient();
  89.         final double[]                       gradY        = acceleration.getY().getGradient();
  90.         final double[]                       gradZ        = acceleration.getZ().getGradient();

  91.         // lower left part of the factor matrix
  92.         factor[ 0] += gradX[0];
  93.         factor[ 1] += gradX[1];
  94.         factor[ 2] += gradX[2];
  95.         factor[ 6] += gradY[0];
  96.         factor[ 7] += gradY[1];
  97.         factor[ 8] += gradY[2];
  98.         factor[12] += gradZ[0];
  99.         factor[13] += gradZ[1];
  100.         factor[14] += gradZ[2];

  101.         if (!forceModel.dependsOnPositionOnly()) {
  102.             // lower right part of the factor matrix
  103.             factor[ 3] += gradX[3];
  104.             factor[ 4] += gradX[4];
  105.             factor[ 5] += gradX[5];
  106.             factor[ 9] += gradY[3];
  107.             factor[10] += gradY[4];
  108.             factor[11] += gradY[5];
  109.             factor[15] += gradZ[3];
  110.             factor[16] += gradZ[4];
  111.             factor[17] += gradZ[5];
  112.         }
  113.         return acceleration.toArray();
  114.     }
  115. }