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 java.util.Collections;
  19. import java.util.List;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.hipparchus.util.FastMath;
  24. import org.orekit.bodies.CelestialBodies;
  25. import org.orekit.bodies.CelestialBody;
  26. import org.orekit.forces.ForceModel;
  27. import org.orekit.propagation.FieldSpacecraftState;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.utils.ParameterDriver;

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

  62.     /** Suffix for parameter name for attraction coefficient enabling Jacobian processing. */
  63.     public static final String ATTRACTION_COEFFICIENT_SUFFIX = " attraction coefficient";

  64.     /** Central attraction scaling factor.
  65.      * <p>
  66.      * We use a power of 2 to avoid numeric noise introduction
  67.      * in the multiplications/divisions sequences.
  68.      * </p>
  69.      */
  70.     private static final double MU_SCALE = FastMath.scalb(1.0, 32);

  71.     /** The body to consider. */
  72.     private final CelestialBody body;

  73.     /** Driver for gravitational parameter. */
  74.     private final ParameterDriver gmParameterDriver;

  75.     /** Simple constructor.
  76.      * @param body the body to consider
  77.      * (ex: {@link CelestialBodies#getSun()} or
  78.      * {@link CelestialBodies#getMoon()})
  79.      */
  80.     public SingleBodyAbsoluteAttraction(final CelestialBody body) {
  81.         gmParameterDriver = new ParameterDriver(body.getName() + ATTRACTION_COEFFICIENT_SUFFIX,
  82.                                                 body.getGM(), MU_SCALE,
  83.                                                 0.0, Double.POSITIVE_INFINITY);

  84.         this.body = body;
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public boolean dependsOnPositionOnly() {
  89.         return true;
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  94.         // compute bodies separation vectors and squared norm
  95.         final Vector3D bodyPosition = body.getPosition(s.getDate(), s.getFrame());
  96.         final Vector3D satToBody     = bodyPosition.subtract(s.getPosition());
  97.         final double r2Sat           = satToBody.getNormSq();

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

  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  104.                                                                          final T[] parameters) {
  105.          // compute bodies separation vectors and squared norm
  106.         final FieldVector3D<T> centralToBody = body.getPosition(s.getDate(), s.getFrame());
  107.         final FieldVector3D<T> satToBody     = centralToBody.subtract(s.getPosition());
  108.         final T                r2Sat         = satToBody.getNormSq();

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

  111.     }

  112.     /** {@inheritDoc} */
  113.     public List<ParameterDriver> getParametersDrivers() {
  114.         return Collections.singletonList(gmParameterDriver);
  115.     }

  116. }