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

  36. /** Body attraction force model computed as relative acceleration towards frame center.
  37.  * @author Luc Maisonabe
  38.  * @author Julio Hernanz
  39.  */
  40. public class SingleBodyRelativeAttraction extends AbstractForceModel {

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

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

  50.     /** Drivers for body attraction coefficient. */
  51.     private final ParameterDriver gmDriver;

  52.     /** The body to consider. */
  53.     private final CelestialBody body;

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

  63.         this.body = body;
  64.     }

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

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

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

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

  80.     }

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

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

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

  92.     }

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

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

  102.     /** {@inheritDoc} */
  103.     public List<ParameterDriver> getParametersDrivers() {
  104.         return Collections.singletonList(gmDriver);
  105.     }

  106. }