Relativity.java

  1. /* Contributed to the public domain
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  25. import org.orekit.errors.OrekitInternalError;
  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.Constants;
  32. import org.orekit.utils.FieldPVCoordinates;
  33. import org.orekit.utils.PVCoordinates;
  34. import org.orekit.utils.ParameterDriver;

  35. /**
  36.  * Post-Newtonian correction force due to general relativity. The main effect is the
  37.  * precession of perigee by a few arcseconds per year.
  38.  *
  39.  * <p> Implemented from Montenbruck and Gill equation 3.146.
  40.  *
  41.  * @author Evan Ward
  42.  * @see "Montenbruck, Oliver, and Gill, Eberhard. Satellite orbits : models, methods, and
  43.  * applications. Berlin New York: Springer, 2000."
  44.  */
  45. public class Relativity extends AbstractForceModel {

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

  53.     /** Driver for gravitational parameter. */
  54.     private final ParameterDriver gmParameterDriver;

  55.     /**
  56.      * Create a force model to add post-Newtonian acceleration corrections to an Earth
  57.      * orbit.
  58.      *
  59.      * @param gm Earth's gravitational parameter.
  60.      */
  61.     public Relativity(final double gm) {
  62.         try {
  63.             gmParameterDriver = new ParameterDriver(NewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT,
  64.                                                     gm, MU_SCALE,
  65.                                                     0.0, Double.POSITIVE_INFINITY);
  66.         } catch (OrekitException oe) {
  67.             // this should never occur as valueChanged above never throws an exception
  68.             throw new OrekitInternalError(oe);
  69.         }

  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public boolean dependsOnPositionOnly() {
  74.         return false;
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters)
  79.         throws OrekitException {

  80.         final double gm = parameters[0];

  81.         final PVCoordinates pv = s.getPVCoordinates();
  82.         final Vector3D p = pv.getPosition();
  83.         final Vector3D v = pv.getVelocity();
  84.         //radius
  85.         final double r2 = p.getNormSq();
  86.         final double r = FastMath.sqrt(r2);
  87.         //speed
  88.         final double s2 = v.getNormSq();
  89.         final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT;
  90.         //eq. 3.146
  91.         return new Vector3D(
  92.                 4 * gm / r - s2,
  93.                 p,
  94.                 4 * p.dotProduct(v),
  95.                 v)
  96.                 .scalarMultiply(gm / (r2 * r * c2));

  97.     }

  98.     /** {@inheritDoc} */
  99.     @Override
  100.     public <T extends RealFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  101.                                                                          final T[] parameters)
  102.         throws OrekitException {

  103.         final T gm = parameters[0];

  104.         final FieldPVCoordinates<T> pv = s.getPVCoordinates();
  105.         final FieldVector3D<T> p = pv.getPosition();
  106.         final FieldVector3D<T> v = pv.getVelocity();
  107.         //radius
  108.         final T r2 = p.getNormSq();
  109.         final T r = r2.sqrt();
  110.         //speed
  111.         final T s2 = v.getNormSq();
  112.         final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT;
  113.         //eq. 3.146
  114.         return new FieldVector3D<>(r.reciprocal().multiply(4).multiply(gm).subtract(s2),
  115.                                    p,
  116.                                    p.dotProduct(v).multiply(4),
  117.                                    v).scalarMultiply(r2.multiply(r).multiply(c2).reciprocal().multiply(gm));

  118.     }

  119.     /** {@inheritDoc} */
  120.     @Override
  121.     public Stream<EventDetector> getEventsDetectors() {
  122.         return Stream.empty();
  123.     }

  124.     /** {@inheritDoc} */
  125.     @Override
  126.     public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  127.         return Stream.empty();
  128.     }

  129.     /** {@inheritDoc} */
  130.     @Override
  131.     public ParameterDriver[] getParametersDrivers() {
  132.         return new ParameterDriver[] {
  133.             gmParameterDriver
  134.         };
  135.     }

  136. }