AbstractBodyAttraction.java

  1. /* Copyright 2022-2025 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.forces.ForceModel;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.FieldAbsoluteDate;
  26. import org.orekit.utils.ExtendedPositionProvider;
  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 position provider for the body to consider. */
  47.     private final ExtendedPositionProvider positionProvider;

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

  50.     /** Name of body. */
  51.     private final String name;

  52.     /** Simple constructor.
  53.      * @param positionProvider provider for the body to consider
  54.      * @param name body name
  55.      * @param mu body gravitational constant
  56.      */
  57.     protected AbstractBodyAttraction(final ExtendedPositionProvider positionProvider, final String name,
  58.                                      final double mu) {
  59.         this.positionProvider = positionProvider;
  60.         this.name = name;
  61.         this.gmParameterDriver = new ParameterDriver(name + ATTRACTION_COEFFICIENT_SUFFIX, FastMath.abs(mu),
  62.             MU_SCALE, 0.0, Double.POSITIVE_INFINITY);
  63.     }

  64.     /** Getter for the body's name.
  65.      * @return the body's name
  66.      */
  67.     public String getBodyName() {
  68.         return name;
  69.     }

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

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

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

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

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

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