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.exception.MathIllegalStateException;
26 import org.hipparchus.ode.EquationsMapper;
27 import org.hipparchus.ode.ODEStateAndDerivative;
28 import org.hipparchus.util.FastMath;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public abstract class AbstractODEStateInterpolator
43 implements ODEStateInterpolator {
44
45
46 private static final long serialVersionUID = 20160328L;
47
48
49 private final ODEStateAndDerivative globalPreviousState;
50
51
52 private final ODEStateAndDerivative globalCurrentState;
53
54
55 private final ODEStateAndDerivative softPreviousState;
56
57
58 private final ODEStateAndDerivative softCurrentState;
59
60
61 private final boolean forward;
62
63
64 private EquationsMapper mapper;
65
66
67
68
69
70
71
72
73
74 protected AbstractODEStateInterpolator(final boolean isForward,
75 final ODEStateAndDerivative globalPreviousState,
76 final ODEStateAndDerivative globalCurrentState,
77 final ODEStateAndDerivative softPreviousState,
78 final ODEStateAndDerivative softCurrentState,
79 final EquationsMapper 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 AbstractODEStateInterpolator restrictStep(final ODEStateAndDerivative previousState,
99 final ODEStateAndDerivative currentState) {
100 return create(forward, globalPreviousState, globalCurrentState, previousState, currentState, mapper);
101 }
102
103
104
105
106
107
108
109
110
111
112 protected abstract AbstractODEStateInterpolator create(boolean newForward,
113 ODEStateAndDerivative newGlobalPreviousState,
114 ODEStateAndDerivative newGlobalCurrentState,
115 ODEStateAndDerivative newSoftPreviousState,
116 ODEStateAndDerivative newSoftCurrentState,
117 EquationsMapper newMapper);
118
119
120
121
122
123 public ODEStateAndDerivative getGlobalPreviousState() {
124 return globalPreviousState;
125 }
126
127
128
129
130
131 public ODEStateAndDerivative getGlobalCurrentState() {
132 return globalCurrentState;
133 }
134
135
136 @Override
137 public ODEStateAndDerivative getPreviousState() {
138 return softPreviousState;
139 }
140
141
142 @Override
143 public boolean isPreviousStateInterpolated() {
144 return softPreviousState != globalPreviousState;
145 }
146
147
148 @Override
149 public ODEStateAndDerivative getCurrentState() {
150 return softCurrentState;
151 }
152
153
154 @Override
155 public boolean isCurrentStateInterpolated() {
156 return softCurrentState != globalCurrentState;
157 }
158
159
160 @Override
161 public ODEStateAndDerivative getInterpolatedState(final double time) {
162 if (FastMath.abs(globalCurrentState.getTime() - globalPreviousState.getTime()) <=
163 FastMath.ulp(globalCurrentState.getTime())) {
164 return globalCurrentState;
165 }
166 final double thetaH = time - globalPreviousState.getTime();
167 final double oneMinusThetaH = globalCurrentState.getTime() - time;
168 final double theta = thetaH / (globalCurrentState.getTime() - 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 EquationsMapper getMapper() {
182 return mapper;
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 protected abstract ODEStateAndDerivative computeInterpolatedStateAndDerivatives(EquationsMapper equationsMapper,
199 double time, double theta,
200 double thetaH, double oneMinusThetaH)
201 throws MathIllegalStateException;
202
203 }