ThirdBodyAttraction.java

  1. /* Copyright 2002-2024 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 org.hipparchus.CalculusFieldElement;
  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.ForceModel;
  27. import org.orekit.propagation.FieldSpacecraftState;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.utils.ParameterDriver;

  30. /** Third body attraction force model.
  31.  *
  32.  * @author Fabien Maussion
  33.  * @author Véronique Pommier-Maurussane
  34.  */
  35. public class ThirdBodyAttraction implements ForceModel {

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

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

  45.     /** Drivers for third body attraction coefficient. */
  46.     private final ParameterDriver gmParameterDriver;

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

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

  58.         this.body = body;
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public boolean dependsOnPositionOnly() {
  63.         return true;
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  68.         final double gm = parameters[0];

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

  74.         // compute relative acceleration
  75.         return new Vector3D(gm / (r2Sat * FastMath.sqrt(r2Sat)), satToBody,
  76.                            -gm / (r2Central * FastMath.sqrt(r2Central)), centralToBody);

  77.     }

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

  82.         final T gm = parameters[0];

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

  88.         // compute relative acceleration
  89.         return new FieldVector3D<>(r2Sat.multiply(r2Sat.sqrt()).reciprocal().multiply(gm), satToBody,
  90.                                    r2Central.multiply(r2Central.sqrt()).reciprocal().multiply(gm).negate(), centralToBody);

  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public List<ParameterDriver> getParametersDrivers() {
  95.         return Collections.singletonList(gmParameterDriver);
  96.     }

  97. }