AbstractGradientConverter.java

  1. /* Copyright 2002-2021 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 org.hipparchus.analysis.differentiation.Gradient;
  19. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;

  21. /** Converter for states and parameters arrays.
  22.  *  @author Luc Maisonobe
  23.  *  @author Bryan Cazabonne
  24.  *  @since 10.2
  25.  */
  26. public abstract class AbstractGradientConverter {

  27.     /** Dimension of the state. */
  28.     private final int freeStateParameters;

  29.     /** Simple constructor.
  30.      * @param freeStateParameters number of free parameters
  31.      */
  32.     protected AbstractGradientConverter(final int freeStateParameters) {
  33.         this.freeStateParameters = freeStateParameters;
  34.     }

  35.     /** Get the number of free state parameters.
  36.      * @return number of free state parameters
  37.      */
  38.     public int getFreeStateParameters() {
  39.         return freeStateParameters;
  40.     }

  41.     /** Add zero derivatives.
  42.      * @param original original scalar
  43.      * @param freeParameters total number of free parameters in the gradient
  44.      * @return extended scalar
  45.      */
  46.     protected Gradient extend(final Gradient original, final int freeParameters) {
  47.         final double[] originalDerivatives = original.getGradient();
  48.         final double[] extendedDerivatives = new double[freeParameters];
  49.         System.arraycopy(originalDerivatives, 0, extendedDerivatives, 0, originalDerivatives.length);
  50.         return new Gradient(original.getValue(), extendedDerivatives);
  51.     }

  52.     /** Add zero derivatives.
  53.      * @param original original vector
  54.      * @param freeParameters total number of free parameters in the gradient
  55.      * @return extended vector
  56.      */
  57.     protected FieldVector3D<Gradient> extend(final FieldVector3D<Gradient> original, final int freeParameters) {
  58.         return new FieldVector3D<>(extend(original.getX(), freeParameters),
  59.                                    extend(original.getY(), freeParameters),
  60.                                    extend(original.getZ(), freeParameters));
  61.     }

  62.     /** Add zero derivatives.
  63.      * @param original original rotation
  64.      * @param freeParameters total number of free parameters in the gradient
  65.      * @return extended rotation
  66.      */
  67.     protected FieldRotation<Gradient> extend(final FieldRotation<Gradient> original, final int freeParameters) {
  68.         return new FieldRotation<>(extend(original.getQ0(), freeParameters),
  69.                                    extend(original.getQ1(), freeParameters),
  70.                                    extend(original.getQ2(), freeParameters),
  71.                                    extend(original.getQ3(), freeParameters),
  72.                                    false);
  73.     }
  74. }