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

  28. /** Body attraction force model computed as relative acceleration towards frame center.
  29.  * @author Luc Maisonabe
  30.  * @author Julio Hernanz
  31.  */
  32. public class SingleBodyRelativeAttraction extends AbstractBodyAttraction {

  33.     /** Simple constructor.
  34.      * @param positionProvider extended position provider for the body to consider
  35.      * @param name name of the body
  36.      * @param mu body gravitational constant
  37.      * @since 13.0
  38.      */
  39.     public SingleBodyRelativeAttraction(final ExtendedPositionProvider positionProvider, final String name,
  40.                                         final double mu) {
  41.         super(positionProvider, name, mu);
  42.     }

  43.     /** Constructor.
  44.      * @param body the body to consider
  45.      * (ex: {@link CelestialBodies#getSun()} or
  46.      * {@link CelestialBodies#getMoon()})
  47.      */
  48.     public SingleBodyRelativeAttraction(final CelestialBody body) {
  49.         this(body, body.getName(), body.getGM());
  50.     }

  51.     /** {@inheritDoc} */
  52.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  53.         // compute bodies separation vectors and squared norm
  54.         final PVCoordinates bodyPV   = getBodyPVCoordinates(s.getDate(), s.getFrame());
  55.         final Vector3D satToBody     = bodyPV.getPosition().subtract(s.getPosition());
  56.         final double r2Sat           = satToBody.getNormSq();

  57.         // compute relative acceleration
  58.         final double gm = parameters[0];
  59.         final double a = gm / r2Sat;
  60.         return new Vector3D(a, satToBody.normalize()).add(bodyPV.getAcceleration());

  61.     }

  62.     /** {@inheritDoc} */
  63.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  64.                                                                          final T[] parameters) {

  65.         // compute bodies separation vectors and squared norm
  66.         final FieldPVCoordinates<T> bodyPV = getBodyPVCoordinates(s.getDate(), s.getFrame());
  67.         final FieldVector3D<T> satToBody   = bodyPV.getPosition().subtract(s.getPosition());
  68.         final T                r2Sat       = satToBody.getNormSq();

  69.         // compute relative acceleration
  70.         final T gm = parameters[0];
  71.         final T a  = gm.divide(r2Sat);
  72.         return new FieldVector3D<>(a, satToBody.normalize()).add(bodyPV.getAcceleration());

  73.     }

  74. }