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.propagation.analytical.gnss;
18  
19  import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.orekit.attitudes.Attitude;
23  import org.orekit.attitudes.AttitudeProvider;
24  import org.orekit.errors.OrekitException;
25  import org.orekit.errors.OrekitMessages;
26  import org.orekit.frames.Frame;
27  import org.orekit.orbits.CartesianOrbit;
28  import org.orekit.orbits.Orbit;
29  import org.orekit.propagation.SpacecraftState;
30  import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
31  import org.orekit.propagation.analytical.gnss.data.SBASOrbitalElements;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.utils.PVCoordinates;
34  
35  /**
36   * This class aims at propagating a SBAS orbit from {@link SBASOrbitalElements}.
37   *
38   * @see "Tyler Reid, Todd Walker, Per Enge, L1/L5 SBAS MOPS Ephemeris Message to
39   *       Support Multiple Orbit Classes, ION ITM, 2013"
40   *
41   * @author Bryan Cazabonne
42   * @since 10.1
43   *
44   */
45  public class SBASPropagator extends AbstractAnalyticalPropagator {
46  
47      /** The SBAS orbital elements used. */
48      private final SBASOrbitalElements sbasOrbit;
49  
50      /** The spacecraft mass (kg). */
51      private final double mass;
52  
53      /** The Earth gravity coefficient used for SBAS propagation. */
54      private final double mu;
55  
56      /** The ECI frame used for SBAS propagation. */
57      private final Frame eci;
58  
59      /** The ECEF frame used for SBAS propagation. */
60      private final Frame ecef;
61  
62      /**
63       * Private constructor.
64       * @param sbasOrbit Glonass orbital elements
65       * @param eci Earth Centered Inertial frame
66       * @param ecef Earth Centered Earth Fixed frame
67       * @param provider Attitude provider
68       * @param mass Satellite mass (kg)
69       * @param mu Earth's gravity coefficient used for SBAS propagation
70       */
71      SBASPropagator(final SBASOrbitalElements sbasOrbit, final Frame eci,
72                     final Frame ecef, final AttitudeProvider provider,
73                     final double mass, final double mu) {
74          super(provider);
75          // Stores the SBAS orbital elements
76          this.sbasOrbit = sbasOrbit;
77          // Sets the start date as the date of the orbital elements
78          setStartDate(sbasOrbit.getDate());
79          // Sets the mu
80          this.mu = mu;
81          // Sets the mass
82          this.mass = mass;
83          // Sets the Earth Centered Inertial frame
84          this.eci  = eci;
85          // Sets the Earth Centered Earth Fixed frame
86          this.ecef = ecef;
87          // Sets initial state
88          final Orbit orbit = propagateOrbit(getStartDate());
89          final Attitude attitude = provider.getAttitude(orbit, orbit.getDate(), orbit.getFrame());
90          super.resetInitialState(new SpacecraftState(orbit, attitude).withMass(mass));
91      }
92  
93      /**
94       * Gets the PVCoordinates of the GNSS SV in {@link #getECEF() ECEF frame}.
95       *
96       * <p>The algorithm uses automatic differentiation to compute velocity and
97       * acceleration.</p>
98       *
99       * @param date the computation date
100      * @return the GNSS SV PVCoordinates in {@link #getECEF() ECEF frame}
101      */
102     public PVCoordinates propagateInEcef(final AbsoluteDate date) {
103         // Duration from SBAS ephemeris Reference date
104         final UnivariateDerivative2 dt = new UnivariateDerivative2(getDT(date), 1.0, 0.0);
105         // Satellite coordinates
106         final UnivariateDerivative2 x = dt.multiply(dt.multiply(0.5 * sbasOrbit.getXDotDot()).add(sbasOrbit.getXDot())).add(sbasOrbit.getX());
107         final UnivariateDerivative2 y = dt.multiply(dt.multiply(0.5 * sbasOrbit.getYDotDot()).add(sbasOrbit.getYDot())).add(sbasOrbit.getY());
108         final UnivariateDerivative2 z = dt.multiply(dt.multiply(0.5 * sbasOrbit.getZDotDot()).add(sbasOrbit.getZDot())).add(sbasOrbit.getZ());
109         // Returns the Earth-fixed coordinates
110         final FieldVector3D<UnivariateDerivative2> positionwithDerivatives =
111                         new FieldVector3D<>(x, y, z);
112         return new PVCoordinates(new Vector3D(positionwithDerivatives.getX().getValue(),
113                                               positionwithDerivatives.getY().getValue(),
114                                               positionwithDerivatives.getZ().getValue()),
115                                  new Vector3D(positionwithDerivatives.getX().getFirstDerivative(),
116                                               positionwithDerivatives.getY().getFirstDerivative(),
117                                               positionwithDerivatives.getZ().getFirstDerivative()),
118                                  new Vector3D(positionwithDerivatives.getX().getSecondDerivative(),
119                                               positionwithDerivatives.getY().getSecondDerivative(),
120                                               positionwithDerivatives.getZ().getSecondDerivative()));
121     }
122 
123     /** {@inheritDoc} */
124     public Orbit propagateOrbit(final AbsoluteDate date) {
125         // Gets the PVCoordinates in ECEF frame
126         final PVCoordinates pvaInECEF = propagateInEcef(date);
127         // Transforms the PVCoordinates to ECI frame
128         final PVCoordinates pvaInECI = ecef.getTransformTo(eci, date).transformPVCoordinates(pvaInECEF);
129         // Returns the Cartesian orbit
130         return new CartesianOrbit(pvaInECI, eci, date, mu);
131     }
132 
133     /**
134      * Get the Earth gravity coefficient used for SBAS propagation.
135      * @return the Earth gravity coefficient.
136      */
137     public double getMU() {
138         return mu;
139     }
140 
141     /**
142      * Gets the Earth Centered Inertial frame used to propagate the orbit.
143      *
144      * @return the ECI frame
145      */
146     public Frame getECI() {
147         return eci;
148     }
149 
150     /**
151      * Gets the Earth Centered Earth Fixed frame used to propagate GNSS orbits.
152      *
153      * @return the ECEF frame
154      */
155     public Frame getECEF() {
156         return ecef;
157     }
158 
159     /**
160      * Get the underlying SBAS orbital elements.
161      *
162      * @return the underlying SBAS orbital elements
163      */
164     public SBASOrbitalElements getSBASOrbitalElements() {
165         return sbasOrbit;
166     }
167 
168     /** {@inheritDoc} */
169     public Frame getFrame() {
170         return eci;
171     }
172 
173     /** {@inheritDoc} */
174     public void resetInitialState(final SpacecraftState state) {
175         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
176     }
177 
178     /** {@inheritDoc} */
179     protected double getMass(final AbsoluteDate date) {
180         return mass;
181     }
182 
183     /** {@inheritDoc} */
184     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
185         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
186     }
187 
188     /** Get the duration from SBAS Reference epoch.
189      * @param date the considered date
190      * @return the duration from SBAS orbit Reference epoch (s)
191      */
192     private double getDT(final AbsoluteDate date) {
193         // Time from ephemeris reference epoch
194         return date.durationFrom(sbasOrbit.getDate());
195     }
196 
197 }