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 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.forces.ForceModel;
  25. import org.orekit.propagation.FieldSpacecraftState;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.utils.Constants;
  28. import org.orekit.utils.FieldPVCoordinates;
  29. import org.orekit.utils.PVCoordinates;
  30. import org.orekit.utils.ParameterDriver;

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

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

  49.     /** Driver for gravitational parameter. */
  50.     private final ParameterDriver gmParameterDriver;

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

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

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

  70.         final double gm = parameters[0];

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

  87.     }

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

  92.         final T gm = parameters[0];

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

  107.     }

  108.     /** {@inheritDoc} */
  109.     @Override
  110.     public List<ParameterDriver> getParametersDrivers() {
  111.         return Collections.singletonList(gmParameterDriver);
  112.     }

  113. }