ThirdBodyAttraction.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.CelestialBody;
  25. import org.orekit.errors.OrekitException;
  26. import org.orekit.errors.OrekitInternalError;
  27. import org.orekit.forces.AbstractForceModel;
  28. import org.orekit.propagation.FieldSpacecraftState;
  29. import org.orekit.propagation.SpacecraftState;
  30. import org.orekit.propagation.events.EventDetector;
  31. import org.orekit.propagation.events.FieldEventDetector;
  32. import org.orekit.utils.ParameterDriver;

  33. /** Third body attraction force model.
  34.  *
  35.  * @author Fabien Maussion
  36.  * @author Véronique Pommier-Maurussane
  37.  */
  38. public class ThirdBodyAttraction extends AbstractForceModel {

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

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

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

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

  52.     /** Simple constructor.
  53.      * @param body the third body to consider
  54.      * (ex: {@link org.orekit.bodies.CelestialBodyFactory#getSun()} or
  55.      * {@link org.orekit.bodies.CelestialBodyFactory#getMoon()})
  56.      */
  57.     public ThirdBodyAttraction(final CelestialBody body) {
  58.         try {
  59.             gmParameterDriver = new ParameterDriver(body.getName() + ATTRACTION_COEFFICIENT_SUFFIX,
  60.                                                     body.getGM(), MU_SCALE,
  61.                                                     0.0, Double.POSITIVE_INFINITY);
  62.         } catch (OrekitException oe) {
  63.             // this should never occur as valueChanged above never throws an exception
  64.             throw new OrekitInternalError(oe);
  65.         }

  66.         this.body = body;

  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public boolean dependsOnPositionOnly() {
  71.         return true;
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  76.         final double gm = parameters[0];

  77.         // compute bodies separation vectors and squared norm
  78.         final Vector3D centralToBody = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  79.         final double r2Central       = centralToBody.getNormSq();
  80.         final Vector3D satToBody     = centralToBody.subtract(s.getPVCoordinates().getPosition());
  81.         final double r2Sat           = satToBody.getNormSq();

  82.         // compute relative acceleration
  83.         return new Vector3D(gm / (r2Sat * FastMath.sqrt(r2Sat)), satToBody,
  84.                            -gm / (r2Central * FastMath.sqrt(r2Central)), centralToBody);

  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public <T extends RealFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  89.                                                                          final T[] parameters) {

  90.         final T gm = parameters[0];

  91.         // compute bodies separation vectors and squared norm
  92.         final FieldVector3D<T> centralToBody = new FieldVector3D<>(s.getA().getField(),
  93.                                                                    body.getPVCoordinates(s.getDate().toAbsoluteDate(), s.getFrame()).getPosition());
  94.         final T                r2Central     = centralToBody.getNormSq();
  95.         final FieldVector3D<T> satToBody     = centralToBody.subtract(s.getPVCoordinates().getPosition());
  96.         final T                r2Sat         = satToBody.getNormSq();

  97.         // compute relative acceleration
  98.         return new FieldVector3D<>(r2Sat.multiply(r2Sat.sqrt()).reciprocal().multiply(gm), satToBody,
  99.                                    r2Central.multiply(r2Central.sqrt()).reciprocal().multiply(gm).negate(), centralToBody);

  100.     }

  101.     /** {@inheritDoc} */
  102.     public Stream<EventDetector> getEventsDetectors() {
  103.         return Stream.empty();
  104.     }

  105.     /** {@inheritDoc} */
  106.     @Override
  107.     public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  108.         return Stream.empty();
  109.     }

  110.     /** {@inheritDoc} */
  111.     @Override
  112.     public ParameterDriver[] getParametersDrivers() {
  113.         return new ParameterDriver[] {
  114.             gmParameterDriver
  115.         };
  116.     }

  117. }