Relativity.java

  1. /* Contributed to the public domain
  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.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.forces.AbstractForceModel;
  25. import org.orekit.propagation.FieldSpacecraftState;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.events.EventDetector;
  28. import org.orekit.propagation.events.FieldEventDetector;
  29. import org.orekit.utils.Constants;
  30. import org.orekit.utils.FieldPVCoordinates;
  31. import org.orekit.utils.PVCoordinates;
  32. import org.orekit.utils.ParameterDriver;

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

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

  51.     /** Driver for gravitational parameter. */
  52.     private final ParameterDriver gmParameterDriver;

  53.     /**
  54.      * Create a force model to add post-Newtonian acceleration corrections to an Earth
  55.      * orbit.
  56.      *
  57.      * @param gm Earth's gravitational parameter.
  58.      */
  59.     public Relativity(final double gm) {
  60.         gmParameterDriver = new ParameterDriver(NewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT,
  61.                                                 gm, MU_SCALE,
  62.                                                 0.0, Double.POSITIVE_INFINITY);
  63.     }

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

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

  72.         final double gm = parameters[0];

  73.         final PVCoordinates pv = s.getPVCoordinates();
  74.         final Vector3D p = pv.getPosition();
  75.         final Vector3D v = pv.getVelocity();
  76.         //radius
  77.         final double r2 = p.getNormSq();
  78.         final double r = FastMath.sqrt(r2);
  79.         //speed
  80.         final double s2 = v.getNormSq();
  81.         final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT;
  82.         //eq. 3.146
  83.         return new Vector3D(
  84.                 4 * gm / r - s2,
  85.                 p,
  86.                 4 * p.dotProduct(v),
  87.                 v)
  88.                 .scalarMultiply(gm / (r2 * r * c2));

  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     public <T extends RealFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  93.                                                                          final T[] parameters) {

  94.         final T gm = parameters[0];

  95.         final FieldPVCoordinates<T> pv = s.getPVCoordinates();
  96.         final FieldVector3D<T> p = pv.getPosition();
  97.         final FieldVector3D<T> v = pv.getVelocity();
  98.         //radius
  99.         final T r2 = p.getNormSq();
  100.         final T r = r2.sqrt();
  101.         //speed
  102.         final T s2 = v.getNormSq();
  103.         final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT;
  104.         //eq. 3.146
  105.         return new FieldVector3D<>(r.reciprocal().multiply(4).multiply(gm).subtract(s2),
  106.                                    p,
  107.                                    p.dotProduct(v).multiply(4),
  108.                                    v).scalarMultiply(r2.multiply(r).multiply(c2).reciprocal().multiply(gm));

  109.     }

  110.     /** {@inheritDoc} */
  111.     @Override
  112.     public Stream<EventDetector> getEventsDetectors() {
  113.         return Stream.empty();
  114.     }

  115.     /** {@inheritDoc} */
  116.     @Override
  117.     public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  118.         return Stream.empty();
  119.     }

  120.     /** {@inheritDoc} */
  121.     @Override
  122.     public ParameterDriver[] getParametersDrivers() {
  123.         return new ParameterDriver[] {
  124.             gmParameterDriver
  125.         };
  126.     }

  127. }