1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.orekit.attitudes.AttitudeProvider;
26 import org.orekit.errors.OrekitException;
27 import org.orekit.errors.OrekitMessages;
28 import org.orekit.frames.Frame;
29 import org.orekit.propagation.events.EventDetector;
30 import org.orekit.propagation.sampling.OrekitFixedStepHandler;
31 import org.orekit.propagation.sampling.OrekitStepHandler;
32 import org.orekit.propagation.sampling.OrekitStepNormalizer;
33 import org.orekit.time.AbsoluteDate;
34 import org.orekit.utils.TimeStampedPVCoordinates;
35
36
37
38
39
40
41
42
43
44 public abstract class AbstractPropagator implements Propagator {
45
46
47 private int mode;
48
49
50 private double fixedStepSize;
51
52
53 private OrekitStepHandler stepHandler;
54
55
56 private AbsoluteDate startDate;
57
58
59 private AttitudeProvider attitudeProvider;
60
61
62 private final List<AdditionalStateProvider> additionalStateProviders;
63
64
65 private SpacecraftState initialState;
66
67
68
69 protected AbstractPropagator() {
70 mode = SLAVE_MODE;
71 stepHandler = null;
72 fixedStepSize = Double.NaN;
73 additionalStateProviders = new ArrayList<AdditionalStateProvider>();
74 }
75
76
77
78
79 protected void setStartDate(final AbsoluteDate startDate) {
80 this.startDate = startDate;
81 }
82
83
84
85
86 protected AbsoluteDate getStartDate() {
87 return startDate;
88 }
89
90
91 public AttitudeProvider getAttitudeProvider() {
92 return attitudeProvider;
93 }
94
95
96 public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
97 this.attitudeProvider = attitudeProvider;
98 }
99
100
101 public SpacecraftState getInitialState() throws OrekitException {
102 return initialState;
103 }
104
105
106 public int getMode() {
107 return mode;
108 }
109
110
111 public Frame getFrame() {
112 return initialState.getFrame();
113 }
114
115
116 public void resetInitialState(final SpacecraftState state) throws OrekitException {
117 initialState = state;
118 setStartDate(state.getDate());
119 }
120
121
122 public void setSlaveMode() {
123 mode = SLAVE_MODE;
124 stepHandler = null;
125 fixedStepSize = Double.NaN;
126 }
127
128
129 public void setMasterMode(final double h,
130 final OrekitFixedStepHandler handler) {
131 setMasterMode(new OrekitStepNormalizer(h, handler));
132 fixedStepSize = h;
133 }
134
135
136 public void setMasterMode(final OrekitStepHandler handler) {
137 mode = MASTER_MODE;
138 stepHandler = handler;
139 fixedStepSize = Double.NaN;
140 }
141
142
143 public void setEphemerisMode() {
144 mode = EPHEMERIS_GENERATION_MODE;
145 stepHandler = null;
146 fixedStepSize = Double.NaN;
147 }
148
149
150 @Override
151 public void setEphemerisMode(final OrekitStepHandler handler) {
152 mode = EPHEMERIS_GENERATION_MODE;
153 stepHandler = handler;
154 fixedStepSize = Double.NaN;
155 }
156
157
158 public void addAdditionalStateProvider(final AdditionalStateProvider additionalStateProvider)
159 throws OrekitException {
160
161
162 if (isAdditionalStateManaged(additionalStateProvider.getName())) {
163
164 throw new OrekitException(OrekitMessages.ADDITIONAL_STATE_NAME_ALREADY_IN_USE,
165 additionalStateProvider.getName());
166 }
167
168
169 additionalStateProviders.add(additionalStateProvider);
170
171 }
172
173
174 public List<AdditionalStateProvider> getAdditionalStateProviders() {
175 return Collections.unmodifiableList(additionalStateProviders);
176 }
177
178
179
180
181
182
183
184 protected SpacecraftState updateAdditionalStates(final SpacecraftState original)
185 throws OrekitException {
186
187
188
189 SpacecraftState updated = original;
190
191 if (initialState != null) {
192
193
194
195 for (final Map.Entry<String, double[]> initial : initialState.getAdditionalStates().entrySet()) {
196 if (!isAdditionalStateManaged(initial.getKey())) {
197
198
199 updated = updated.addAdditionalState(initial.getKey(), initial.getValue());
200 }
201 }
202 }
203
204
205 for (final AdditionalStateProvider provider : additionalStateProviders) {
206 updated = updated.addAdditionalState(provider.getName(),
207 provider.getAdditionalState(updated));
208 }
209
210 return updated;
211
212 }
213
214
215 public boolean isAdditionalStateManaged(final String name) {
216 for (final AdditionalStateProvider provider : additionalStateProviders) {
217 if (provider.getName().equals(name)) {
218 return true;
219 }
220 }
221 return false;
222 }
223
224
225 public String[] getManagedAdditionalStates() {
226 final String[] managed = new String[additionalStateProviders.size()];
227 for (int i = 0; i < managed.length; ++i) {
228 managed[i] = additionalStateProviders.get(i).getName();
229 }
230 return managed;
231 }
232
233
234
235
236 protected double getFixedStepSize() {
237 return fixedStepSize;
238 }
239
240
241
242
243 protected OrekitStepHandler getStepHandler() {
244 return stepHandler;
245 }
246
247
248 public abstract BoundedPropagator getGeneratedEphemeris();
249
250
251 public abstract <T extends EventDetector> void addEventDetector(T detector);
252
253
254 public abstract Collection<EventDetector> getEventsDetectors();
255
256
257 public abstract void clearEventsDetectors();
258
259
260 public SpacecraftState propagate(final AbsoluteDate target) throws OrekitException {
261 if (startDate == null) {
262 startDate = getInitialState().getDate();
263 }
264 return propagate(startDate, target);
265 }
266
267
268 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame)
269 throws OrekitException {
270 return propagate(date).getPVCoordinates(frame);
271 }
272
273 }