AbstractBodyAttraction.java

  1. /* Copyright 2022-2024 Romain Serra
  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 org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.orekit.bodies.CelestialBody;
  23. import org.orekit.forces.ForceModel;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.FieldAbsoluteDate;
  27. import org.orekit.utils.ParameterDriver;
  28. import org.orekit.utils.TimeStampedPVCoordinates;
  29. import org.orekit.utils.TimeStampedFieldPVCoordinates;

  30. import java.util.Collections;
  31. import java.util.List;

  32. /** Abstract class for non-central body attraction force model.
  33.  *
  34.  * @author Romain Serra
  35.  */
  36. public abstract class AbstractBodyAttraction implements ForceModel {

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

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

  46.     /** The body to consider. */
  47.     private final CelestialBody body;

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

  50.     /** Simple constructor.
  51.      * @param body the third body to consider
  52.      */
  53.     protected AbstractBodyAttraction(final CelestialBody body) {
  54.         this.body = body;
  55.         this.gmParameterDriver = new ParameterDriver(body.getName() + ATTRACTION_COEFFICIENT_SUFFIX,
  56.                 body.getGM(), MU_SCALE, 0.0, Double.POSITIVE_INFINITY);
  57.     }

  58.     /** Getter for the body's name.
  59.      * @return the body's name
  60.      */
  61.     public String getBodyName() {
  62.         return body.getName();
  63.     }

  64.     /** Protected getter for the body.
  65.      * @return the third body considered
  66.      * @deprecated in next major release this shall be removed as the class will not have to use a CelestialBody
  67.      */
  68.     @Deprecated
  69.     protected CelestialBody getBody() {
  70.         return body;
  71.     }

  72.     /**
  73.      * Get the body's position vector.
  74.      * @param date date
  75.      * @param frame frame
  76.      * @return position
  77.      * @since 12.2
  78.      */
  79.     protected Vector3D getBodyPosition(final AbsoluteDate date, final Frame frame) {
  80.         return body.getPosition(date, frame);
  81.     }

  82.     /**
  83.      * Get the body's position vector.
  84.      * @param date date
  85.      * @param frame frame
  86.      * @param <T> field type
  87.      * @return position
  88.      * @since 12.2
  89.      */
  90.     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getBodyPosition(final FieldAbsoluteDate<T> date,
  91.                                                                                    final Frame frame) {
  92.         return body.getPosition(date, frame);
  93.     }

  94.     /**
  95.      * Get the body's position-velocity-acceleration vector.
  96.      * @param date date
  97.      * @param frame frame
  98.      * @return PV
  99.      * @since 12.2
  100.      */
  101.     protected TimeStampedPVCoordinates getBodyPVCoordinates(final AbsoluteDate date, final Frame frame) {
  102.         return body.getPVCoordinates(date, frame);
  103.     }

  104.     /**
  105.      * Get the body's position-velocity-acceleration vector.
  106.      * @param date date
  107.      * @param frame frame
  108.      * @param <T> field type
  109.      * @return PV
  110.      * @since 12.2
  111.      */
  112.     protected <T extends CalculusFieldElement<T>> TimeStampedFieldPVCoordinates<T> getBodyPVCoordinates(final FieldAbsoluteDate<T> date,
  113.                                                                                                         final Frame frame) {
  114.         return body.getPVCoordinates(date, frame);
  115.     }

  116.     /** {@inheritDoc} */
  117.     @Override
  118.     public boolean dependsOnPositionOnly() {
  119.         return true;
  120.     }

  121.     /** {@inheritDoc} */
  122.     @Override
  123.     public List<ParameterDriver> getParametersDrivers() {
  124.         return Collections.singletonList(gmParameterDriver);
  125.     }
  126. }