CartesianAdjointThirdBodyTerm.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.FastMath;
  22. import org.hipparchus.util.MathArrays;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.FieldAbsoluteDate;
  26. import org.orekit.utils.ExtendedPositionProvider;

  27. /**
  28.  * Class defining the contributions of a point-mass, third body in the adjoint equations for Cartesian coordinates.
  29.  * If present, then the propagator should also include a {@link org.orekit.forces.gravity.ThirdBodyAttraction}.
  30.  * @author Romain Serra
  31.  * @see CartesianAdjointEquationTerm
  32.  * @see org.orekit.forces.gravity.ThirdBodyAttraction
  33.  * @since 12.2
  34.  */
  35. public class CartesianAdjointThirdBodyTerm extends AbstractCartesianAdjointNonCentralBodyTerm {

  36.     /**
  37.      * Constructor.
  38.      * @param mu body gravitational parameter.
  39.      * @param bodyPositionProvider body position provider
  40.      */
  41.     public CartesianAdjointThirdBodyTerm(final double mu, final ExtendedPositionProvider bodyPositionProvider) {
  42.         super(mu, bodyPositionProvider);
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     public Vector3D getAcceleration(final AbsoluteDate date, final double[] stateVariables,
  47.                                     final Frame frame) {
  48.         final Vector3D bodyPosition = getBodyPosition(date, frame);
  49.         final double x = stateVariables[0] - bodyPosition.getX();
  50.         final double y = stateVariables[1] - bodyPosition.getY();
  51.         final double z = stateVariables[2] - bodyPosition.getZ();
  52.         final Vector3D newtonianAcceleration = getNewtonianAcceleration(new double[] {x, y, z});
  53.         final double rBody2 = bodyPosition.getNormSq();
  54.         final Vector3D bodyCentralAcceleration = bodyPosition.scalarMultiply(getMu() / (rBody2 * FastMath.sqrt(rBody2)));
  55.         return newtonianAcceleration.subtract(bodyCentralAcceleration);
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getFieldAcceleration(final FieldAbsoluteDate<T> date,
  60.                                                                                      final T[] stateVariables,
  61.                                                                                      final Frame frame) {
  62.         final FieldVector3D<T> bodyPosition = getFieldBodyPosition(date, frame);
  63.         final T x = stateVariables[0].subtract(bodyPosition.getX());
  64.         final T y = stateVariables[1].subtract(bodyPosition.getY());
  65.         final T z = stateVariables[2].subtract(bodyPosition.getZ());
  66.         final T[] relativePosition = MathArrays.buildArray(date.getField(), 3);
  67.         relativePosition[0] = x;
  68.         relativePosition[1] = y;
  69.         relativePosition[2] = z;
  70.         final FieldVector3D<T> newtonianAcceleration = getFieldNewtonianAcceleration(relativePosition);
  71.         final T rBody2 = bodyPosition.getNormSq();
  72.         final T factor = rBody2.multiply(rBody2.sqrt()).reciprocal().multiply(getMu());
  73.         final FieldVector3D<T> bodyCentralAcceleration = bodyPosition.scalarMultiply(factor);
  74.         return newtonianAcceleration.subtract(bodyCentralAcceleration);
  75.     }
  76. }