1   /* Copyright 2002-2025 CS GROUP
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.radiation;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.hipparchus.CalculusFieldElement;
24  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
25  import org.hipparchus.geometry.euclidean.threed.Vector3D;
26  import org.hipparchus.util.FastMath;
27  import org.hipparchus.util.FieldSinCos;
28  import org.hipparchus.util.SinCos;
29  import org.orekit.annotation.DefaultDataContext;
30  import org.orekit.bodies.OneAxisEllipsoid;
31  import org.orekit.data.DataContext;
32  import org.orekit.frames.Frames;
33  import org.orekit.propagation.FieldSpacecraftState;
34  import org.orekit.propagation.SpacecraftState;
35  import org.orekit.utils.ExtendedPositionProvider;
36  import org.orekit.utils.ParameterDriver;
37  
38  /**
39   * The Empirical CODE Orbit Model 2 (ECOM2) of the Center for Orbit Determination in Europe (CODE).
40   * <p>
41   * The drag acceleration is computed as follows :
42   * γ = γ<sub>0</sub> + D(u)e<sub>D</sub> + Y(u)e<sub>Y</sub> + B(u)e<sub>B</sub>
43   * </p> <p>
44   * In the above equation, γ<sub>0</sub> is a selectable a priori model. Since 2013, no
45   * a priori model is used for CODE IGS contribution (i.e. γ<sub>0</sub> = 0). Moreover,
46   * u denotes the satellite's argument of latitude.
47   * </p> <p>
48   * D(u), Y(u) and B(u) are three functions of the ECOM2 model that can be represented
49   * as Fourier series. The coefficients of the Fourier series are estimated during the
50   * estimation process. he ECOM2 model has user-defines upper limits <i>nD</i> and
51   * <i>nB</i> for the Fourier series (i.e. <i>nD</i> for D(u) and <i>nB</i> for
52   * B(u). Y(u) is defined as a constant value).
53   * </p> <p>
54   * It exists several configurations to initialize <i>nD</i> and <i>nB</i> values. However,
55   * Arnold et al recommend to use <b>D2B1</b> (i.e. <i>nD</i> = 1 and <i>nB</i> = 1) and
56   * <b>D4B1</b> (i.e. <i>nD</i> = 2 an <i>nB</i> = 1) configurations. At the opposite, in Arnold paper, it
57   * is recommend to not use <b>D2B0</b> (i.e. <i>nD</i> = 1 and <i>nB</i> = 0) configuration.
58   * </p> <p>
59   * Since Orekit 11.0, it is possible to take into account
60   * the eclipses generated by Moon in the solar radiation
61   * pressure force model using the
62   * {@link #addOccultingBody(ExtendedPositionProvider, double)}
63   * method.<br>
64   * <code> ECOM2 srp =</code>
65   * <code>       new ECOM2(1, 1, 0.0, CelestialBodyFactory.getSun(), Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS);</code><br>
66   * <code> srp.addOccultingBody(CelestialBodyFactory.getMoon(), Constants.MOON_EQUATORIAL_RADIUS);</code><br>
67   *
68   * @see "Arnold, Daniel, et al, CODE’s new solar radiation pressure model for GNSS orbit determination,
69   *       Journal of geodesy 89.8 (2015): 775-791."
70   *
71   * @see "Tzu-Pang tseng and Michael Moore, Impact of solar radiation pressure mis-modeling on
72   *       GNSS satellite orbit determination, IGS Worshop, Wuhan, China, 2018."
73   *
74   * @author David Soulard
75   * @since 10.2
76   */
77  public class ECOM2 extends AbstractRadiationForceModel {
78  
79      /** Parameter name for ECOM model coefficients enabling Jacobian processing. */
80      public static final String ECOM_COEFFICIENT = "ECOM coefficient";
81  
82      /** Minimum value for ECOM2 estimated parameters. */
83      private static final double MIN_VALUE = Double.NEGATIVE_INFINITY;
84  
85      /** Maximum value for ECOM2 estimated parameters. */
86      private static final double MAX_VALUE = Double.POSITIVE_INFINITY;
87  
88      /** Highest order for parameter along eD axis (satellite --> sun direction). */
89      private final int nD;
90  
91      /** Highest order for parameter along eB axis. */
92      private final int nB;
93  
94      /** Estimated acceleration coefficients.
95       * <p>
96       * The 2 * nD first driver are Fourier driver along eD, axis,
97       * then along eY, then 2*nB following are along eB axis.
98       * </p>
99       */
100     private final List<ParameterDriver> coefficients;
101 
102     /** Sun model. */
103     private final ExtendedPositionProvider sun;
104 
105     /**
106      * Constructor.
107      * @param nD truncation rank of Fourier series in D term.
108      * @param nB truncation rank of Fourier series in B term.
109      * @param value parameters initial value
110      * @param sun provide for Sun parameter
111      * @param equatorialRadius spherical shape model (for umbra/penumbra computation)
112      */
113     @DefaultDataContext
114     public ECOM2(final int nD, final int nB, final double value,
115                  final ExtendedPositionProvider sun, final double equatorialRadius) {
116         this(nD, nB, value, sun, equatorialRadius, DataContext.getDefault().getFrames());
117     }
118 
119     /**
120      * Constructor.
121      * @param nD truncation rank of Fourier series in D term.
122      * @param nB truncation rank of Fourier series in B term.
123      * @param value parameters initial value
124      * @param sun provide for Sun parameter
125      * @param equatorialRadius spherical shape model (for umbra/penumbra computation)
126      * @param frames list of frames with user-defined data context
127      * @since 13.1.1
128      */
129     public ECOM2(final int nD, final int nB, final double value,
130                  final ExtendedPositionProvider sun, final double equatorialRadius,
131                  final Frames frames) {
132         super(sun, new OneAxisEllipsoid(equatorialRadius, 0.0, frames.getGCRF()), getDefaultEclipseDetectionSettings());
133         this.nB = nB;
134         this.nD = nD;
135         this.coefficients = new ArrayList<>(2 * (nD + nB) + 3);
136 
137         // Parameters scaling factor
138         final double scale = FastMath.scalb(1.0, -22);
139         // Add parameter along eB axis in alphabetical order
140         coefficients.add(new ParameterDriver(ECOM_COEFFICIENT + " B0", value, scale, MIN_VALUE, MAX_VALUE));
141         for (int i = 1; i < nB + 1; i++) {
142             coefficients.add(new ParameterDriver(ECOM_COEFFICIENT + " Bcos" + (i - 1), value, scale, MIN_VALUE, MAX_VALUE));
143         }
144         for (int i = nB + 1; i < 2 * nB + 1; i++) {
145             coefficients.add(new ParameterDriver(ECOM_COEFFICIENT + " Bsin" + (i - (nB + 1)), value, scale, MIN_VALUE, MAX_VALUE));
146         }
147         // Add driver along eD axis in alphabetical order
148         coefficients.add(2 * nB + 1, new ParameterDriver(ECOM_COEFFICIENT + " D0", value, scale, MIN_VALUE, MAX_VALUE));
149         for (int i = 2 * nB + 2; i < 2 * nB + 2 + nD; i++) {
150             coefficients.add(new ParameterDriver(ECOM_COEFFICIENT + " Dcos" + (i - (2 * nB + 2)), value, scale, MIN_VALUE, MAX_VALUE));
151         }
152         for (int i = 2 * nB + 2 + nD; i < 2 * (nB + nD) + 2; i++) {
153             coefficients.add(new ParameterDriver(ECOM_COEFFICIENT + " Dsin" + (i - (2 * nB + nD + 2)), value, scale, MIN_VALUE, MAX_VALUE));
154         }
155         // Add Y0
156         coefficients.add(new ParameterDriver(ECOM_COEFFICIENT + " Y0", value, scale, MIN_VALUE, MAX_VALUE));
157 
158         // For ECOM2 model, all parameters are estimated
159         coefficients.forEach(parameter -> parameter.setSelected(true));
160         this.sun = sun;
161     }
162 
163     /** {@inheritDoc} */
164     @Override
165     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {
166 
167         // Spacecraft and Sun position vectors (expressed in the spacecraft's frame)
168         final Vector3D satPos = s.getPosition();
169         final Vector3D sunPos = sun.getPosition(s.getDate(), s.getFrame());
170 
171         // Build the coordinate system
172         final Vector3D Z = s.getPVCoordinates().getMomentum();
173         final Vector3D Y = Z.crossProduct(sunPos).normalize();
174         final Vector3D X = Y.crossProduct(Z).normalize();
175 
176         // Build eD, eY, eB vectors
177         final Vector3D eD = sunPos.subtract(satPos).normalize();
178         final Vector3D eY = eD.crossProduct(satPos).normalize();
179         final Vector3D eB = eD.crossProduct(eY);
180 
181         // Angular argument difference u_s - u
182         final double delta_u = FastMath.atan2(satPos.dotProduct(Y), satPos.dotProduct(X));
183 
184         // Compute B(u)
185         double b_u = parameters[0];
186         for (int i = 1; i < nB + 1; i++) {
187             final SinCos sc = FastMath.sinCos((2 * i - 1) * delta_u);
188             b_u += parameters[i] * sc.cos() + parameters[i + nB] * sc.sin();
189         }
190         // Compute D(u)
191         double d_u = parameters[2 * nB + 1];
192         for (int i = 1; i < nD + 1; i++) {
193             final SinCos sc = FastMath.sinCos(2 * i * delta_u);
194             d_u += parameters[2 * nB + 1 + i] * sc.cos() + parameters[2 * nB + 1 + i + nD] * sc.sin();
195         }
196         // Return acceleration
197         return new Vector3D(d_u, eD, parameters[2 * (nD + nB) + 2], eY, b_u, eB);
198     }
199 
200     /** {@inheritDoc} */
201     @Override
202     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s, final T[] parameters) {
203 
204         // Spacecraft and Sun position vectors (expressed in the spacecraft's frame)
205         final FieldVector3D<T> satPos = s.getPosition();
206         final FieldVector3D<T> sunPos = sun.getPosition(s.getDate(), s.getFrame());
207 
208         // Build the coordinate system
209         final FieldVector3D<T> Z = s.getPVCoordinates().getMomentum();
210         final FieldVector3D<T> Y = Z.crossProduct(sunPos).normalize();
211         final FieldVector3D<T> X = Y.crossProduct(Z).normalize();
212 
213         // Build eD, eY, eB vectors
214         final FieldVector3D<T> eD = sunPos.subtract(satPos).normalize();
215         final FieldVector3D<T> eY = eD.crossProduct(satPos).normalize();
216         final FieldVector3D<T> eB = eD.crossProduct(eY);
217 
218         // Angular argument difference u_s - u
219         final T  delta_u = FastMath.atan2(satPos.dotProduct(Y), satPos.dotProduct(X));
220 
221         // Compute B(u)
222         T b_u =  parameters[0];
223         for (int i = 1; i < nB + 1; i++) {
224             final FieldSinCos<T> sc = FastMath.sinCos(delta_u.multiply(2 * i - 1));
225             b_u = b_u.add(sc.cos().multiply(parameters[i])).add(sc.sin().multiply(parameters[i + nB]));
226         }
227         // Compute D(u)
228         T d_u = parameters[2 * nB + 1];
229 
230         for (int i = 1; i < nD + 1; i++) {
231             final FieldSinCos<T> sc = FastMath.sinCos(delta_u.multiply(2 * i));
232             d_u =  d_u.add(sc.cos().multiply(parameters[2 * nB + 1 + i])).add(sc.sin().multiply(parameters[2 * nB + 1 + i + nD]));
233         }
234         // Return the acceleration
235         return new FieldVector3D<>(d_u, eD, parameters[2 * (nD + nB) + 2], eY, b_u, eB);
236     }
237 
238     /** {@inheritDoc} */
239     @Override
240     public List<ParameterDriver> getParametersDrivers() {
241         return Collections.unmodifiableList(coefficients);
242     }
243 
244 }
245