SingleBodyRelativeAttraction.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.FieldPVCoordinates;
  32. import org.orekit.utils.PVCoordinates;
  33. import org.orekit.utils.ParameterDriver;

  34. /** Body attraction force model computed as relative acceleration towards frame center.
  35.  * @author Luc Maisonabe
  36.  * @author Julio Hernanz
  37.  */
  38. public class SingleBodyRelativeAttraction 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 body attraction coefficient. */
  49.     private final ParameterDriver gmDriver;

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

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

  61.         this.body = body;
  62.     }

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

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

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

  74.         // compute relative acceleration
  75.         final double gm = parameters[0];
  76.         final double a = gm / r2Sat;
  77.         return new Vector3D(a, satToBody.normalize()).add(bodyPV.getAcceleration());

  78.     }

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

  82.         // compute bodies separation vectors and squared norm
  83.         final FieldPVCoordinates<T> bodyPV = body.getPVCoordinates(s.getDate(), s.getFrame());
  84.         final FieldVector3D<T> satToBody   = bodyPV.getPosition().subtract(s.getPVCoordinates().getPosition());
  85.         final T                r2Sat       = satToBody.getNormSq();

  86.         // compute relative acceleration
  87.         final T gm = parameters[0];
  88.         final T a  = gm.divide(r2Sat);
  89.         return new FieldVector3D<>(a, satToBody.normalize()).add(bodyPV.getAcceleration());

  90.     }

  91.     /** {@inheritDoc} */
  92.     public Stream<EventDetector> getEventsDetectors() {
  93.         return Stream.empty();
  94.     }

  95.     @Override
  96.     /** {@inheritDoc} */
  97.     public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  98.         return Stream.empty();
  99.     }

  100.     /** {@inheritDoc} */
  101.     public ParameterDriver[] getParametersDrivers() {
  102.         return new ParameterDriver[] {
  103.             gmDriver
  104.         };
  105.     }

  106. }