1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.hipparchus.ode.sampling;
24
25 import org.hipparchus.CalculusFieldElement;
26 import org.hipparchus.exception.MathIllegalStateException;
27 import org.hipparchus.ode.FieldEquationsMapper;
28 import org.hipparchus.ode.FieldODEStateAndDerivative;
29 import org.hipparchus.util.FastMath;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public abstract class AbstractFieldODEStateInterpolator<T extends CalculusFieldElement<T>>
46 implements FieldODEStateInterpolator<T> {
47
48
49 private final FieldODEStateAndDerivative<T> globalPreviousState;
50
51
52 private final FieldODEStateAndDerivative<T> globalCurrentState;
53
54
55 private final FieldODEStateAndDerivative<T> softPreviousState;
56
57
58 private final FieldODEStateAndDerivative<T> softCurrentState;
59
60
61 private final boolean forward;
62
63
64 private FieldEquationsMapper<T> mapper;
65
66
67
68
69
70
71
72
73
74 protected AbstractFieldODEStateInterpolator(final boolean isForward,
75 final FieldODEStateAndDerivative<T> globalPreviousState,
76 final FieldODEStateAndDerivative<T> globalCurrentState,
77 final FieldODEStateAndDerivative<T> softPreviousState,
78 final FieldODEStateAndDerivative<T> softCurrentState,
79 final FieldEquationsMapper<T> equationsMapper) {
80 this.forward = isForward;
81 this.globalPreviousState = globalPreviousState;
82 this.globalCurrentState = globalCurrentState;
83 this.softPreviousState = softPreviousState;
84 this.softCurrentState = softCurrentState;
85 this.mapper = equationsMapper;
86 }
87
88
89
90
91
92
93
94
95
96
97
98 public AbstractFieldODEStateInterpolator<T> restrictStep(final FieldODEStateAndDerivative<T> previousState,
99 final FieldODEStateAndDerivative<T> currentState) {
100 return create(forward, globalPreviousState, globalCurrentState, previousState, currentState, mapper);
101 }
102
103
104
105
106
107
108
109
110
111
112 protected abstract AbstractFieldODEStateInterpolator<T> create(boolean newForward,
113 FieldODEStateAndDerivative<T> newGlobalPreviousState,
114 FieldODEStateAndDerivative<T> newGlobalCurrentState,
115 FieldODEStateAndDerivative<T> newSoftPreviousState,
116 FieldODEStateAndDerivative<T> newSoftCurrentState,
117 FieldEquationsMapper<T> newMapper);
118
119
120
121
122
123 public FieldODEStateAndDerivative<T> getGlobalPreviousState() {
124 return globalPreviousState;
125 }
126
127
128
129
130
131 public FieldODEStateAndDerivative<T> getGlobalCurrentState() {
132 return globalCurrentState;
133 }
134
135
136 @Override
137 public FieldODEStateAndDerivative<T> getPreviousState() {
138 return softPreviousState;
139 }
140
141
142 @Override
143 public boolean isPreviousStateInterpolated() {
144 return softPreviousState != globalPreviousState;
145 }
146
147
148 @Override
149 public FieldODEStateAndDerivative<T> getCurrentState() {
150 return softCurrentState;
151 }
152
153
154 @Override
155 public boolean isCurrentStateInterpolated() {
156 return softCurrentState != globalCurrentState;
157 }
158
159
160 @Override
161 public FieldODEStateAndDerivative<T> getInterpolatedState(final T time) {
162 if (FastMath.abs(globalCurrentState.getTime().subtract(globalPreviousState.getTime()).getReal()) <=
163 FastMath.ulp(globalCurrentState.getTime().getReal())) {
164 return globalCurrentState;
165 }
166 final T thetaH = time.subtract(globalPreviousState.getTime());
167 final T oneMinusThetaH = globalCurrentState.getTime().subtract(time);
168 final T theta = thetaH.divide(globalCurrentState.getTime().subtract(globalPreviousState.getTime()));
169 return computeInterpolatedStateAndDerivatives(mapper, time, theta, thetaH, oneMinusThetaH);
170 }
171
172
173 @Override
174 public boolean isForward() {
175 return forward;
176 }
177
178
179
180
181 protected FieldEquationsMapper<T> getMapper() {
182 return mapper;
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 protected abstract FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(FieldEquationsMapper<T> equationsMapper,
199 T time, T theta,
200 T thetaH, T oneMinusThetaH)
201 throws MathIllegalStateException;
202
203 }