SingleBodyAbsoluteAttraction.java

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

  58.     /** Simple constructor.
  59.      * @param body the body to consider
  60.      * (ex: {@link CelestialBodies#getSun()} or
  61.      * {@link CelestialBodies#getMoon()})
  62.      */
  63.     public SingleBodyAbsoluteAttraction(final CelestialBody body) {
  64.         super(body);
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  69.         // compute bodies separation vectors and squared norm
  70.         final Vector3D bodyPosition = getBody().getPosition(s.getDate(), s.getFrame());
  71.         final Vector3D satToBody     = bodyPosition.subtract(s.getPosition());
  72.         final double r2Sat           = satToBody.getNormSq();

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

  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  79.                                                                              final T[] parameters) {
  80.          // compute bodies separation vectors and squared norm
  81.         final FieldVector3D<T> centralToBody = getBody().getPosition(s.getDate(), s.getFrame());
  82.         final FieldVector3D<T> satToBody     = centralToBody.subtract(s.getPosition());
  83.         final T                r2Sat         = satToBody.getNormSq();

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

  86.     }

  87. }