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 org.hipparchus.CalculusFieldElement;
26 import org.hipparchus.Field;
27 import org.hipparchus.ode.FieldEquationsMapper;
28 import org.hipparchus.ode.FieldODEStateAndDerivative;
29 import org.hipparchus.ode.nonstiff.EmbeddedRungeKuttaFieldIntegrator;
30 import org.hipparchus.ode.nonstiff.FixedStepRungeKuttaFieldIntegrator;
31 import org.hipparchus.ode.sampling.AbstractFieldODEStateInterpolator;
32 import org.hipparchus.util.MathArrays;
33
34
35
36
37
38
39
40
41
42
43 public abstract class RungeKuttaFieldStateInterpolator<T extends CalculusFieldElement<T>>
44 extends AbstractFieldODEStateInterpolator<T> {
45
46
47 private final Field<T> field;
48
49
50 private final T[][] yDotK;
51
52
53
54
55
56
57
58
59
60
61
62 protected RungeKuttaFieldStateInterpolator(final Field<T> field, final boolean forward,
63 final T[][] yDotK,
64 final FieldODEStateAndDerivative<T> globalPreviousState,
65 final FieldODEStateAndDerivative<T> globalCurrentState,
66 final FieldODEStateAndDerivative<T> softPreviousState,
67 final FieldODEStateAndDerivative<T> softCurrentState,
68 final FieldEquationsMapper<T> mapper) {
69 super(forward, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
70 this.field = field;
71 this.yDotK = MathArrays.buildArray(field, yDotK.length, -1);
72 for (int i = 0; i < yDotK.length; ++i) {
73 this.yDotK[i] = yDotK[i].clone();
74 }
75 }
76
77
78 @Override
79 protected RungeKuttaFieldStateInterpolator<T> create(boolean newForward,
80 FieldODEStateAndDerivative<T> newGlobalPreviousState,
81 FieldODEStateAndDerivative<T> newGlobalCurrentState,
82 FieldODEStateAndDerivative<T> newSoftPreviousState,
83 FieldODEStateAndDerivative<T> newSoftCurrentState,
84 FieldEquationsMapper<T> newMapper) {
85 return create(field, newForward, yDotK,
86 newGlobalPreviousState, newGlobalCurrentState,
87 newSoftPreviousState, newSoftCurrentState,
88 newMapper);
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102 protected abstract RungeKuttaFieldStateInterpolator<T> create(Field<T> newField, boolean newForward, T[][] newYDotK,
103 FieldODEStateAndDerivative<T> newGlobalPreviousState,
104 FieldODEStateAndDerivative<T> newGlobalCurrentState,
105 FieldODEStateAndDerivative<T> newSoftPreviousState,
106 FieldODEStateAndDerivative<T> newSoftCurrentState,
107 FieldEquationsMapper<T> newMapper);
108
109
110
111
112
113 @SafeVarargs
114 protected final T[] previousStateLinearCombination(final T ... coefficients) {
115 return combine(getGlobalPreviousState().getCompleteState(),
116 coefficients);
117 }
118
119
120
121
122
123 @SuppressWarnings("unchecked")
124 protected T[] currentStateLinearCombination(final T ... coefficients) {
125 return combine(getGlobalCurrentState().getCompleteState(),
126 coefficients);
127 }
128
129
130
131
132
133 @SuppressWarnings("unchecked")
134 protected T[] derivativeLinearCombination(final T ... coefficients) {
135 return combine(MathArrays.buildArray(field, yDotK[0].length), coefficients);
136 }
137
138
139
140
141
142
143 @SuppressWarnings("unchecked")
144 private T[] combine(final T[] a, final T ... coefficients) {
145 for (int i = 0; i < a.length; ++i) {
146 for (int k = 0; k < coefficients.length; ++k) {
147 a[i] = a[i].add(coefficients[k].multiply(yDotK[k][i]));
148 }
149 }
150 return a;
151 }
152
153 }