AbstractCartesianAdjointGravitationalTerm.java

  1. /* Copyright 2022-2025 Romain Serra
  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.control.indirect.adjoint;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.util.MathArrays;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.time.FieldAbsoluteDate;

  23. /**
  24.  * Abstract class for common computations regarding adjoint dynamics and gravity for Cartesian coordinates.
  25.  *
  26.  * @author Romain Serra
  27.  * @see CartesianAdjointEquationTerm
  28.  * @since 12.2
  29.  */
  30. public abstract class AbstractCartesianAdjointGravitationalTerm extends AbstractCartesianAdjointEquationTerm {

  31.     /** Body gravitational parameter. */
  32.     private final double mu;

  33.     /**
  34.      * Constructor.
  35.      * @param mu body gravitational parameter
  36.      */
  37.     protected AbstractCartesianAdjointGravitationalTerm(final double mu) {
  38.         this.mu = mu;
  39.     }

  40.     /**
  41.      * Getter for the gravitational constant.
  42.      * @return mu
  43.      */
  44.     public double getMu() {
  45.         return mu;
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public double[] getRatesContribution(final AbsoluteDate date, final double[] stateVariables,
  50.                                          final double[] adjointVariables, final Frame frame) {
  51.         final double[] contribution = new double[adjointVariables.length];
  52.         final double[] positionAdjointContribution = getPositionAdjointContribution(date, stateVariables,
  53.             adjointVariables, frame);
  54.         System.arraycopy(positionAdjointContribution, 0, contribution, 0, positionAdjointContribution.length);
  55.         return contribution;
  56.     }

  57.     /**
  58.      * Computes the contribution to position adjoint derivatives.
  59.      *
  60.      * @param date             date
  61.      * @param stateVariables   state variables
  62.      * @param adjointVariables adjoint variables
  63.      * @param frame            propagation frame
  64.      * @return contribution to position adjoint derivatives
  65.      */
  66.     protected abstract double[] getPositionAdjointContribution(AbsoluteDate date, double[] stateVariables,
  67.                                                                double[] adjointVariables, Frame frame);

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public <T extends CalculusFieldElement<T>> T[] getFieldRatesContribution(final FieldAbsoluteDate<T> date,
  71.                                                                              final T[] stateVariables,
  72.                                                                              final T[] adjointVariables, final Frame frame) {
  73.         final T[] contribution = MathArrays.buildArray(date.getField(), adjointVariables.length);
  74.         final T[] positionAdjointFieldContribution = getPositionAdjointFieldContribution(date, stateVariables,
  75.             adjointVariables, frame);
  76.         System.arraycopy(positionAdjointFieldContribution, 0, contribution, 0, positionAdjointFieldContribution.length);
  77.         return contribution;
  78.     }

  79.     /**
  80.      * Computes the contribution to position adjoint derivatives.
  81.      *
  82.      * @param <T>              field type
  83.      * @param date             date
  84.      * @param stateVariables   state variables
  85.      * @param adjointVariables adjoint variables
  86.      * @param frame            propagation frame
  87.      * @return contribution to position adjoint derivatives
  88.      */
  89.     protected abstract <T extends CalculusFieldElement<T>> T[] getPositionAdjointFieldContribution(FieldAbsoluteDate<T> date,
  90.                                                                                                    T[] stateVariables,
  91.                                                                                                    T[] adjointVariables,
  92.                                                                                                    Frame frame);
  93. }