SingleBodyAbsoluteAttraction.java

  1. /* Copyright 2002-2022 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 java.util.stream.Stream;

  21. import org.hipparchus.Field;
  22. import org.hipparchus.CalculusFieldElement;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.hipparchus.util.FastMath;
  26. import org.orekit.bodies.CelestialBodies;
  27. import org.orekit.bodies.CelestialBody;
  28. import org.orekit.forces.AbstractForceModel;
  29. import org.orekit.propagation.FieldSpacecraftState;
  30. import org.orekit.propagation.SpacecraftState;
  31. import org.orekit.propagation.events.EventDetector;
  32. import org.orekit.propagation.events.FieldEventDetector;
  33. import org.orekit.utils.ParameterDriver;

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

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

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

  75.     /** The body to consider. */
  76.     private final CelestialBody body;

  77.     /** Driver for gravitational parameter. */
  78.     private final ParameterDriver gmParameterDriver;

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

  88.         this.body = body;
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     public boolean dependsOnPositionOnly() {
  93.         return true;
  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  98.         // compute bodies separation vectors and squared norm
  99.         final Vector3D bodyPosition = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  100.         final Vector3D satToBody     = bodyPosition.subtract(s.getPVCoordinates().getPosition());
  101.         final double r2Sat           = satToBody.getNormSq();

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

  104.     }

  105.     /** {@inheritDoc} */
  106.     @Override
  107.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  108.                                                                          final T[] parameters) {
  109.          // compute bodies separation vectors and squared norm
  110.         final FieldVector3D<T> centralToBody = new FieldVector3D<>(s.getA().getField(),
  111.                                                                    body.getPVCoordinates(s.getDate().toAbsoluteDate(), s.getFrame()).getPosition());
  112.         final FieldVector3D<T> satToBody     = centralToBody.subtract(s.getPVCoordinates().getPosition());
  113.         final T                r2Sat         = satToBody.getNormSq();

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

  116.     }

  117.     /** {@inheritDoc} */
  118.     public Stream<EventDetector> getEventsDetectors() {
  119.         return Stream.empty();
  120.     }

  121.     @Override
  122.     /** {@inheritDoc} */
  123.     public <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  124.         return Stream.empty();
  125.     }

  126.     /** {@inheritDoc} */
  127.     public List<ParameterDriver> getParametersDrivers() {
  128.         return Collections.singletonList(gmParameterDriver);
  129.     }

  130. }