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
21 import org.hipparchus.ode.EquationsMapper;
22 import org.hipparchus.ode.ExpandableODE;
23 import org.hipparchus.ode.ODEStateAndDerivative;
24
25 public abstract class RungeKuttaStateInterpolatorAbstractTest extends ODEStateInterpolatorAbstractTest {
26
27 protected abstract RungeKuttaStateInterpolator
28 createInterpolator(boolean forward, double[][] yDotK,
29 ODEStateAndDerivative globalPreviousState,
30 ODEStateAndDerivative globalCurrentState,
31 ODEStateAndDerivative softPreviousState,
32 ODEStateAndDerivative softCurrentState,
33 EquationsMapper mapper);
34
35 protected abstract ButcherArrayProvider createButcherArrayProvider();
36
37 protected RungeKuttaStateInterpolator setUpInterpolator(final ReferenceODE eqn,
38 final double t0, final double[] y0,
39 final double t1) {
40
41
42 ButcherArrayProvider provider = createButcherArrayProvider();
43 double[][] a = provider.getA();
44 double[] b = provider.getB();
45 double[] c = provider.getC();
46
47
48 EquationsMapper mapper = new ExpandableODE(eqn).getMapper();
49 double[][] yDotK = new double[b.length][];
50 yDotK[0] = eqn.computeDerivatives(t0, y0);
51 ODEStateAndDerivative s0 = mapper.mapStateAndDerivative(t0, y0, yDotK[0]);
52
53
54 double h = t1 - t0;
55 for (int k = 0; k < a.length; ++k) {
56 double[] y = y0.clone();
57 for (int i = 0; i < y0.length; ++i) {
58 for (int s = 0; s <= k; ++s) {
59 y[i] += h * a[k][s] * yDotK[s][i];
60 }
61 }
62 yDotK[k + 1] = eqn.computeDerivatives(t0 + h * c[k], y);
63 }
64
65
66 double[] y = y0.clone();
67 for (int i = 0; i < y0.length; ++i) {
68 for (int s = 0; s < b.length; ++s) {
69 y[i] += h * b[s] * yDotK[s][i];
70 }
71 }
72 ODEStateAndDerivative s1 = mapper.mapStateAndDerivative(t1, y, eqn.computeDerivatives(t1, y));
73
74 return createInterpolator(t1 > t0, yDotK, s0, s1, s0, s1, mapper);
75
76 }
77
78 }