1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.hipparchus.ode.nonstiff;
19
20 import org.hipparchus.linear.Array2DRowRealMatrix;
21 import org.hipparchus.ode.EquationsMapper;
22 import org.hipparchus.ode.ODEStateAndDerivative;
23 import org.hipparchus.ode.sampling.AbstractODEStateInterpolator;
24 import org.hipparchus.util.FastMath;
25
26
27
28
29
30
31
32
33
34
35
36 class AdamsStateInterpolator extends AbstractODEStateInterpolator {
37
38
39 private static final long serialVersionUID = 20160402L;
40
41
42 private double scalingH;
43
44
45
46
47
48
49
50 private final ODEStateAndDerivative reference;
51
52
53 private double[] scaled;
54
55
56 private Array2DRowRealMatrix nordsieck;
57
58
59
60
61
62
63
64
65
66
67
68 AdamsStateInterpolator(final double stepSize, final ODEStateAndDerivative reference,
69 final double[] scaled, final Array2DRowRealMatrix nordsieck,
70 final boolean isForward,
71 final ODEStateAndDerivative globalPreviousState,
72 final ODEStateAndDerivative globalCurrentState,
73 final EquationsMapper equationsMapper) {
74 this(stepSize, reference, scaled, nordsieck,
75 isForward, globalPreviousState, globalCurrentState,
76 globalPreviousState, globalCurrentState, equationsMapper);
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90
91 private AdamsStateInterpolator(final double stepSize, final ODEStateAndDerivative reference,
92 final double[] scaled, final Array2DRowRealMatrix nordsieck,
93 final boolean isForward,
94 final ODEStateAndDerivative globalPreviousState,
95 final ODEStateAndDerivative globalCurrentState,
96 final ODEStateAndDerivative softPreviousState,
97 final ODEStateAndDerivative softCurrentState,
98 final EquationsMapper equationsMapper) {
99 super(isForward, globalPreviousState, globalCurrentState,
100 softPreviousState, softCurrentState, equationsMapper);
101 this.scalingH = stepSize;
102 this.reference = reference;
103 this.scaled = scaled.clone();
104 this.nordsieck = new Array2DRowRealMatrix(nordsieck.getData(), false);
105 }
106
107
108
109
110
111
112
113
114
115
116 @Override
117 protected AdamsStateInterpolator create(boolean newForward,
118 ODEStateAndDerivative newGlobalPreviousState,
119 ODEStateAndDerivative newGlobalCurrentState,
120 ODEStateAndDerivative newSoftPreviousState,
121 ODEStateAndDerivative newSoftCurrentState,
122 EquationsMapper newMapper) {
123 return new AdamsStateInterpolator(scalingH, reference, scaled, nordsieck,
124 newForward,
125 newGlobalPreviousState, newGlobalCurrentState,
126 newSoftPreviousState, newSoftCurrentState,
127 newMapper);
128
129 }
130
131
132
133
134 public double[] getScaled() {
135 return scaled.clone();
136 }
137
138
139
140
141 public Array2DRowRealMatrix getNordsieck() {
142 return nordsieck;
143 }
144
145
146 @Override
147 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper equationsMapper,
148 final double time, final double theta,
149 final double thetaH, final double oneMinusThetaH) {
150 return taylor(equationsMapper, reference, time, scalingH, scaled, nordsieck);
151 }
152
153
154
155
156
157
158
159
160
161
162 public static ODEStateAndDerivative taylor(final EquationsMapper equationsMapper,
163 final ODEStateAndDerivative reference,
164 final double time, final double stepSize,
165 final double[] scaled,
166 final Array2DRowRealMatrix nordsieck) {
167
168 final double x = time - reference.getTime();
169 final double normalizedAbscissa = x / stepSize;
170
171 double[] stateVariation = new double[scaled.length];
172 double[] estimatedDerivatives = new double[scaled.length];
173
174
175
176 final double[][] nData = nordsieck.getDataRef();
177 for (int i = nData.length - 1; i >= 0; --i) {
178 final int order = i + 2;
179 final double[] nDataI = nData[i];
180 final double power = FastMath.pow(normalizedAbscissa, order);
181 for (int j = 0; j < nDataI.length; ++j) {
182 final double d = nDataI[j] * power;
183 stateVariation[j] = stateVariation[j] + d;
184 estimatedDerivatives[j] = estimatedDerivatives[j] + d * order;
185 }
186 }
187
188 double[] estimatedState = reference.getCompleteState();
189 for (int j = 0; j < stateVariation.length; ++j) {
190 stateVariation[j] = stateVariation[j] + scaled[j] * normalizedAbscissa;
191 estimatedState[j] = estimatedState[j] + stateVariation[j];
192 estimatedDerivatives[j] = (estimatedDerivatives[j] + scaled[j] * normalizedAbscissa) / x;
193 }
194
195 return equationsMapper.mapStateAndDerivative(time, estimatedState, estimatedDerivatives);
196
197 }
198
199 }