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.integration;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.orekit.attitudes.AttitudeProvider;
21  import org.orekit.frames.Frame;
22  import org.orekit.orbits.OrbitType;
23  import org.orekit.orbits.PositionAngleType;
24  import org.orekit.propagation.FieldSpacecraftState;
25  import org.orekit.propagation.PropagationType;
26  import org.orekit.time.FieldAbsoluteDate;
27  
28  /** This class maps between raw double elements and {@link FieldSpacecraftState} instances.
29   * @author Luc Maisonobe
30   * @param <T> type of the field elements
31   */
32  public abstract class FieldStateMapper<T extends CalculusFieldElement<T>> {
33  
34      /** Reference date. */
35      private final FieldAbsoluteDate<T> referenceDate;
36  
37      /** Propagation orbit type. */
38      private final OrbitType orbitType;
39  
40      /** Position angle type. */
41      private final PositionAngleType angleType;
42  
43      /** Attitude provider. */
44      private AttitudeProvider attitudeProvider;
45  
46      /** Central attraction coefficient. */
47      private final T mu;
48  
49      /** Inertial frame. */
50      private final Frame frame;
51  
52      /** Simple constructor.
53       * <p>
54       * The position parameter type is meaningful only if {@link
55       * #getOrbitType() propagation orbit type}
56       * support it. As an example, it is not meaningful for propagation
57       * in {@link  OrbitType#CARTESIAN Cartesian} parameters.
58       * </p>
59       * @param referenceDate reference date
60       * @param mu central attraction coefficient (m³/s²)
61       * @param orbitType orbit type to use for mapping
62       * @param positionAngleType angle type to use for propagation
63       * @param attitudeProvider attitude provider
64       * @param frame inertial frame
65       */
66      protected FieldStateMapper(final FieldAbsoluteDate<T> referenceDate, final T mu,
67                            final OrbitType orbitType, final PositionAngleType positionAngleType,
68                            final AttitudeProvider attitudeProvider, final Frame frame) {
69          this.referenceDate    = referenceDate;
70          this.mu               = mu;
71          this.orbitType        = orbitType;
72          this.angleType        = positionAngleType;
73          this.attitudeProvider = attitudeProvider;
74          this.frame            = frame;
75      }
76  
77      /** Get reference date.
78       * @return reference date
79       */
80      public FieldAbsoluteDate<T> getReferenceDate() {
81          return referenceDate;
82      }
83  
84      /** Get propagation parameter type.
85       * @return orbit type used for propagation
86       */
87      public  OrbitType getOrbitType() {
88          return orbitType;
89      }
90  
91      /** Set position angle type.
92       */
93      public void setPositionAngleType() {
94      }
95  
96      /** Get propagation parameter type.
97       * @return angle type to use for propagation
98       */
99      public PositionAngleType getPositionAngleType() {
100         return angleType;
101     }
102 
103     /** Get the central attraction coefficient μ.
104      * @return mu central attraction coefficient (m³/s²)
105      */
106     public T getMu() {
107         return mu;
108     }
109 
110     /** Get the inertial frame.
111      * @return inertial frame
112      */
113     public Frame getFrame() {
114         return frame;
115     }
116 
117     /** Get the attitude provider.
118      * @return attitude provider
119      */
120     public AttitudeProvider getAttitudeProvider() {
121         return attitudeProvider;
122     }
123 
124     /**
125      * Setter for the attitude provider.
126      * @param attitudeProvider new attitude provider
127      */
128     public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
129         this.attitudeProvider = attitudeProvider;
130     }
131 
132     /** Map the raw double time offset to a date.
133      * @param t date offset
134      * @return date
135      */
136     public FieldAbsoluteDate<T> mapDoubleToDate(final T t) {
137         return referenceDate.shiftedBy(t);
138     }
139 
140     /**
141      * Map the raw double time offset to a date.
142      *
143      * @param t    date offset
144      * @param date The expected date.
145      * @return {@code date} if it is the same time as {@code t} to within the
146      * lower precision of the latter. Otherwise a new date is returned that
147      * corresponds to time {@code t}.
148      */
149     public FieldAbsoluteDate<T> mapDoubleToDate(final T t,
150                                         final FieldAbsoluteDate<T> date) {
151         if (date.durationFrom(referenceDate).getReal() == t.getReal()) {
152             return date;
153         } else {
154             return mapDoubleToDate(t);
155         }
156     }
157 
158     /** Map a date to a raw double time offset.
159      * @param date date
160      * @return time offset
161      */
162     public T mapDateToDouble(final FieldAbsoluteDate<T> date) {
163         return date.durationFrom(referenceDate);
164     }
165 
166     /** Map the raw double components to a spacecraft state.
167      * @param t date offset
168      * @param y state components
169      * @param yDot state derivative components
170      * @param type type of the elements used to build the state (mean or osculating)
171      * @return spacecraft state
172      */
173     public FieldSpacecraftState<T> mapArrayToState(final T t, final T[] y, final T[] yDot, final PropagationType type) {
174         return mapArrayToState(mapDoubleToDate(t), y, yDot, type);
175     }
176 
177     /** Map the raw double components to a spacecraft state.
178      * @param date of the state components
179      * @param y state components
180      * @param yDot state derivative components
181      * @param type type of the elements used to build the state (mean or osculating).
182      * @return spacecraft state
183      */
184     public abstract FieldSpacecraftState<T> mapArrayToState(FieldAbsoluteDate<T> date, T[] y, T[] yDot, PropagationType type);
185 
186     /** Map a spacecraft state to raw double components.
187      * @param state state to map
188      * @param y placeholder where to put the components
189      * @param yDot placeholder where to put the components derivatives
190      */
191     public abstract void mapStateToArray(FieldSpacecraftState<T> state, T[] y, T[] yDot);
192 
193 }