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