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.Collections;
  19. import java.util.List;
  20. import java.util.stream.Stream;

  21. import org.hipparchus.Field;
  22. import org.hipparchus.CalculusFieldElement;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.hipparchus.util.FastMath;
  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.         gmParameterDriver = new ParameterDriver(NewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT,
  63.                                                 gm, MU_SCALE,
  64.                                                 0.0, Double.POSITIVE_INFINITY);
  65.     }

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

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

  74.         final double gm = parameters[0];

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

  91.     }

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

  96.         final T gm = parameters[0];

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

  111.     }

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

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

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

  127. }