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  
19  import java.util.Collections;
20  import java.util.List;
21  
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.annotation.DefaultDataContext;
27  import org.orekit.bodies.CelestialBody;
28  import org.orekit.data.DataContext;
29  import org.orekit.forces.ForceModel;
30  import org.orekit.propagation.FieldSpacecraftState;
31  import org.orekit.propagation.SpacecraftState;
32  import org.orekit.utils.Constants;
33  import org.orekit.utils.ExtendedPositionProvider;
34  import org.orekit.utils.FieldPVCoordinates;
35  import org.orekit.utils.PVCoordinates;
36  import org.orekit.utils.ParameterDriver;
37  
38  /**
39   * De Sitter post-Newtonian correction force due to general relativity.
40   * <p>
41   * De Sitter term causes a precession of the orbital plane at a rate of 19 mas per year.
42   * </p>
43   * @see "Petit, G. and Luzum, B. (eds.), IERS Conventions (2010), Chapter 10,
44   * General relativistic models for space-time coordinates and equations of motion (2010)"
45   *
46   * @author Bryan Cazabonne
47   * @since 10.3
48   */
49  public class DeSitterRelativity implements ForceModel {
50  
51      /** Suffix for parameter name for attraction coefficient enabling Jacobian processing. */
52      public static final String ATTRACTION_COEFFICIENT_SUFFIX = " attraction coefficient";
53  
54      /** Central attraction scaling factor.
55       * <p>
56       * We use a power of 2 to avoid numeric noise introduction
57       * in the multiplications/divisions sequences.
58       * </p>
59       */
60      private static final double MU_SCALE = FastMath.scalb(1.0, 32);
61  
62      /** The Sun. */
63      private final CelestialBody sun;
64  
65      /** The Earth. */
66      private final ExtendedPositionProvider earth;
67  
68      /** Driver for gravitational parameter. */
69      private final ParameterDriver gmParameterDriver;
70  
71      /**
72       * Constructor.
73       * <p>It uses the {@link DataContext#getDefault()} to initialize the celestial bodies.</p>
74       */
75      @DefaultDataContext
76      public DeSitterRelativity() {
77          this(DataContext.getDefault().getCelestialBodies().getEarth(),
78               DataContext.getDefault().getCelestialBodies().getSun());
79      }
80  
81      /**
82       * Simple constructor.
83       * @param earth the Earth
84       * @param sun the Sun
85       */
86      public DeSitterRelativity(final CelestialBody earth, final CelestialBody sun) {
87          gmParameterDriver = new ParameterDriver(sun.getName() + ATTRACTION_COEFFICIENT_SUFFIX,
88                                                  sun.getGM(), MU_SCALE,
89                                                  0.0, Double.POSITIVE_INFINITY);
90          this.earth = earth;
91          this.sun   = sun;
92      }
93  
94      /**
95       * Get the sun model used to compute De Sitter effect.
96       * @return the sun model
97       */
98      public CelestialBody getSun() {
99          return sun;
100     }
101 
102     /**
103      * Get the Earth model used to compute De Sitter effect.
104      * @return the earth model
105      */
106     public ExtendedPositionProvider getEarth() {
107         return earth;
108     }
109 
110     /** {@inheritDoc} */
111     @Override
112     public boolean dependsOnPositionOnly() {
113         return false;
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {
119 
120         // Useful constant
121         final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT;
122 
123         // Sun's gravitational parameter
124         final double gm = parameters[0];
125 
126         // Satellite velocity with respect to the Earth
127         final PVCoordinates pvSat = s.getPVCoordinates();
128         final Vector3D vSat = pvSat.getVelocity();
129 
130         // Coordinates of the Earth with respect to the Sun
131         final PVCoordinates pvEarth = earth.getPVCoordinates(s.getDate(), sun.getInertiallyOrientedFrame());
132         final Vector3D pEarth = pvEarth.getPosition();
133         final Vector3D vEarth = pvEarth.getVelocity();
134 
135         // Radius
136         final double r  = pEarth.getNorm();
137         final double r3 = r * r * r;
138 
139         // Eq. 10.12
140         return new Vector3D((-3.0 * gm) / (c2 * r3), vEarth.crossProduct(pEarth).crossProduct(vSat));
141     }
142 
143     /** {@inheritDoc} */
144     @Override
145     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
146                                                                          final T[] parameters) {
147 
148         // Useful constant
149         final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT;
150 
151         // Sun's gravitational parameter
152         final T gm = parameters[0];
153 
154         // Satellite velocity with respect to the Earth
155         final FieldPVCoordinates<T> pvSat = s.getPVCoordinates();
156         final FieldVector3D<T> vSat = pvSat.getVelocity();
157 
158         // Coordinates of the Earth with respect to the Sun
159         final FieldPVCoordinates<T> pvEarth = earth.getPVCoordinates(s.getDate(), sun.getInertiallyOrientedFrame());
160         final FieldVector3D<T> pEarth = pvEarth.getPosition();
161         final FieldVector3D<T> vEarth = pvEarth .getVelocity();
162 
163         // Radius
164         final T r  = pEarth.getNorm();
165         final T r3 = r.multiply(r).multiply(r);
166 
167         // Eq. 10.12
168         return new FieldVector3D<>(gm.multiply(-3.0).divide(r3.multiply(c2)), vEarth.crossProduct(pEarth).crossProduct(vSat));
169     }
170 
171     /** {@inheritDoc} */
172     @Override
173     public List<ParameterDriver> getParametersDrivers() {
174         return Collections.singletonList(gmParameterDriver);
175     }
176 
177 }