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