AbstractCartesianAdjointNonCentralBodyTerm.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.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.MathArrays;
  22. import org.orekit.frames.Frame;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.FieldAbsoluteDate;
  25. import org.orekit.utils.ExtendedPositionProvider;

  26. /**
  27.  * Abstract class defining the contributions of a point-mass, single body gravity in the adjoint equations for Cartesian coordinates.
  28.  * @author Romain Serra
  29.  * @see CartesianAdjointEquationTerm
  30.  * @since 12.2
  31.  */
  32. public abstract class AbstractCartesianAdjointNonCentralBodyTerm extends AbstractCartesianAdjointNewtonianTerm {

  33.     /** Extended position provider for the body. */
  34.     private final ExtendedPositionProvider bodyPositionProvider;

  35.     /**
  36.      * Constructor.
  37.      * @param mu body gravitational parameter.
  38.      * @param bodyPositionProvider body position provider
  39.      */
  40.     protected AbstractCartesianAdjointNonCentralBodyTerm(final double mu,
  41.                                                          final ExtendedPositionProvider bodyPositionProvider) {
  42.         super(mu);
  43.         this.bodyPositionProvider = bodyPositionProvider;
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public double[] getPositionAdjointContribution(final AbsoluteDate date, final double[] stateVariables,
  48.                                                    final double[] adjointVariables, final Frame frame) {
  49.         return getNewtonianVelocityAdjointContribution(formRelativePosition(date, stateVariables, frame),
  50.             adjointVariables);
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public <T extends CalculusFieldElement<T>> T[] getPositionAdjointFieldContribution(final FieldAbsoluteDate<T> date,
  55.                                                                                        final T[] stateVariables,
  56.                                                                                        final T[] adjointVariables,
  57.                                                                                        final Frame frame) {
  58.         return getFieldNewtonianVelocityAdjointContribution(formFieldRelativePosition(date, stateVariables, frame),
  59.             adjointVariables);
  60.     }

  61.     /**
  62.      * Get body's position.
  63.      * @param date date
  64.      * @param frame frame
  65.      * @return position vector
  66.      */
  67.     protected Vector3D getBodyPosition(final AbsoluteDate date, final Frame frame) {
  68.         return bodyPositionProvider.getPosition(date, frame);
  69.     }

  70.     /**
  71.      * Get body's position.
  72.      * @param <T> field type
  73.      * @param date date
  74.      * @param frame frame
  75.      * @return position vector
  76.      */
  77.     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getFieldBodyPosition(final FieldAbsoluteDate<T> date,
  78.                                                                                         final Frame frame) {
  79.         return bodyPositionProvider.getPosition(date, frame);
  80.     }

  81.     /**
  82.      * Form relative position vector w.r.t. body.
  83.      * @param date date
  84.      * @param stateVariables Cartesian variables
  85.      * @param frame frame where Cartesian coordinates apply
  86.      * @return relative position vector as array
  87.      */
  88.     protected double[] formRelativePosition(final AbsoluteDate date, final double[] stateVariables, final Frame frame) {
  89.         final Vector3D bodyPosition = getBodyPosition(date, frame);
  90.         final double x = stateVariables[0] - bodyPosition.getX();
  91.         final double y = stateVariables[1] - bodyPosition.getY();
  92.         final double z = stateVariables[2] - bodyPosition.getZ();
  93.         return new double[] { x, y, z };
  94.     }

  95.     /**
  96.      * Form relative position vector w.r.t. body.
  97.      * @param date date
  98.      * @param stateVariables Cartesian variables
  99.      * @param frame frame where Cartesian coordinates apply
  100.      * @param <T> field type
  101.      * @return relative position vector as array
  102.      */
  103.     protected <T extends CalculusFieldElement<T>> T[] formFieldRelativePosition(final FieldAbsoluteDate<T> date,
  104.                                                                               final T[] stateVariables,
  105.                                                                               final Frame frame) {
  106.         final FieldVector3D<T> bodyPosition = getFieldBodyPosition(date, frame);
  107.         final T x = stateVariables[0].subtract(bodyPosition.getX());
  108.         final T y = stateVariables[1].subtract(bodyPosition.getY());
  109.         final T z = stateVariables[2].subtract(bodyPosition.getZ());
  110.         final T[] relativePosition = MathArrays.buildArray(date.getField(), 3);
  111.         relativePosition[0] = x;
  112.         relativePosition[1] = y;
  113.         relativePosition[2] = z;
  114.         return relativePosition;
  115.     }
  116. }