AbstractJacobiansMapper.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.integration;

  18. import java.util.List;
  19. import java.util.stream.Collectors;

  20. import org.hipparchus.linear.Array2DRowRealMatrix;
  21. import org.hipparchus.linear.RealMatrix;
  22. import org.orekit.propagation.MatricesHarvester;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.utils.ParameterDriversList;

  25. /** Base class for jacobian mapper.
  26.  * @author Bryan Cazabonne
  27.  * @since 10.0
  28.  */
  29. public abstract class AbstractJacobiansMapper implements MatricesHarvester {

  30.     /** State dimension, fixed to 6.
  31.      * @since 9.0
  32.      */
  33.     public static final int STATE_DIMENSION = 6;

  34.     /** Name. */
  35.     private String name;

  36.     /** Selected parameters for Jacobian computation. */
  37.     private final ParameterDriversList parameters;

  38.     /** Simple constructor.
  39.      * @param name name of the Jacobians
  40.      * @param parameters selected parameters for Jacobian computation
  41.      */
  42.     protected AbstractJacobiansMapper(final String name, final ParameterDriversList parameters) {
  43.         this.name       = name;
  44.         this.parameters = parameters;
  45.     }

  46.     /** Get the name of the partial Jacobians.
  47.      * @return name of the Jacobians
  48.      */
  49.     public String getName() {
  50.         return name;
  51.     }

  52.     /** Get the number of parameters.
  53.      * @return number of parameters
  54.      */
  55.     public int getParameters() {
  56.         return parameters.getNbParams();
  57.     }

  58.     /** Compute the length of the one-dimensional additional state array needed.
  59.      * @return length of the one-dimensional additional state array
  60.      */
  61.     public int getAdditionalStateDimension() {
  62.         return STATE_DIMENSION * (STATE_DIMENSION + parameters.getNbParams());
  63.     }

  64.     /** Not used anymore.
  65.      * @param s spacecraft state
  66.      * @deprecated as of 11.1, not used anymore
  67.      */
  68.     @Deprecated
  69.     public void analyticalDerivatives(final SpacecraftState s) {
  70.         // nothing by default
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public void setReferenceState(final SpacecraftState reference) {
  75.         // nothing by default
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     public RealMatrix getStateTransitionMatrix(final SpacecraftState s) {
  80.         final double[][] dYdY0 = new double[STATE_DIMENSION][STATE_DIMENSION];
  81.         getStateJacobian(s, dYdY0);
  82.         return new Array2DRowRealMatrix(dYdY0, false);
  83.     }

  84.     /** {@inheritDoc} */
  85.     @Override
  86.     public RealMatrix getParametersJacobian(final SpacecraftState s) {
  87.         if (getParameters() == 0) {
  88.             return null;
  89.         } else {
  90.             final double[][] dYdP = new double[STATE_DIMENSION][getParameters()];
  91.             getParametersJacobian(s, dYdP);
  92.             return new Array2DRowRealMatrix(dYdP, false);
  93.         }
  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     public List<String> getJacobiansColumnsNames() {
  98.         return parameters.getDrivers().stream().map(d -> d.getName()).collect(Collectors.toList());
  99.     }

  100.     /** Set the Jacobian with respect to state into a one-dimensional additional state array.
  101.      * @param state spacecraft state
  102.      * @param dY1dY0 Jacobian of current state at time t₁
  103.      * with respect to state at some previous time t₀
  104.      * @param dY1dP Jacobian of current state at time t₁
  105.      * with respect to parameters (may be null if there are no parameters)
  106.      * @param p placeholder where to put the one-dimensional additional state
  107.      * @see #getStateJacobian(SpacecraftState, double[][])
  108.      */
  109.     public abstract void setInitialJacobians(SpacecraftState state, double[][] dY1dY0, double[][] dY1dP, double[] p);

  110.     /** Get the Jacobian with respect to state from a one-dimensional additional state array.
  111.      * <p>
  112.      * This method extract the data from the {@code state} and put it in the
  113.      * {@code dYdY0} array.
  114.      * <p>
  115.      * @param state spacecraft state
  116.      * @param dYdY0 placeholder where to put the Jacobian with respect to state
  117.      * @see #getParametersJacobian(SpacecraftState, double[][])
  118.      */
  119.     public abstract void getStateJacobian(SpacecraftState state, double[][] dYdY0);

  120.     /** Get the Jacobian with respect to parameters from a one-dimensional additional state array.
  121.      * <p>
  122.      * This method extract the data from the {@code state} and put it in the
  123.      * {@code dYdP} array.
  124.      * </p>
  125.      * <p>
  126.      * If no parameters have been set in the constructor, the method returns immediately and
  127.      * does not reference {@code dYdP} which can safely be null in this case.
  128.      * </p>
  129.      * @param state spacecraft state
  130.      * @param dYdP placeholder where to put the Jacobian with respect to parameters
  131.      * @see #getStateJacobian(SpacecraftState, double[][])
  132.      */
  133.     public abstract void getParametersJacobian(SpacecraftState state, double[][] dYdP);

  134. }