IntegrableJacobianColumnGenerator.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.orekit.propagation.SpacecraftState;
  19. import org.orekit.propagation.integration.AdditionalDerivativesProvider;
  20. import org.orekit.propagation.integration.CombinedDerivatives;

  21. /** Generator for one column of a Jacobian matrix.
  22.  * <p>
  23.  * This generator is based on variational equations, so
  24.  * it implements {@link AdditionalDerivativesProvider} and
  25.  * computes only the derivative of the Jacobian column, to
  26.  * be integrated by the propagator alongside the primary state.
  27.  * </p>
  28.  * @author Luc Maisonobe
  29.  * @since 11.1
  30.  */
  31. class IntegrableJacobianColumnGenerator
  32.     implements AdditionalDerivativesProvider, AbstractStateTransitionMatrixGenerator.PartialsObserver {

  33.     /** Name of the state for State Transition Matrix. */
  34.     private final String stmName;

  35.     /** Name of the parameter corresponding to the column. */
  36.     private final String columnName;

  37.     /** Last value computed for the partial derivatives. */
  38.     private final double[] pDot;

  39.     /** Simple constructor.
  40.      * <p>
  41.      * The generator for State Transition Matrix <em>must</em> be registered as
  42.      * an integrable generator to the same propagator as the instance, as it
  43.      * must be scheduled to update the state before the instance
  44.      * </p>
  45.      * @param stmGenerator generator for State Transition Matrix
  46.      * @param columnName name of the parameter corresponding to the column
  47.      * @param isMassIncluded flag to consider mass as a state variable
  48.      */
  49.     IntegrableJacobianColumnGenerator(final AbstractStateTransitionMatrixGenerator stmGenerator,
  50.                                       final String columnName, final boolean isMassIncluded) {
  51.         this.stmName    = stmGenerator.getName();
  52.         this.columnName = columnName;
  53.         this.pDot       = new double[isMassIncluded ? 7 : 6];
  54.         stmGenerator.addObserver(columnName, this);
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public String getName() {
  59.         return columnName;
  60.     }

  61.     /** Get the dimension of the generated column.
  62.      * @return dimension of the generated column
  63.      */
  64.     public int getDimension() {
  65.         return pDot.length;
  66.     }

  67.     /** {@inheritDoc}
  68.      * <p>
  69.      * The column derivative can be computed only if the State Transition Matrix derivatives
  70.      * are available, as it implies the STM generator has already been run.
  71.      * </p>
  72.      */
  73.     @Override
  74.     public boolean yields(final SpacecraftState state) {
  75.         return !state.hasAdditionalStateDerivative(stmName);
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     public void partialsComputed(final SpacecraftState state, final double[] factor, final double[] partials) {
  80.         // retrieve current Jacobian column
  81.         final double[] p = state.getAdditionalState(getName());

  82.         // compute time derivative of the Jacobian column
  83.         if (getDimension() == 7) {
  84.             ExtendedStateTransitionMatrixGenerator.staticMultiplyMatrix(factor, p, pDot, 1);
  85.         } else {
  86.             StateTransitionMatrixGenerator.staticMultiplyMatrix(factor, p, pDot, 1);
  87.         }
  88.         for (int i = 0; i < partials.length; i++) {
  89.             pDot[i + 3] += partials[i];
  90.         }
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public CombinedDerivatives combinedDerivatives(final SpacecraftState s) {
  95.         return new CombinedDerivatives(pDot, null);
  96.     }

  97. }