1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation.integration;
18
19 import java.io.NotSerializableException;
20 import java.io.Serializable;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.commons.math3.ode.ContinuousOutputModel;
28 import org.orekit.errors.OrekitException;
29 import org.orekit.errors.OrekitExceptionWrapper;
30 import org.orekit.errors.OrekitMessages;
31 import org.orekit.errors.PropagationException;
32 import org.orekit.frames.Frame;
33 import org.orekit.orbits.Orbit;
34 import org.orekit.propagation.AdditionalStateProvider;
35 import org.orekit.propagation.BoundedPropagator;
36 import org.orekit.propagation.SpacecraftState;
37 import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
38 import org.orekit.time.AbsoluteDate;
39 import org.orekit.utils.TimeStampedPVCoordinates;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public class IntegratedEphemeris
76 extends AbstractAnalyticalPropagator implements BoundedPropagator, Serializable {
77
78
79 private static final long serialVersionUID = 20140213L;
80
81
82 private final StateMapper mapper;
83
84
85
86
87
88
89
90 private boolean meanOrbit;
91
92
93 private final AbsoluteDate startDate;
94
95
96 private final AbsoluteDate minDate;
97
98
99 private final AbsoluteDate maxDate;
100
101
102 private ContinuousOutputModel model;
103
104
105 private final Map<String, double[]> unmanaged;
106
107
108
109
110
111
112
113
114
115
116
117
118
119 public IntegratedEphemeris(final AbsoluteDate startDate,
120 final AbsoluteDate minDate, final AbsoluteDate maxDate,
121 final StateMapper mapper, final boolean meanOrbit,
122 final ContinuousOutputModel model,
123 final Map<String, double[]> unmanaged,
124 final List<AdditionalStateProvider> providers,
125 final String[] equations)
126 throws OrekitException {
127
128 super(mapper.getAttitudeProvider());
129
130 this.startDate = startDate;
131 this.minDate = minDate;
132 this.maxDate = maxDate;
133 this.mapper = mapper;
134 this.meanOrbit = meanOrbit;
135 this.model = model;
136 this.unmanaged = unmanaged;
137
138
139 for (final AdditionalStateProvider provider : providers) {
140 addAdditionalStateProvider(provider);
141 }
142
143
144 for (int i = 0; i < equations.length; ++i) {
145 addAdditionalStateProvider(new LocalProvider(equations[i], i));
146 }
147
148 }
149
150
151
152
153
154
155 private void setInterpolationDate(final AbsoluteDate date)
156 throws PropagationException {
157
158 if (date.equals(startDate.shiftedBy(model.getInterpolatedTime()))) {
159
160 return;
161 }
162
163 if ((date.compareTo(minDate) < 0) || (date.compareTo(maxDate) > 0)) {
164
165 throw new PropagationException(OrekitMessages.OUT_OF_RANGE_EPHEMERIDES_DATE,
166 date, minDate, maxDate);
167 }
168
169
170 model.setInterpolatedTime(date.durationFrom(startDate));
171
172 }
173
174
175 @Override
176 protected SpacecraftState basicPropagate(final AbsoluteDate date)
177 throws PropagationException {
178 try {
179 setInterpolationDate(date);
180 SpacecraftState state = mapper.mapArrayToState(model.getInterpolatedTime(),
181 model.getInterpolatedState(),
182 meanOrbit);
183 for (Map.Entry<String, double[]> initial : unmanaged.entrySet()) {
184 state = state.addAdditionalState(initial.getKey(), initial.getValue());
185 }
186 return state;
187 } catch (OrekitExceptionWrapper oew) {
188 if (oew.getException() instanceof PropagationException) {
189 throw (PropagationException) oew.getException();
190 } else {
191 throw new PropagationException(oew.getException());
192 }
193 } catch (OrekitException oe) {
194 if (oe instanceof PropagationException) {
195 throw (PropagationException) oe;
196 } else {
197 throw new PropagationException(oe);
198 }
199 }
200 }
201
202
203 protected Orbit propagateOrbit(final AbsoluteDate date)
204 throws PropagationException {
205 return basicPropagate(date).getOrbit();
206 }
207
208
209 protected double getMass(final AbsoluteDate date) throws PropagationException {
210 return basicPropagate(date).getMass();
211 }
212
213
214 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame)
215 throws OrekitException {
216 return propagate(date).getPVCoordinates(frame);
217 }
218
219
220
221
222 public AbsoluteDate getMinDate() {
223 return minDate;
224 }
225
226
227
228
229 public AbsoluteDate getMaxDate() {
230 return maxDate;
231 }
232
233 @Override
234 public Frame getFrame() {
235 return this.mapper.getFrame();
236 }
237
238
239 public void resetInitialState(final SpacecraftState state)
240 throws PropagationException {
241 throw new PropagationException(OrekitMessages.NON_RESETABLE_STATE);
242 }
243
244
245 public SpacecraftState getInitialState() throws PropagationException {
246 return updateAdditionalStates(basicPropagate(getMinDate()));
247 }
248
249
250
251
252
253 private Object writeReplace() throws NotSerializableException {
254
255
256 final String[] unmanagedNames = new String[unmanaged.size()];
257 final double[][] unmanagedValues = new double[unmanaged.size()][];
258 int i = 0;
259 for (Map.Entry<String, double[]> entry : unmanaged.entrySet()) {
260 unmanagedNames[i] = entry.getKey();
261 unmanagedValues[i] = entry.getValue();
262 ++i;
263 }
264
265
266 final List<AdditionalStateProvider> serializableProviders = new ArrayList<AdditionalStateProvider>();
267 final List<String> equationNames = new ArrayList<String>();
268 for (final AdditionalStateProvider provider : getAdditionalStateProviders()) {
269 if (provider instanceof LocalProvider) {
270 equationNames.add(((LocalProvider) provider).getName());
271 } else if (provider instanceof Serializable) {
272 serializableProviders.add(provider);
273 }
274 }
275
276 return new DataTransferObject(startDate, minDate, maxDate, mapper, meanOrbit, model,
277 unmanagedNames, unmanagedValues,
278 serializableProviders.toArray(new AdditionalStateProvider[serializableProviders.size()]),
279 equationNames.toArray(new String[equationNames.size()]));
280
281 }
282
283
284 private class LocalProvider implements AdditionalStateProvider {
285
286
287 private final String name;
288
289
290 private final int index;
291
292
293
294
295
296 public LocalProvider(final String name, final int index) {
297 this.name = name;
298 this.index = index;
299 }
300
301
302 public String getName() {
303 return name;
304 }
305
306
307 public double[] getAdditionalState(final SpacecraftState state)
308 throws PropagationException {
309
310
311 setInterpolationDate(state.getDate());
312
313
314 return model.getInterpolatedSecondaryState(index);
315
316 }
317
318 }
319
320
321 private static class DataTransferObject implements Serializable {
322
323
324 private static final long serialVersionUID = 20140213L;
325
326
327 private final StateMapper mapper;
328
329
330 private final boolean meanOrbit;
331
332
333 private final AbsoluteDate startDate;
334
335
336 private final AbsoluteDate minDate;
337
338
339 private final AbsoluteDate maxDate;
340
341
342 private final ContinuousOutputModel model;
343
344
345 private final String[] unmanagedNames;
346
347
348 private final double[][] unmanagedValues;
349
350
351 private final String[] equations;
352
353
354 private final AdditionalStateProvider[] providers;
355
356
357
358
359
360
361
362
363
364
365
366
367
368 public DataTransferObject(final AbsoluteDate startDate,
369 final AbsoluteDate minDate, final AbsoluteDate maxDate,
370 final StateMapper mapper, final boolean meanOrbit,
371 final ContinuousOutputModel model,
372 final String[] unmanagedNames, final double[][] unmanagedValues,
373 final AdditionalStateProvider[] providers,
374 final String[] equations) {
375 this.startDate = startDate;
376 this.minDate = minDate;
377 this.maxDate = maxDate;
378 this.mapper = mapper;
379 this.meanOrbit = meanOrbit;
380 this.model = model;
381 this.unmanagedNames = unmanagedNames;
382 this.unmanagedValues = unmanagedValues;
383 this.providers = providers;
384 this.equations = equations;
385 }
386
387
388
389
390 private Object readResolve() {
391 try {
392 final Map<String, double[]> unmanaged = new HashMap<String, double[]>(unmanagedNames.length);
393 for (int i = 0; i < unmanagedNames.length; ++i) {
394 unmanaged.put(unmanagedNames[i], unmanagedValues[i]);
395 }
396 return new IntegratedEphemeris(startDate, minDate, maxDate, mapper, meanOrbit, model,
397 unmanaged, Arrays.asList(providers), equations);
398 } catch (OrekitException oe) {
399 throw OrekitException.createInternalError(oe);
400 }
401 }
402
403 }
404
405 }