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