1   /* Copyright 2002-2022 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.semianalytical.dsst.forces;
18  
19  import java.util.List;
20  
21  import org.hipparchus.Field;
22  import org.hipparchus.CalculusFieldElement;
23  import org.hipparchus.util.MathArrays;
24  import org.orekit.attitudes.AttitudeProvider;
25  import org.orekit.propagation.FieldSpacecraftState;
26  import org.orekit.propagation.PropagationType;
27  import org.orekit.propagation.SpacecraftState;
28  import org.orekit.propagation.events.EventDetector;
29  import org.orekit.propagation.events.FieldEventDetector;
30  import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
31  import org.orekit.propagation.semianalytical.dsst.utilities.FieldAuxiliaryElements;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.time.FieldAbsoluteDate;
34  import org.orekit.utils.ParameterDriver;
35  
36  /** This interface represents a force modifying spacecraft motion for a {@link
37   *  org.orekit.propagation.semianalytical.dsst.DSSTPropagator DSSTPropagator}.
38   *  <p>
39   *  Objects implementing this interface are intended to be added to a {@link
40   *  org.orekit.propagation.semianalytical.dsst.DSSTPropagator DSST propagator}
41   *  before the propagation is started.
42   *  </p>
43   *  <p>
44   *  The propagator will call at the very beginning of a propagation the {@link
45   *  #initializeShortPeriodTerms(AuxiliaryElements, PropagationType, double[])} method allowing
46   *  preliminary computation such as truncation if needed.
47   *  </p>
48   *  <p>
49   *  Then the propagator will call at each step:
50   *  <ol>
51   *  <li>the {@link #getMeanElementRate(SpacecraftState, AuxiliaryElements, double[])} method.
52   *  The force model instance will extract all the state data needed to compute
53   *  the mean element rates that contribute to the mean state derivative.</li>
54   *  <li>the {@link #updateShortPeriodTerms(double[], SpacecraftState...)} method,
55   *  if osculating parameters are desired, on a sample of points within the
56   *  last step.</li>
57   *  </ol>
58   *
59   * @author Romain Di Constanzo
60   * @author Pascal Parraud
61   */
62  public interface DSSTForceModel {
63  
64      /**
65       * Initialize the force model at the start of propagation.
66       * <p> The default implementation of this method does nothing.</p>
67       *
68       * @param initialState spacecraft state at the start of propagation.
69       * @param target       date of propagation. Not equal to {@code initialState.getDate()}.
70       * @since 11.0
71       */
72      default void init(SpacecraftState initialState, AbsoluteDate target) {
73      }
74  
75      /**
76       * Initialize the force model at the start of propagation.
77       * <p> The default implementation of this method does nothing.</p>
78       *
79       * @param initialState spacecraft state at the start of propagation.
80       * @param target       date of propagation. Not equal to {@code initialState.getDate()}.
81       * @param <T> type of the elements
82       * @since 11.1
83       */
84      default <T extends CalculusFieldElement<T>> void init(FieldSpacecraftState<T> initialState, FieldAbsoluteDate<T> target) {
85          init(initialState.toSpacecraftState(), target.toAbsoluteDate());
86      }
87  
88      /** Performs initialization prior to propagation for the current force model.
89       *  <p>
90       *  This method aims at being called at the very beginning of a propagation.
91       *  </p>
92       *  @param auxiliaryElements auxiliary elements related to the current orbit
93       *  @param type type of the elements used during the propagation
94       *  @param parameters values of the force model parameters
95       *  @return a list of objects that will hold short period terms (the objects
96       *  are also retained by the force model, which will update them during propagation)
97       */
98      List<ShortPeriodTerms> initializeShortPeriodTerms(AuxiliaryElements auxiliaryElements,
99                                                        PropagationType type, double[] parameters);
100 
101     /** Performs initialization prior to propagation for the current force model.
102      *  <p>
103      *  This method aims at being called at the very beginning of a propagation.
104      *  </p>
105      *  @param <T> type of the elements
106      *  @param auxiliaryElements auxiliary elements related to the current orbit
107      *  @param type type of the elements used during the propagation
108      *  @param parameters values of the force model parameters
109      *  @return a list of objects that will hold short period terms (the objects
110      *  are also retained by the force model, which will update them during propagation)
111      */
112     <T extends CalculusFieldElement<T>> List<FieldShortPeriodTerms<T>> initializeShortPeriodTerms(FieldAuxiliaryElements<T> auxiliaryElements,
113                                                                                               PropagationType type, T[] parameters);
114 
115     /** Get force model parameters.
116      * @return force model parameters
117      * @since 9.0
118      */
119     default double[] getParameters() {
120         final List<ParameterDriver> drivers = getParametersDrivers();
121         final double[] parameters = new double[drivers.size()];
122         for (int i = 0; i < drivers.size(); ++i) {
123             parameters[i] = drivers.get(i).getValue();
124         }
125         return parameters;
126     }
127 
128     /** Get force model parameters.
129      * @param field field to which the elements belong
130      * @param <T> type of the elements
131      * @return force model parameters
132      * @since 9.0
133      */
134     default <T extends CalculusFieldElement<T>> T[] getParameters(final Field<T> field) {
135         final List<ParameterDriver> drivers = getParametersDrivers();
136         final T[] parameters = MathArrays.buildArray(field, drivers.size());
137         for (int i = 0; i < drivers.size(); ++i) {
138             parameters[i] = field.getZero().add(drivers.get(i).getValue());
139         }
140         return parameters;
141     }
142 
143     /** Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
144      *
145      *  @param state current state information: date, kinematics, attitude
146      *  @param auxiliaryElements auxiliary elements related to the current orbit
147      *  @param parameters values of the force model parameters
148      *  @return the mean element rates dai/dt
149      */
150     double[] getMeanElementRate(SpacecraftState state,
151                                 AuxiliaryElements auxiliaryElements, double[] parameters);
152 
153     /** Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
154      *
155      *  @param <T> type of the elements
156      *  @param state current state information: date, kinematics, attitude
157      *  @param auxiliaryElements auxiliary elements related to the current orbit
158      *  @param parameters values of the force model parameters
159      *  @return the mean element rates dai/dt
160      */
161     <T extends CalculusFieldElement<T>> T[] getMeanElementRate(FieldSpacecraftState<T> state,
162                                                            FieldAuxiliaryElements<T> auxiliaryElements, T[] parameters);
163 
164 
165     /** Get the discrete events related to the model.
166      * @return array of events detectors or null if the model is not
167      * related to any discrete events
168      */
169     EventDetector[] getEventsDetectors();
170 
171     /** Get the discrete events related to the model.
172      * @param <T> type of the elements
173      * @param field field used by default
174      * @return array of events detectors or null if the model is not
175      * related to any discrete events
176      */
177     <T extends CalculusFieldElement<T>> FieldEventDetector<T>[] getFieldEventsDetectors(Field<T> field);
178 
179     /** Register an attitude provider.
180      * <p>
181      * Register an attitude provider that can be used by the force model.
182      * </p>
183      * @param provider the {@link AttitudeProvider}
184      */
185     void registerAttitudeProvider(AttitudeProvider provider);
186 
187     /** Update the short period terms.
188      * <p>
189      * The {@link ShortPeriodTerms short period terms} that will be updated
190      * are the ones that were returned during the call to {@link
191      * #initializeShortPeriodTerms(AuxiliaryElements, PropagationType, double[])}.
192      * </p>
193      * @param parameters values of the force model parameters
194      * @param meanStates mean states information: date, kinematics, attitude
195      */
196     void updateShortPeriodTerms(double[] parameters, SpacecraftState... meanStates);
197 
198     /** Update the short period terms.
199      * <p>
200      * The {@link ShortPeriodTerms short period terms} that will be updated
201      * are the ones that were returned during the call to {@link
202      * #initializeShortPeriodTerms(AuxiliaryElements, PropagationType, double[])}.
203      * </p>
204      * @param <T> type of the elements
205      * @param parameters values of the force model parameters
206      * @param meanStates mean states information: date, kinematics, attitude
207      */
208     @SuppressWarnings("unchecked")
209     <T extends CalculusFieldElement<T>> void updateShortPeriodTerms(T[] parameters, FieldSpacecraftState<T>... meanStates);
210 
211     /** Get the drivers for force model parameters.
212      * @return drivers for force model parameters
213      */
214     List<ParameterDriver> getParametersDrivers();
215 
216 }