STMEquations.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.cr3bp;

  18. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  19. import org.hipparchus.linear.Array2DRowRealMatrix;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.orekit.bodies.CR3BPSystem;
  22. import org.orekit.propagation.SpacecraftState;
  23. import org.orekit.propagation.integration.AdditionalDerivativesProvider;
  24. import org.orekit.propagation.integration.CombinedDerivatives;

  25. import java.util.Arrays;

  26. /** Class calculating the state transition matrix coefficient for CR3BP Computation.
  27.  * @see "Dynamical systems, the three-body problem, and space mission design, Koon, Lo, Marsden, Ross"
  28.  * @author Vincent Mouraux
  29.  * @since 10.2
  30.  */
  31. public class STMEquations
  32.     implements AdditionalDerivativesProvider {

  33.     /** Matrix Dimension. */
  34.     private static final int DIM = 6;

  35.     /** Mass ratio of the considered CR3BP System. */
  36.     private final CR3BPSystem syst;

  37.     /** Name of the equations. */
  38.     private final String name;

  39.     /** Potential Hessian Matrix. */
  40.     private final double[][] jacobian = new double[DIM][DIM];

  41.     /** Simple constructor.
  42.      * @param syst CR3BP System considered
  43.      */
  44.     public STMEquations(final CR3BPSystem syst) {
  45.         this.syst = syst;
  46.         this.name = "stmEquations";

  47.         // Jacobian constant values initialization
  48.         for (double[] doubles : jacobian) {
  49.             Arrays.fill(doubles, 0.0);
  50.         }

  51.         jacobian[0][3] = 1.0;
  52.         jacobian[1][4] = 1.0;
  53.         jacobian[2][5] = 1.0;
  54.         jacobian[3][4] = 2.0;
  55.         jacobian[4][3] = -2.0;
  56.     }

  57.     /** Method adding the standard initial values of the additional state to the initial spacecraft state.
  58.      * @param s Initial state of the system
  59.      * @return s Initial augmented (with the additional equations) state
  60.      */
  61.     public SpacecraftState setInitialPhi(final SpacecraftState s) {
  62.         final int stateDimension = 36;
  63.         final double[] phi = new double[stateDimension];
  64.         for (int i = 0; i < stateDimension; i = i + 7) {
  65.             phi[i] = 1.0;
  66.         }
  67.         return s.addAdditionalData(name, phi);
  68.     }

  69.     /** {@inheritDoc} */
  70.     public CombinedDerivatives combinedDerivatives(final SpacecraftState s) {

  71.         // State Transition Matrix
  72.         final double[] phi = s.getAdditionalState(getName());
  73.         final double[] dPhi = new double[phi.length];

  74.         // Spacecraft Potential
  75.         final DerivativeStructure potential = new CR3BPForceModel(syst).getPotential(s);

  76.         // Potential derivatives
  77.         final double[] dU = potential.getAllDerivatives();

  78.         // second order derivatives index
  79.         final int idXX = potential.getFactory().getCompiler().getPartialDerivativeIndex(2, 0, 0);
  80.         final int idXY = potential.getFactory().getCompiler().getPartialDerivativeIndex(1, 1, 0);
  81.         final int idXZ = potential.getFactory().getCompiler().getPartialDerivativeIndex(1, 0, 1);
  82.         final int idYY = potential.getFactory().getCompiler().getPartialDerivativeIndex(0, 2, 0);
  83.         final int idYZ = potential.getFactory().getCompiler().getPartialDerivativeIndex(0, 1, 1);
  84.         final int idZZ = potential.getFactory().getCompiler().getPartialDerivativeIndex(0, 0, 2);

  85.         // New Jacobian values
  86.         jacobian[3][0] = dU[idXX];
  87.         jacobian[4][1] = dU[idYY];
  88.         jacobian[5][2] = dU[idZZ];
  89.         jacobian[3][1] = dU[idXY];
  90.         jacobian[4][0] = jacobian[3][1];
  91.         jacobian[3][2] = dU[idXZ];
  92.         jacobian[5][0] = jacobian[3][2];
  93.         jacobian[4][2] = dU[idYZ];
  94.         jacobian[5][1] = jacobian[4][2];

  95.         // STM derivatives computation : dPhi = Jacobian * Phi if both dPhi and Phi are defined as Matrix
  96.         for (int k = 0; k < DIM; k++) {
  97.             for (int l = 0; l < DIM; l++) {
  98.                 for (int i = 0; i < DIM; i++) {
  99.                     dPhi[DIM * k + l] =
  100.                         dPhi[DIM * k + l] + jacobian[k][i] * phi[DIM * i + l];
  101.                 }
  102.             }
  103.         }

  104.         return new CombinedDerivatives(dPhi, null);

  105.     }

  106.     /** {@inheritDoc} */
  107.     public String getName() {
  108.         return name;
  109.     }

  110.     /** {@inheritDoc} */
  111.     @Override
  112.     public int getDimension() {
  113.         return DIM * DIM;
  114.     }

  115.     /** Method returning the State Transition Matrix.
  116.      * @param s SpacecraftState of the system
  117.      * @return phiM State Transition Matrix
  118.      */
  119.     public RealMatrix getStateTransitionMatrix(final SpacecraftState s) {
  120.         final double[][] phi2dA = new double[DIM][DIM];
  121.         final double[] stm = s.getAdditionalState(getName());
  122.         for (int i = 0; i < DIM; i++) {
  123.             for (int j = 0; j < 6; j++) {
  124.                 phi2dA[i][j] = stm[DIM * i + j];
  125.             }
  126.         }
  127.         return new Array2DRowRealMatrix(phi2dA, false);
  128.     }
  129. }