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