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 final 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 @Override
90 public AbstractFieldODEStateInterpolator<T> restrictStep(final FieldODEStateAndDerivative<T> previousState,
91 final FieldODEStateAndDerivative<T> currentState) {
92 return create(forward, globalPreviousState, globalCurrentState, previousState, currentState, mapper);
93 }
94
95
96
97
98
99
100
101
102
103
104 protected abstract AbstractFieldODEStateInterpolator<T> create(boolean newForward,
105 FieldODEStateAndDerivative<T> newGlobalPreviousState,
106 FieldODEStateAndDerivative<T> newGlobalCurrentState,
107 FieldODEStateAndDerivative<T> newSoftPreviousState,
108 FieldODEStateAndDerivative<T> newSoftCurrentState,
109 FieldEquationsMapper<T> newMapper);
110
111
112
113
114
115 public FieldODEStateAndDerivative<T> getGlobalPreviousState() {
116 return globalPreviousState;
117 }
118
119
120
121
122
123 public FieldODEStateAndDerivative<T> getGlobalCurrentState() {
124 return globalCurrentState;
125 }
126
127
128 @Override
129 public FieldODEStateAndDerivative<T> getPreviousState() {
130 return softPreviousState;
131 }
132
133
134 @Override
135 public boolean isPreviousStateInterpolated() {
136 return softPreviousState != globalPreviousState;
137 }
138
139
140 @Override
141 public FieldODEStateAndDerivative<T> getCurrentState() {
142 return softCurrentState;
143 }
144
145
146 @Override
147 public boolean isCurrentStateInterpolated() {
148 return softCurrentState != globalCurrentState;
149 }
150
151
152 @Override
153 public FieldODEStateAndDerivative<T> getInterpolatedState(final T time) {
154 if (FastMath.abs(globalCurrentState.getTime().subtract(globalPreviousState.getTime()).getReal()) <=
155 FastMath.ulp(globalCurrentState.getTime().getReal())) {
156 return globalCurrentState;
157 }
158 final T thetaH = time.subtract(globalPreviousState.getTime());
159 final T oneMinusThetaH = globalCurrentState.getTime().subtract(time);
160 final T theta = thetaH.divide(globalCurrentState.getTime().subtract(globalPreviousState.getTime()));
161 return computeInterpolatedStateAndDerivatives(mapper, time, theta, thetaH, oneMinusThetaH);
162 }
163
164
165 @Override
166 public boolean isForward() {
167 return forward;
168 }
169
170
171
172
173 protected FieldEquationsMapper<T> getMapper() {
174 return mapper;
175 }
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190 protected abstract FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(FieldEquationsMapper<T> equationsMapper,
191 T time, T theta,
192 T thetaH, T oneMinusThetaH)
193 throws MathIllegalStateException;
194
195 }