ThirdBodyAttraction.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. /** Third body attraction force model.
  33.  *
  34.  * @author Fabien Maussion
  35.  * @author Véronique Pommier-Maurussane
  36.  */
  37. public class ThirdBodyAttraction extends AbstractForceModel {

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

  40.     /** Central attraction scaling factor.
  41.      * <p>
  42.      * We use a power of 2 to avoid numeric noise introduction
  43.      * in the multiplications/divisions sequences.
  44.      * </p>
  45.      */
  46.     private static final double MU_SCALE = FastMath.scalb(1.0, 32);

  47.     /** Drivers for third body attraction coefficient. */
  48.     private final ParameterDriver gmParameterDriver;

  49.     /** The body to consider. */
  50.     private final CelestialBody body;

  51.     /** Simple constructor.
  52.      * @param body the third body to consider
  53.      * (ex: {@link CelestialBodies#getSun()} or
  54.      * {@link CelestialBodies#getMoon()})
  55.      */
  56.     public ThirdBodyAttraction(final CelestialBody body) {
  57.         gmParameterDriver = new ParameterDriver(body.getName() + ATTRACTION_COEFFICIENT_SUFFIX,
  58.                                                 body.getGM(), MU_SCALE,
  59.                                                 0.0, Double.POSITIVE_INFINITY);

  60.         this.body = body;
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public boolean dependsOnPositionOnly() {
  65.         return true;
  66.     }

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

  70.         final double gm = parameters[0];

  71.         // compute bodies separation vectors and squared norm
  72.         final Vector3D centralToBody = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  73.         final double r2Central       = centralToBody.getNormSq();
  74.         final Vector3D satToBody     = centralToBody.subtract(s.getPVCoordinates().getPosition());
  75.         final double r2Sat           = satToBody.getNormSq();

  76.         // compute relative acceleration
  77.         return new Vector3D(gm / (r2Sat * FastMath.sqrt(r2Sat)), satToBody,
  78.                            -gm / (r2Central * FastMath.sqrt(r2Central)), centralToBody);

  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public <T extends RealFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  83.                                                                          final T[] parameters) {

  84.         final T gm = parameters[0];

  85.         // compute bodies separation vectors and squared norm
  86.         final FieldVector3D<T> centralToBody = new FieldVector3D<>(s.getA().getField(),
  87.                                                                    body.getPVCoordinates(s.getDate().toAbsoluteDate(), s.getFrame()).getPosition());
  88.         final T                r2Central     = centralToBody.getNormSq();
  89.         final FieldVector3D<T> satToBody     = centralToBody.subtract(s.getPVCoordinates().getPosition());
  90.         final T                r2Sat         = satToBody.getNormSq();

  91.         // compute relative acceleration
  92.         return new FieldVector3D<>(r2Sat.multiply(r2Sat.sqrt()).reciprocal().multiply(gm), satToBody,
  93.                                    r2Central.multiply(r2Central.sqrt()).reciprocal().multiply(gm).negate(), centralToBody);

  94.     }

  95.     /** {@inheritDoc} */
  96.     public Stream<EventDetector> getEventsDetectors() {
  97.         return Stream.empty();
  98.     }

  99.     /** {@inheritDoc} */
  100.     @Override
  101.     public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  102.         return Stream.empty();
  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     public ParameterDriver[] getParametersDrivers() {
  107.         return new ParameterDriver[] {
  108.             gmParameterDriver
  109.         };
  110.     }

  111. }