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() {
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) {
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
160
161 if (isAdditionalStateManaged(additionalStateProvider.getName())) {
162
163 throw new OrekitException(OrekitMessages.ADDITIONAL_STATE_NAME_ALREADY_IN_USE,
164 additionalStateProvider.getName());
165 }
166
167
168 additionalStateProviders.add(additionalStateProvider);
169
170 }
171
172
173 public List<AdditionalStateProvider> getAdditionalStateProviders() {
174 return Collections.unmodifiableList(additionalStateProviders);
175 }
176
177
178
179
180
181
182 protected SpacecraftStateate">SpacecraftState updateAdditionalStates(final SpacecraftState original) {
183
184
185
186 SpacecraftState updated = original;
187
188 if (initialState != null) {
189
190
191
192 for (final Map.Entry<String, double[]> initial : initialState.getAdditionalStates().entrySet()) {
193 if (!isAdditionalStateManaged(initial.getKey())) {
194
195
196 updated = updated.addAdditionalState(initial.getKey(), initial.getValue());
197 }
198 }
199 }
200
201
202 for (final AdditionalStateProvider provider : additionalStateProviders) {
203 updated = updated.addAdditionalState(provider.getName(),
204 provider.getAdditionalState(updated));
205 }
206
207 return updated;
208
209 }
210
211
212 public boolean isAdditionalStateManaged(final String name) {
213 for (final AdditionalStateProvider provider : additionalStateProviders) {
214 if (provider.getName().equals(name)) {
215 return true;
216 }
217 }
218 return false;
219 }
220
221
222 public String[] getManagedAdditionalStates() {
223 final String[] managed = new String[additionalStateProviders.size()];
224 for (int i = 0; i < managed.length; ++i) {
225 managed[i] = additionalStateProviders.get(i).getName();
226 }
227 return managed;
228 }
229
230
231
232
233 protected double getFixedStepSize() {
234 return fixedStepSize;
235 }
236
237
238
239
240 protected OrekitStepHandler getStepHandler() {
241 return stepHandler;
242 }
243
244
245 public abstract BoundedPropagator getGeneratedEphemeris();
246
247
248 public abstract <T extends EventDetector> void addEventDetector(T detector);
249
250
251 public abstract Collection<EventDetector> getEventsDetectors();
252
253
254 public abstract void clearEventsDetectors();
255
256
257 public SpacecraftState propagate(final AbsoluteDate target) {
258 if (startDate == null) {
259 startDate = getInitialState().getDate();
260 }
261 return propagate(startDate, target);
262 }
263
264
265 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame) {
266 return propagate(date).getPVCoordinates(frame);
267 }
268
269 }