1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation.sampling;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.stream.Collectors;
22
23 import org.hipparchus.util.FastMath;
24 import org.orekit.propagation.SpacecraftState;
25 import org.orekit.time.AbsoluteDate;
26
27
28
29
30
31
32
33
34
35
36
37 public class MultisatStepNormalizer implements MultiSatStepHandler {
38
39
40 private double h;
41
42
43 private MultiSatFixedStepHandler handler;
44
45
46 private List<SpacecraftState> lastStates;
47
48
49 private boolean forward;
50
51
52
53
54
55 public MultisatStepNormalizer(final double h, final MultiSatFixedStepHandler handler) {
56 this.h = FastMath.abs(h);
57 this.handler = handler;
58 this.lastStates = null;
59 this.forward = true;
60 }
61
62
63
64
65 public double getFixedTimeStep() {
66 return h;
67 }
68
69
70
71
72 public MultiSatFixedStepHandler getFixedStepHandler() {
73 return handler;
74 }
75
76
77 public void init(final List<SpacecraftState> s0, final AbsoluteDate t) {
78 lastStates = new ArrayList<>(s0);
79 forward = true;
80 handler.init(s0, t, h);
81 }
82
83
84 public void handleStep(final List<OrekitStepInterpolator> interpolators) {
85
86 if (lastStates == null) {
87
88 lastStates = interpolators.stream().map(OrekitStepInterpolator::getPreviousState).collect(Collectors.toList());
89 }
90
91
92 double step = h;
93 forward = interpolators.get(0).isForward();
94 if (!forward) {
95 step = -h;
96 }
97
98
99
100 AbsoluteDate nextTime = lastStates.get(0).getDate().shiftedBy(step);
101 boolean nextInStep = forward ^ nextTime.compareTo(interpolators.get(0).getCurrentState().getDate()) > 0;
102 while (nextInStep) {
103
104
105 handler.handleStep(lastStates);
106
107
108 final AbsoluteDate time = nextTime;
109 lastStates = interpolators.stream().map(i -> i.getInterpolatedState(time)).collect(Collectors.toList());
110
111
112 nextTime = nextTime.shiftedBy(step);
113 nextInStep = forward ^ nextTime.compareTo(interpolators.get(0).getCurrentState().getDate()) > 0;
114
115 }
116
117 }
118
119
120 @Override
121 public void finish(final List<SpacecraftState> finalStates) {
122
123
124
125 handler.handleStep(lastStates);
126
127
128 handler.finish(finalStates);
129
130 }
131
132 }