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.LutherIntegrator;
23 import org.hipparchus.util.FastMath;
24
25
26
27
28
29
30
31
32
33
34
35
36 public class LutherStateInterpolator extends RungeKuttaStateInterpolator {
37
38
39 private static final long serialVersionUID = 20160328;
40
41
42 private static final double Q = FastMath.sqrt(21);
43
44
45
46
47
48
49
50
51
52
53 public LutherStateInterpolator(final boolean forward,
54 final double[][] yDotK,
55 final ODEStateAndDerivative globalPreviousState,
56 final ODEStateAndDerivative globalCurrentState,
57 final ODEStateAndDerivative softPreviousState,
58 final ODEStateAndDerivative softCurrentState,
59 final EquationsMapper mapper) {
60 super(forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
61 }
62
63
64 @Override
65 protected LutherStateInterpolator create(final boolean newForward, final double[][] newYDotK,
66 final ODEStateAndDerivative newGlobalPreviousState,
67 final ODEStateAndDerivative newGlobalCurrentState,
68 final ODEStateAndDerivative newSoftPreviousState,
69 final ODEStateAndDerivative newSoftCurrentState,
70 final EquationsMapper newMapper) {
71 return new LutherStateInterpolator(newForward, newYDotK,
72 newGlobalPreviousState, newGlobalCurrentState,
73 newSoftPreviousState, newSoftCurrentState,
74 newMapper);
75 }
76
77
78 @Override
79 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
80 final double time, final double theta,
81 final double thetaH, final double oneMinusThetaH) {
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 final double[] interpolatedState;
127 final double[] interpolatedDerivatives;
128
129 final double coeffDot1 = 1 + theta * ( -54 / 5.0 + theta * ( 36 + theta * ( -47 + theta * 21)));
130 final double coeffDot2 = 0;
131 final double coeffDot3 = theta * (-208 / 15.0 + theta * ( 320 / 3.0 + theta * (-608 / 3.0 + theta * 112)));
132 final double coeffDot4 = theta * ( 324 / 25.0 + theta * ( -486 / 5.0 + theta * ( 972 / 5.0 + theta * -567 / 5.0)));
133 final double coeffDot5 = theta * ((833 + 343 * Q) / 150.0 + theta * ((-637 - 357 * Q) / 30.0 + theta * ((392 + 287 * Q) / 15.0 + theta * (-49 - 49 * Q) / 5.0)));
134 final double coeffDot6 = theta * ((833 - 343 * Q) / 150.0 + theta * ((-637 + 357 * Q) / 30.0 + theta * ((392 - 287 * Q) / 15.0 + theta * (-49 + 49 * Q) / 5.0)));
135 final double coeffDot7 = theta * ( 3 / 5.0 + theta * ( -3 + theta * 3));
136
137 if (getGlobalPreviousState() != null && theta <= 0.5) {
138
139 final double coeff1 = 1 + theta * ( -27 / 5.0 + theta * ( 12 + theta * ( -47 / 4.0 + theta * 21 / 5.0)));
140 final double coeff2 = 0;
141 final double coeff3 = theta * (-104 / 15.0 + theta * ( 320 / 9.0 + theta * (-152 / 3.0 + theta * 112 / 5.0)));
142 final double coeff4 = theta * ( 162 / 25.0 + theta * ( -162 / 5.0 + theta * ( 243 / 5.0 + theta * -567 / 25.0)));
143 final double coeff5 = theta * ((833 + 343 * Q) / 300.0 + theta * ((-637 - 357 * Q) / 90.0 + theta * ((392 + 287 * Q) / 60.0 + theta * (-49 - 49 * Q) / 25.0)));
144 final double coeff6 = theta * ((833 - 343 * Q) / 300.0 + theta * ((-637 + 357 * Q) / 90.0 + theta * ((392 - 287 * Q) / 60.0 + theta * (-49 + 49 * Q) / 25.0)));
145 final double coeff7 = theta * ( 3 / 10.0 + theta * ( -1 + theta * ( 3 / 4.0)));
146 interpolatedState = previousStateLinearCombination(thetaH * coeff1, thetaH * coeff2,
147 thetaH * coeff3, thetaH * coeff4,
148 thetaH * coeff5, thetaH * coeff6,
149 thetaH * coeff7);
150 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4, coeffDot5, coeffDot6, coeffDot7);
151 } else {
152
153 final double coeff1 = -1 / 20.0 + theta * ( 19 / 20.0 + theta * ( -89 / 20.0 + theta * ( 151 / 20.0 + theta * -21 / 5.0)));
154 final double coeff2 = 0;
155 final double coeff3 = -16 / 45.0 + theta * ( -16 / 45.0 + theta * ( -328 / 45.0 + theta * ( 424 / 15.0 + theta * -112 / 5.0)));
156 final double coeff4 = theta * ( theta * ( 162 / 25.0 + theta * ( -648 / 25.0 + theta * 567 / 25.0)));
157 final double coeff5 = -49 / 180.0 + theta * ( -49 / 180.0 + theta * ((2254 + 1029 * Q) / 900.0 + theta * ((-1372 - 847 * Q) / 300.0 + theta * ( 49 + 49 * Q) / 25.0)));
158 final double coeff6 = -49 / 180.0 + theta * ( -49 / 180.0 + theta * ((2254 - 1029 * Q) / 900.0 + theta * ((-1372 + 847 * Q) / 300.0 + theta * ( 49 - 49 * Q) / 25.0)));
159 final double coeff7 = -1 / 20.0 + theta * ( -1 / 20.0 + theta * ( 1 / 4.0 + theta * ( -3 / 4.0)));
160 interpolatedState = currentStateLinearCombination(oneMinusThetaH * coeff1, oneMinusThetaH * coeff2,
161 oneMinusThetaH * coeff3, oneMinusThetaH * coeff4,
162 oneMinusThetaH * coeff5, oneMinusThetaH * coeff6,
163 oneMinusThetaH * coeff7);
164 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4, coeffDot5, coeffDot6, coeffDot7);
165 }
166
167 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
168
169 }
170
171 }