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.nonstiff.interpolators;
24
25 import java.util.Arrays;
26
27 import org.hipparchus.CalculusFieldElement;
28 import org.hipparchus.linear.Array2DRowFieldMatrix;
29 import org.hipparchus.ode.FieldEquationsMapper;
30 import org.hipparchus.ode.FieldODEStateAndDerivative;
31 import org.hipparchus.ode.nonstiff.AdamsBashforthFieldIntegrator;
32 import org.hipparchus.ode.nonstiff.AdamsMoultonFieldIntegrator;
33 import org.hipparchus.ode.sampling.AbstractFieldODEStateInterpolator;
34 import org.hipparchus.util.MathArrays;
35
36
37
38
39
40
41
42
43
44
45
46
47 public class AdamsFieldStateInterpolator<T extends CalculusFieldElement<T>> extends AbstractFieldODEStateInterpolator<T> {
48
49
50 private T scalingH;
51
52
53
54
55
56
57
58 private final FieldODEStateAndDerivative<T> reference;
59
60
61 private final T[] scaled;
62
63
64 private final Array2DRowFieldMatrix<T> nordsieck;
65
66
67
68
69
70
71
72
73
74
75
76 public AdamsFieldStateInterpolator(final T stepSize, final FieldODEStateAndDerivative<T> reference,
77 final T[] scaled, final Array2DRowFieldMatrix<T> nordsieck,
78 final boolean isForward,
79 final FieldODEStateAndDerivative<T> globalPreviousState,
80 final FieldODEStateAndDerivative<T> globalCurrentState,
81 final FieldEquationsMapper<T> equationsMapper) {
82 this(stepSize, reference, scaled, nordsieck, isForward, globalPreviousState, globalCurrentState,
83 globalPreviousState, globalCurrentState, equationsMapper);
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97
98 private AdamsFieldStateInterpolator(final T stepSize, final FieldODEStateAndDerivative<T> reference,
99 final T[] scaled, final Array2DRowFieldMatrix<T> nordsieck,
100 final boolean isForward,
101 final FieldODEStateAndDerivative<T> globalPreviousState,
102 final FieldODEStateAndDerivative<T> globalCurrentState,
103 final FieldODEStateAndDerivative<T> softPreviousState,
104 final FieldODEStateAndDerivative<T> softCurrentState,
105 final FieldEquationsMapper<T> equationsMapper) {
106 super(isForward, globalPreviousState, globalCurrentState,
107 softPreviousState, softCurrentState, equationsMapper);
108 this.scalingH = stepSize;
109 this.reference = reference;
110 this.scaled = scaled.clone();
111 this.nordsieck = new Array2DRowFieldMatrix<>(nordsieck.getData(), false);
112 }
113
114
115
116
117
118
119
120
121
122
123 @Override
124 protected AdamsFieldStateInterpolator<T> create(boolean newForward,
125 FieldODEStateAndDerivative<T> newGlobalPreviousState,
126 FieldODEStateAndDerivative<T> newGlobalCurrentState,
127 FieldODEStateAndDerivative<T> newSoftPreviousState,
128 FieldODEStateAndDerivative<T> newSoftCurrentState,
129 FieldEquationsMapper<T> newMapper) {
130 return new AdamsFieldStateInterpolator<>(scalingH, reference, scaled, nordsieck,
131 newForward,
132 newGlobalPreviousState, newGlobalCurrentState,
133 newSoftPreviousState, newSoftCurrentState,
134 newMapper);
135
136 }
137
138
139
140
141 public T[] getScaled() {
142 return scaled.clone();
143 }
144
145
146
147
148 public Array2DRowFieldMatrix<T> getNordsieck() {
149 return new Array2DRowFieldMatrix<>(nordsieck.getData());
150 }
151
152
153 @Override
154 protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> equationsMapper,
155 final T time, final T theta,
156 final T thetaH, final T oneMinusThetaH) {
157 return taylor(equationsMapper, reference, time, scalingH, scaled, nordsieck);
158 }
159
160
161
162
163
164
165
166
167
168
169
170 public static <S extends CalculusFieldElement<S>> FieldODEStateAndDerivative<S> taylor(final FieldEquationsMapper<S> equationsMapper,
171 final FieldODEStateAndDerivative<S> reference,
172 final S time, final S stepSize,
173 final S[] scaled,
174 final Array2DRowFieldMatrix<S> nordsieck) {
175
176 final S x = time.subtract(reference.getTime());
177 final S normalizedAbscissa = x.divide(stepSize);
178
179 S[] stateVariation = MathArrays.buildArray(time.getField(), scaled.length);
180 Arrays.fill(stateVariation, time.getField().getZero());
181 S[] estimatedDerivatives = MathArrays.buildArray(time.getField(), scaled.length);
182 Arrays.fill(estimatedDerivatives, time.getField().getZero());
183
184
185
186 final S[][] nData = nordsieck.getDataRef();
187 for (int i = nData.length - 1; i >= 0; --i) {
188 final int order = i + 2;
189 final S[] nDataI = nData[i];
190 final S power = normalizedAbscissa.pow(order);
191 for (int j = 0; j < nDataI.length; ++j) {
192 final S d = nDataI[j].multiply(power);
193 stateVariation[j] = stateVariation[j].add(d);
194 estimatedDerivatives[j] = estimatedDerivatives[j].add(d.multiply(order));
195 }
196 }
197
198 S[] estimatedState = reference.getCompleteState();
199 for (int j = 0; j < stateVariation.length; ++j) {
200 stateVariation[j] = stateVariation[j].add(scaled[j].multiply(normalizedAbscissa));
201 estimatedState[j] = estimatedState[j].add(stateVariation[j]);
202 estimatedDerivatives[j] =
203 estimatedDerivatives[j].add(scaled[j].multiply(normalizedAbscissa)).divide(x);
204 }
205
206 return equationsMapper.mapStateAndDerivative(time, estimatedState, estimatedDerivatives);
207
208 }
209
210 }