TLEPartialDerivativesEquations.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.analytical.tle;

  18. import org.orekit.errors.OrekitException;
  19. import org.orekit.errors.OrekitMessages;
  20. import org.orekit.propagation.SpacecraftState;
  21. import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
  22. import org.orekit.utils.ParameterDriver;
  23. import org.orekit.utils.ParameterDriversList;

  24. /** Set of additional equations computing the partial derivatives
  25.  * of the state (orbit) with respect to initial state.
  26.  * <p>
  27.  * This set of equations are automatically added to an {@link AbstractAnalyticalPropagator analytical propagator}
  28.  * in order to compute partial derivatives of the orbit along with the orbit itself. This is
  29.  * useful for example in orbit determination applications.
  30.  * </p>
  31.  * <p>
  32.  * The partial derivatives with respect to initial state are dimension 6 (orbit only).
  33.  * </p>
  34.  * @author Bryan Cazabonne
  35.  * @author Thomas Paulet
  36.  * @since 11.0
  37.  */
  38. @Deprecated
  39. public class TLEPartialDerivativesEquations {

  40.     /** Propagator computing state evolution. */
  41.     private final TLEPropagator propagator;

  42.     /** Selected parameters for Jacobian computation. */
  43.     private ParameterDriversList selected;

  44.     /** Name. */
  45.     private final String name;

  46.     /** Flag for Jacobian matrices initialization. */
  47.     private boolean initialized;

  48.     /** Simple constructor.
  49.      * <p>
  50.      * Instance regrouping equations to compute derivatives.
  51.      * </p>
  52.      * @param name name of the partial derivatives equations
  53.      * @param propagator the propagator that will handle the orbit propagation
  54.      */
  55.     public TLEPartialDerivativesEquations(final String name,
  56.                                           final TLEPropagator propagator) {
  57.         this.name        = name;
  58.         this.selected    = null;
  59.         this.propagator  = propagator;
  60.         this.initialized = false;
  61.     }

  62.     /** Get the name of the additional state.
  63.      * @return name of the additional state
  64.      */
  65.     public String getName() {
  66.         return name;
  67.     }

  68.     /** Freeze the selected parameters from the force models.
  69.      */
  70.     private void freezeParametersSelection() {
  71.         if (selected == null) {
  72.             // create new selected parameter driver list
  73.             selected = new ParameterDriversList();
  74.             for (final ParameterDriver driver : propagator.getTLE().getParametersDrivers()) {
  75.                 if (driver.isSelected()) {
  76.                     selected.add(driver);
  77.                 }
  78.             }
  79.         }
  80.     }

  81.     /** Set the initial value of the Jacobian with respect to state and parameter.
  82.      * <p>
  83.      * This method is equivalent to call {@link #setInitialJacobians(SpacecraftState,
  84.      * double[][], double[][])} with dYdY0 set to the identity matrix and dYdP set
  85.      * to a zero matrix.
  86.      * </p>
  87.      * <p>
  88.      * The force models parameters for which partial derivatives are desired,
  89.      * <em>must</em> have been {@link ParameterDriver#setSelected(boolean) selected}
  90.      * before this method is called, so proper matrices dimensions are used.
  91.      * </p>
  92.      * @param s0 initial state
  93.      * @return state with initial Jacobians added
  94.      */
  95.     public SpacecraftState setInitialJacobians(final SpacecraftState s0) {
  96.         freezeParametersSelection();
  97.         final int stateDimension = 6;
  98.         final double[][] dYdY0 = new double[stateDimension][stateDimension];
  99.         final double[][] dYdP  = new double[stateDimension][selected.getNbParams()];
  100.         for (int i = 0; i < stateDimension; ++i) {
  101.             dYdY0[i][i] = 1.0;
  102.         }
  103.         return setInitialJacobians(s0, dYdY0, dYdP);
  104.     }

  105.     /** Set the initial value of the Jacobian with respect to state and parameter.
  106.      * <p>
  107.      * The returned state must be added to the propagator (it is not done
  108.      * automatically, as the user may need to add more states to it).
  109.      * </p>
  110.      * @param s1 current state
  111.      * @param dY1dY0 Jacobian of current state at time t₁ with respect
  112.      * to state at some previous time t₀ (must be 6x6)
  113.      * @param dY1dP Jacobian of current state at time t₁ with respect
  114.      * to parameters (may be null if no parameters are selected)
  115.      * @return state with initial Jacobians added
  116.      */
  117.     public SpacecraftState setInitialJacobians(final SpacecraftState s1,
  118.                                                final double[][] dY1dY0, final double[][] dY1dP) {

  119.         freezeParametersSelection();

  120.         // Check dimensions
  121.         final int stateDim = dY1dY0.length;
  122.         if (stateDim != 6 || stateDim != dY1dY0[0].length) {
  123.             throw new OrekitException(OrekitMessages.STATE_JACOBIAN_NOT_6X6,
  124.                                       stateDim, dY1dY0[0].length);
  125.         }
  126.         if (dY1dP != null && stateDim != dY1dP.length) {
  127.             throw new OrekitException(OrekitMessages.STATE_AND_PARAMETERS_JACOBIANS_ROWS_MISMATCH,
  128.                                       stateDim, dY1dP.length);
  129.         }
  130.         if (dY1dP == null && selected.getNbParams() != 0 ||
  131.             dY1dP != null && selected.getNbParams() != dY1dP[0].length) {
  132.             throw new OrekitException(new OrekitException(OrekitMessages.INITIAL_MATRIX_AND_PARAMETERS_NUMBER_MISMATCH,
  133.                                                           dY1dP == null ? 0 : dY1dP[0].length, selected.getNbParams()));
  134.         }

  135.         // store the matrices as a single dimension array
  136.         initialized = true;
  137.         final TLEJacobiansMapper mapper = getMapper();
  138.         final double[] p = new double[mapper.getAdditionalStateDimension()];
  139.         mapper.setInitialJacobians(s1, dY1dY0, dY1dP, p);

  140.         // set value in propagator
  141.         return s1.addAdditionalState(name, p);

  142.     }

  143.     /** Get a mapper between two-dimensional Jacobians and one-dimensional additional state.
  144.      * @return a mapper between two-dimensional Jacobians and one-dimensional additional state,
  145.      * with the same name as the instance
  146.      * @see #setInitialJacobians(SpacecraftState)
  147.      * @see #setInitialJacobians(SpacecraftState, double[][], double[][])
  148.      */
  149.     public TLEJacobiansMapper getMapper() {
  150.         if (!initialized) {
  151.             throw new OrekitException(OrekitMessages.STATE_JACOBIAN_NOT_INITIALIZED);
  152.         }
  153.         return new TLEJacobiansMapper(name, selected, propagator);
  154.     }

  155. }