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