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