STMEquations.java

  1. /* Copyright 2002-2022 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 java.util.Arrays;

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

  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. @SuppressWarnings("deprecation")
  32. public class STMEquations
  33.     implements AdditionalDerivativesProvider,
  34.                org.orekit.propagation.integration.AdditionalEquations {

  35.     /** Matrix Dimension. */
  36.     private static final int DIM = 6;

  37.     /** Mass ratio of the considered CR3BP System. */
  38.     private final CR3BPSystem syst;

  39.     /** Name of the equations. */
  40.     private final String name;

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

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

  49.         // Jacobian constant values initialization
  50.         for (int j = 0; j < jacobian.length; ++j) {
  51.             Arrays.fill(jacobian[j], 0.0);
  52.         }

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

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

  71.     /** {@inheritDoc} */
  72.     public void init(final SpacecraftState initialState, final AbsoluteDate target) {
  73.         // FIXME: remove in 12.0 when AdditionalEquations is removed
  74.         AdditionalDerivativesProvider.super.init(initialState, target);
  75.     }

  76.     /** {@inheritDoc} */
  77.     public double[] computeDerivatives(final SpacecraftState s, final double[] pDot) {
  78.         // FIXME: remove in 12.0 when AdditionalEquations is removed
  79.         System.arraycopy(derivatives(s), 0, pDot, 0, pDot.length);
  80.         return null;
  81.     }

  82.     /** {@inheritDoc} */
  83.     public double[] derivatives(final SpacecraftState s) {

  84.         // State Transition Matrix
  85.         final double[] phi = s.getAdditionalState(getName());
  86.         final double[] dPhi = new double[phi.length];

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

  89.         // Potential derivatives
  90.         final double[] dU = potential.getAllDerivatives();

  91.         // second order derivatives index
  92.         final int idXX = potential.getFactory().getCompiler().getPartialDerivativeIndex(2, 0, 0);
  93.         final int idXY = potential.getFactory().getCompiler().getPartialDerivativeIndex(1, 1, 0);
  94.         final int idXZ = potential.getFactory().getCompiler().getPartialDerivativeIndex(1, 0, 1);
  95.         final int idYY = potential.getFactory().getCompiler().getPartialDerivativeIndex(0, 2, 0);
  96.         final int idYZ = potential.getFactory().getCompiler().getPartialDerivativeIndex(0, 1, 1);
  97.         final int idZZ = potential.getFactory().getCompiler().getPartialDerivativeIndex(0, 0, 2);

  98.         // New Jacobian values
  99.         jacobian[3][0] = dU[idXX];
  100.         jacobian[4][1] = dU[idYY];
  101.         jacobian[5][2] = dU[idZZ];
  102.         jacobian[3][1] = dU[idXY];
  103.         jacobian[4][0] = jacobian[3][1];
  104.         jacobian[3][2] = dU[idXZ];
  105.         jacobian[5][0] = jacobian[3][2];
  106.         jacobian[4][2] = dU[idYZ];
  107.         jacobian[5][1] = jacobian[4][2];

  108.         // STM derivatives computation : dPhi = Jacobian * Phi if both dPhi and Phi are defined as Matrix
  109.         for (int k = 0; k < DIM; k++) {
  110.             for (int l = 0; l < DIM; l++) {
  111.                 for (int i = 0; i < DIM; i++) {
  112.                     dPhi[DIM * k + l] =
  113.                         dPhi[DIM * k + l] + jacobian[k][i] * phi[DIM * i + l];
  114.                 }
  115.             }
  116.         }

  117.         return dPhi;

  118.     }

  119.     /** {@inheritDoc} */
  120.     public String getName() {
  121.         return name;
  122.     }

  123.     /** {@inheritDoc} */
  124.     @Override
  125.     public int getDimension() {
  126.         return DIM * DIM;
  127.     }

  128.     /** Method returning the State Transition Matrix.
  129.      * @param s SpacecraftState of the system
  130.      * @return phiM State Transition Matrix
  131.      */
  132.     public RealMatrix getStateTransitionMatrix(final SpacecraftState s) {
  133.         final double[][] phi2dA = new double[DIM][DIM];
  134.         final double[] stm = s.getAdditionalState(getName());
  135.         for (int i = 0; i < DIM; i++) {
  136.             for (int j = 0; j < 6; j++) {
  137.                 phi2dA[i][j] = stm[DIM * i + j];
  138.             }
  139.         }
  140.         return new Array2DRowRealMatrix(phi2dA, false);
  141.     }
  142. }