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.forces;
18
19 import java.util.List;
20 import java.util.stream.Stream;
21
22 import org.hipparchus.CalculusFieldElement;
23 import org.hipparchus.Field;
24 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
25 import org.hipparchus.geometry.euclidean.threed.Vector3D;
26 import org.hipparchus.util.MathArrays;
27 import org.orekit.propagation.FieldSpacecraftState;
28 import org.orekit.propagation.SpacecraftState;
29 import org.orekit.propagation.events.EventDetector;
30 import org.orekit.propagation.events.FieldEventDetector;
31 import org.orekit.propagation.numerical.FieldTimeDerivativesEquations;
32 import org.orekit.propagation.numerical.TimeDerivativesEquations;
33 import org.orekit.time.AbsoluteDate;
34 import org.orekit.time.FieldAbsoluteDate;
35 import org.orekit.utils.ParameterDriver;
36
37 /** This interface represents a force modifying spacecraft motion.
38 *
39 * <p>
40 * Objects implementing this interface are intended to be added to a
41 * {@link org.orekit.propagation.numerical.NumericalPropagator numerical propagator}
42 * before the propagation is started.
43 *
44 * <p>
45 * The propagator will call at each step the {@link #addContribution(SpacecraftState,
46 * TimeDerivativesEquations)} method. The force model instance will extract all the
47 * state data it needs (date, position, velocity, frame, attitude, mass) from the first
48 * parameter. From these state data, it will compute the perturbing acceleration. It
49 * will then add this acceleration to the second parameter which will take thins
50 * contribution into account and will use the Gauss equations to evaluate its impact
51 * on the global state derivative.
52 * </p>
53 * <p>
54 * Force models which create discontinuous acceleration patterns (typically for maneuvers
55 * start/stop or solar eclipses entry/exit) must provide one or more {@link
56 * org.orekit.propagation.events.EventDetector events detectors} to the
57 * propagator thanks to their {@link #getEventsDetectors()} method. This method
58 * is called once just before propagation starts. The events states will be checked by
59 * the propagator to ensure accurate propagation and proper events handling.
60 * </p>
61 *
62 * @author Mathieu Roméro
63 * @author Luc Maisonobe
64 * @author Véronique Pommier-Maurussane
65 */
66 public interface ForceModel {
67
68 /**
69 * Initialize the force model at the start of propagation. This method will be called
70 * before any calls to {@link #addContribution(SpacecraftState, TimeDerivativesEquations)},
71 * {@link #addContribution(FieldSpacecraftState, FieldTimeDerivativesEquations)},
72 * {@link #acceleration(SpacecraftState, double[])} or {@link #acceleration(FieldSpacecraftState, CalculusFieldElement[])}
73 *
74 * <p> The default implementation of this method does nothing.</p>
75 *
76 * @param initialState spacecraft state at the start of propagation.
77 * @param target date of propagation. Not equal to {@code initialState.getDate()}.
78 */
79 default void init(SpacecraftState initialState, AbsoluteDate target) {
80 }
81
82 /**
83 * Initialize the force model at the start of propagation. This method will be called
84 * before any calls to {@link #addContribution(SpacecraftState, TimeDerivativesEquations)},
85 * {@link #addContribution(FieldSpacecraftState, FieldTimeDerivativesEquations)},
86 * {@link #acceleration(SpacecraftState, double[])} or {@link #acceleration(FieldSpacecraftState, CalculusFieldElement[])}
87 *
88 * <p> The default implementation of this method does nothing.</p>
89 *
90 * @param initialState spacecraft state at the start of propagation.
91 * @param target date of propagation. Not equal to {@code initialState.getDate()}.
92 * @param <T> type of the elements
93 */
94 default <T extends CalculusFieldElement<T>> void init(FieldSpacecraftState<T> initialState, FieldAbsoluteDate<T> target) {
95 init(initialState.toSpacecraftState(), target.toAbsoluteDate());
96 }
97
98 /** Compute the contribution of the force model to the perturbing
99 * acceleration.
100 * <p>
101 * The default implementation simply adds the {@link #acceleration(SpacecraftState, double[]) acceleration}
102 * as a non-Keplerian acceleration.
103 * </p>
104 * @param s current state information: date, kinematics, attitude
105 * @param adder object where the contribution should be added
106 */
107 default void addContribution(SpacecraftState s, TimeDerivativesEquations adder) {
108 adder.addNonKeplerianAcceleration(acceleration(s, getParameters()));
109 }
110
111 /** Compute the contribution of the force model to the perturbing
112 * acceleration.
113 * @param s current state information: date, kinematics, attitude
114 * @param adder object where the contribution should be added
115 * @param <T> type of the elements
116 */
117 default <T extends CalculusFieldElement<T>> void addContribution(FieldSpacecraftState<T> s, FieldTimeDerivativesEquations<T> adder) {
118 adder.addNonKeplerianAcceleration(acceleration(s, getParameters(s.getDate().getField())));
119 }
120
121 /** Get force model parameters.
122 * @return force model parameters
123 * @since 9.0
124 */
125 default double[] getParameters() {
126 final List<ParameterDriver> drivers = getParametersDrivers();
127 final double[] parameters = new double[drivers.size()];
128 for (int i = 0; i < drivers.size(); ++i) {
129 parameters[i] = drivers.get(i).getValue();
130 }
131 return parameters;
132 }
133
134 /** Get force model parameters.
135 * @param field field to which the elements belong
136 * @param <T> type of the elements
137 * @return force model parameters
138 * @since 9.0
139 */
140 default <T extends CalculusFieldElement<T>> T[] getParameters(final Field<T> field) {
141 final List<ParameterDriver> drivers = getParametersDrivers();
142 final T[] parameters = MathArrays.buildArray(field, drivers.size());
143 for (int i = 0; i < drivers.size(); ++i) {
144 parameters[i] = field.getZero().add(drivers.get(i).getValue());
145 }
146 return parameters;
147 }
148
149 /** Check if force models depends on position only.
150 * @return true if force model depends on position only, false
151 * if it depends on velocity, either directly or due to a dependency
152 * on attitude
153 * @since 9.0
154 */
155 boolean dependsOnPositionOnly();
156
157 /** Compute acceleration.
158 * @param s current state information: date, kinematics, attitude
159 * @param parameters values of the force model parameters
160 * @return acceleration in same frame as state
161 * @since 9.0
162 */
163 Vector3D acceleration(SpacecraftState s, double[] parameters);
164
165 /** Compute acceleration.
166 * @param s current state information: date, kinematics, attitude
167 * @param parameters values of the force model parameters
168 * @return acceleration in same frame as state
169 * @param <T> type of the elements
170 * @since 9.0
171 */
172 <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(FieldSpacecraftState<T> s, T[] parameters);
173
174 /** Get the discrete events related to the model.
175 * @return stream of events detectors
176 */
177 Stream<EventDetector> getEventsDetectors();
178
179 /** Get the discrete events related to the model.
180 * @param field field to which the state belongs
181 * @param <T> extends CalculusFieldElement<T>
182 * @return stream of events detectors
183 */
184 <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(Field<T> field);
185
186 /** Get the drivers for force model parameters.
187 * @return drivers for force model parameters
188 * @since 8.0
189 */
190 List<ParameterDriver> getParametersDrivers();
191
192 /** Get parameter value from its name.
193 * @param name parameter name
194 * @return parameter value
195 * @since 8.0
196 */
197 ParameterDriver getParameterDriver(String name);
198
199 /** Check if a parameter is supported.
200 * <p>Supported parameters are those listed by {@link #getParametersDrivers()}.</p>
201 * @param name parameter name to check
202 * @return true if the parameter is supported
203 * @see #getParametersDrivers()
204 */
205 boolean isSupported(String name);
206
207 }