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