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