SingleBodyAbsoluteAttraction.java

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

  19. import org.hipparchus.Field;
  20. import org.hipparchus.RealFieldElement;
  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.AbstractForceModel;
  27. import org.orekit.propagation.FieldSpacecraftState;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.propagation.events.EventDetector;
  30. import org.orekit.propagation.events.FieldEventDetector;
  31. import org.orekit.utils.ParameterDriver;

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

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

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

  73.     /** The body to consider. */
  74.     private final CelestialBody body;

  75.     /** Driver for gravitational parameter. */
  76.     private final ParameterDriver gmParameterDriver;

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

  86.         this.body = body;
  87.     }

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

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

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

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

  102.     }

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

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

  114.     }

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

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

  124.     /** {@inheritDoc} */
  125.     public ParameterDriver[] getParametersDrivers() {
  126.         return new ParameterDriver[] {
  127.             gmParameterDriver
  128.         };
  129.     }

  130. }