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.ode.EquationsMapper;
21 import org.hipparchus.ode.ODEStateAndDerivative;
22 import org.hipparchus.ode.sampling.AbstractODEStateInterpolator;
23
24
25
26
27
28
29
30
31
32 abstract class RungeKuttaStateInterpolator extends AbstractODEStateInterpolator {
33
34
35 private static final long serialVersionUID = 20160328L;
36
37
38 protected double[][] yDotK;
39
40
41
42
43
44
45
46
47
48
49 protected RungeKuttaStateInterpolator(final boolean forward,
50 final double[][] yDotK,
51 final ODEStateAndDerivative globalPreviousState,
52 final ODEStateAndDerivative globalCurrentState,
53 final ODEStateAndDerivative softPreviousState,
54 final ODEStateAndDerivative softCurrentState,
55 final EquationsMapper mapper) {
56 super(forward, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
57 this.yDotK = new double[yDotK.length][];
58 for (int i = 0; i < yDotK.length; ++i) {
59 this.yDotK[i] = yDotK[i].clone();
60 }
61 }
62
63
64 @Override
65 protected RungeKuttaStateInterpolator create(boolean newForward,
66 ODEStateAndDerivative newGlobalPreviousState,
67 ODEStateAndDerivative newGlobalCurrentState,
68 ODEStateAndDerivative newSoftPreviousState,
69 ODEStateAndDerivative newSoftCurrentState,
70 EquationsMapper newMapper) {
71 return create(newForward, yDotK,
72 newGlobalPreviousState, newGlobalCurrentState,
73 newSoftPreviousState, newSoftCurrentState,
74 newMapper);
75 }
76
77
78
79
80
81
82
83
84
85
86
87 protected abstract RungeKuttaStateInterpolator create(boolean newForward, double[][] newYDotK,
88 ODEStateAndDerivative newGlobalPreviousState,
89 ODEStateAndDerivative newGlobalCurrentState,
90 ODEStateAndDerivative newSoftPreviousState,
91 ODEStateAndDerivative newSoftCurrentState,
92 EquationsMapper newMapper);
93
94
95
96
97
98 protected final double[] previousStateLinearCombination(final double ... coefficients) {
99 return combine(getGlobalPreviousState().getCompleteState(),
100 coefficients);
101 }
102
103
104
105
106
107 protected double[] currentStateLinearCombination(final double ... coefficients) {
108 return combine(getGlobalCurrentState().getCompleteState(),
109 coefficients);
110 }
111
112
113
114
115
116 protected double[] derivativeLinearCombination(final double ... coefficients) {
117 return combine(new double[yDotK[0].length], coefficients);
118 }
119
120
121
122
123
124
125 private double[] combine(final double[] a, final double ... coefficients) {
126 for (int i = 0; i < a.length; ++i) {
127 for (int k = 0; k < coefficients.length; ++k) {
128 a[i] += coefficients[k] * yDotK[k][i];
129 }
130 }
131 return a;
132 }
133
134 }