1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.hipparchus.ode.nonstiff.interpolators;
19
20 import org.hipparchus.ode.EquationsMapper;
21 import org.hipparchus.ode.ODEStateAndDerivative;
22 import org.hipparchus.ode.nonstiff.EmbeddedRungeKuttaIntegrator;
23 import org.hipparchus.ode.nonstiff.FixedStepRungeKuttaIntegrator;
24 import org.hipparchus.ode.sampling.AbstractODEStateInterpolator;
25
26
27
28
29
30
31
32
33
34 public abstract class RungeKuttaStateInterpolator extends AbstractODEStateInterpolator {
35
36
37 private static final long serialVersionUID = 20160328L;
38
39
40 protected double[][] yDotK;
41
42
43
44
45
46
47
48
49
50
51 protected RungeKuttaStateInterpolator(final boolean forward,
52 final double[][] yDotK,
53 final ODEStateAndDerivative globalPreviousState,
54 final ODEStateAndDerivative globalCurrentState,
55 final ODEStateAndDerivative softPreviousState,
56 final ODEStateAndDerivative softCurrentState,
57 final EquationsMapper mapper) {
58 super(forward, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
59 this.yDotK = new double[yDotK.length][];
60 for (int i = 0; i < yDotK.length; ++i) {
61 this.yDotK[i] = yDotK[i].clone();
62 }
63 }
64
65
66 @Override
67 protected RungeKuttaStateInterpolator create(boolean newForward,
68 ODEStateAndDerivative newGlobalPreviousState,
69 ODEStateAndDerivative newGlobalCurrentState,
70 ODEStateAndDerivative newSoftPreviousState,
71 ODEStateAndDerivative newSoftCurrentState,
72 EquationsMapper newMapper) {
73 return create(newForward, yDotK, newGlobalPreviousState, newGlobalCurrentState,
74 newSoftPreviousState, newSoftCurrentState, 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 }