NumericalPropagationHarvester.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 java.util.List;

  19. import org.hipparchus.linear.MatrixUtils;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.orekit.orbits.Orbit;
  22. import org.orekit.orbits.OrbitType;
  23. import org.orekit.orbits.PositionAngleType;
  24. import org.orekit.propagation.AbstractMatricesHarvester;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.utils.DoubleArrayDictionary;

  27. /** Harvester between two-dimensional Jacobian matrices and one-dimensional {@link
  28.  * SpacecraftState#getAdditionalState(String) additional state arrays}.
  29.  * @author Luc Maisonobe
  30.  * @since 11.1
  31.  */
  32. class NumericalPropagationHarvester extends AbstractMatricesHarvester {

  33.     /** Propagator bound to this harvester. */
  34.     private final NumericalPropagator propagator;

  35.     /** Columns names for parameters. */
  36.     private List<String> columnsNames;

  37.     /** Simple constructor.
  38.      * <p>
  39.      * The arguments for initial matrices <em>must</em> be compatible with the {@link org.orekit.orbits.OrbitType orbit type}
  40.      * and {@link PositionAngleType position angle} that will be used by propagator
  41.      * </p>
  42.      * <p>
  43.      * If the initial matrix is 7x7, it means that the mass is considered as being a state variable.
  44.      * </p>
  45.      * @param propagator propagator bound to this harvester
  46.      * @param stmName State Transition Matrix state name
  47.      * @param initialStm initial State Transition Matrix ∂Y/∂Y₀,
  48.      * if null (which is the most frequent case), assumed to be 6x6 identity
  49.      * @param initialJacobianColumns initial columns of the Jacobians matrix with respect to parameters,
  50.      * if null or if some selected parameters are missing from the dictionary, the corresponding
  51.      * initial column is assumed to be 0
  52.      */
  53.     NumericalPropagationHarvester(final NumericalPropagator propagator, final String stmName,
  54.                                   final RealMatrix initialStm, final DoubleArrayDictionary initialJacobianColumns) {
  55.         super(stmName, initialStm, initialJacobianColumns);
  56.         this.propagator   = propagator;
  57.         this.columnsNames = null;
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     protected double[][] getConversionJacobian(final SpacecraftState state) {

  62.         final double[][] identity = super.getConversionJacobian(state);

  63.         if (state.isOrbitDefined() && state.getOrbit().getType() != OrbitType.CARTESIAN) {
  64.             // make sure the state is in the desired orbit type
  65.             final Orbit orbit = propagator.getOrbitType().convertType(state.getOrbit());

  66.             // compute the Jacobian, taking the position angle type into account
  67.             final double[][] dYdC = new double[identity.length][identity[0].length];
  68.             orbit.getJacobianWrtCartesian(propagator.getPositionAngleType(), dYdC);
  69.             return dYdC;
  70.         } else {
  71.             return identity;
  72.         }

  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public void freezeColumnsNames() {
  77.         columnsNames = getJacobiansColumnsNames();
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public List<String> getJacobiansColumnsNames() {
  82.         return columnsNames == null ? propagator.getJacobiansColumnsNames() : columnsNames;
  83.     }

  84.     /** {@inheritDoc} */
  85.     @Override
  86.     public OrbitType getOrbitType() {
  87.         return propagator.getOrbitType();
  88.     }

  89.     /** {@inheritDoc} */
  90.     @Override
  91.     public PositionAngleType getPositionAngleType() {
  92.         return propagator.getPositionAngleType();
  93.     }

  94.     /** {@inheritDoc} */
  95.     @Override
  96.     public RealMatrix getStateTransitionMatrix(final SpacecraftState state) {

  97.         if (!state.hasAdditionalData(getStmName())) {
  98.             return null;
  99.         }

  100.         // extract the additional state
  101.         final double[] p = state.getAdditionalState(getStmName());
  102.         final RealMatrix  dCdY0 = toSquareMatrix(p);

  103.         final RealMatrix  dYdY0;
  104.         if (!state.isOrbitDefined() || state.getOrbit().getType() == OrbitType.CARTESIAN) {
  105.             dYdY0 = dCdY0;
  106.         } else {
  107.             // get the conversion Jacobian
  108.             final RealMatrix dYdC = MatrixUtils.createRealIdentityMatrix(getStateDimension());
  109.             dYdC.setSubMatrix(getConversionJacobian(state), 0, 0);

  110.             // compute dYdC * dCdY0
  111.             dYdY0 = dYdC.multiply(dCdY0);
  112.         }

  113.         return dYdY0;

  114.     }

  115. }