SingleBodyAbsoluteAttraction.java

  1. /* Copyright 2002-2025 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.forces.gravity;

  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.orekit.bodies.CelestialBodies;
  23. import org.orekit.bodies.CelestialBody;
  24. import org.orekit.propagation.FieldSpacecraftState;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.utils.ExtendedPositionProvider;

  27. /** Body attraction force model computed as absolute acceleration towards a body.
  28.  * <p>
  29.  * This force model represents the same physical principles as {@link NewtonianAttraction},
  30.  * but has several major differences:
  31.  * </p>
  32.  * <ul>
  33.  *   <li>the attracting body can be <em>away</em> from the integration frame center,</li>
  34.  *   <li>several instances of this force model can be added when several bodies are involved,</li>
  35.  *   <li>this force model is <em>never</em> automatically added by the numerical propagator</li>
  36.  * </ul>
  37.  * <p>
  38.  * The possibility for the attracting body to be away from the frame center allows to use this force
  39.  * model when integrating for example an interplanetary trajectory propagated in an Earth centered
  40.  * frame (in which case an instance of {@link org.orekit.forces.inertia.InertialForces} must also be
  41.  * added to take into account the coupling effect of relative frames motion).
  42.  * </p>
  43.  * <p>
  44.  * The possibility to add several instances allows to use this in interplanetary trajectories or
  45.  * in trajectories about Lagrangian points
  46.  * </p>
  47.  * <p>
  48.  * The fact this force model is <em>never</em> automatically added by the numerical propagator differs
  49.  * from {@link NewtonianAttraction} as {@link NewtonianAttraction} may be added automatically when
  50.  * propagating a trajectory represented as an {@link org.orekit.orbits.Orbit}, which must always refer
  51.  * to a central body, if user did not add the {@link NewtonianAttraction} or set the central attraction
  52.  * coefficient by himself.
  53.  * </p>
  54.  * @see org.orekit.forces.inertia.InertialForces
  55.  * @author Luc Maisonobe
  56.  * @author Julio Hernanz
  57.  */
  58. public class SingleBodyAbsoluteAttraction extends AbstractBodyAttraction {

  59.     /** Simple constructor.
  60.      * @param positionProvider extended position provider for the body to consider
  61.      * @param name name of the body
  62.      * @param mu body gravitational constant
  63.      * @since 13.0
  64.      */
  65.     public SingleBodyAbsoluteAttraction(final ExtendedPositionProvider positionProvider,
  66.                                         final String name, final double mu) {
  67.         super(positionProvider, name, mu);
  68.     }

  69.     /** Constructor.
  70.      * @param body the body to consider
  71.      * (ex: {@link CelestialBodies#getSun()} or
  72.      * {@link CelestialBodies#getMoon()})
  73.      */
  74.     public SingleBodyAbsoluteAttraction(final CelestialBody body) {
  75.         this(body, body.getName(), body.getGM());
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  80.         // compute bodies separation vectors and squared norm
  81.         final Vector3D bodyPosition = getBodyPosition(s.getDate(), s.getFrame());
  82.         final Vector3D satToBody     = bodyPosition.subtract(s.getPosition());
  83.         final double r2Sat           = satToBody.getNormSq();

  84.         // compute absolute acceleration
  85.         return new Vector3D(parameters[0] / (r2Sat * FastMath.sqrt(r2Sat)), satToBody);

  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  90.                                                                              final T[] parameters) {
  91.          // compute bodies separation vectors and squared norm
  92.         final FieldVector3D<T> centralToBody = getBodyPosition(s.getDate(), s.getFrame());
  93.         final FieldVector3D<T> satToBody     = centralToBody.subtract(s.getPosition());
  94.         final T                r2Sat         = satToBody.getNormSq();

  95.         // compute absolute acceleration
  96.         return new FieldVector3D<>(parameters[0].divide(r2Sat.multiply(r2Sat.sqrt())), satToBody);

  97.     }

  98. }