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.ThreeEighthesIntegrator;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 public class ThreeEighthesStateInterpolator extends RungeKuttaStateInterpolator {
58
59
60 private static final long serialVersionUID = 20160328L;
61
62
63
64
65
66
67
68
69
70
71 public ThreeEighthesStateInterpolator(final boolean forward,
72 final double[][] yDotK,
73 final ODEStateAndDerivative globalPreviousState,
74 final ODEStateAndDerivative globalCurrentState,
75 final ODEStateAndDerivative softPreviousState,
76 final ODEStateAndDerivative softCurrentState,
77 final EquationsMapper mapper) {
78 super(forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
79 }
80
81
82 @Override
83 protected ThreeEighthesStateInterpolator create(final boolean newForward, final double[][] newYDotK,
84 final ODEStateAndDerivative newGlobalPreviousState,
85 final ODEStateAndDerivative newGlobalCurrentState,
86 final ODEStateAndDerivative newSoftPreviousState,
87 final ODEStateAndDerivative newSoftCurrentState,
88 final EquationsMapper newMapper) {
89 return new ThreeEighthesStateInterpolator(newForward, newYDotK,
90 newGlobalPreviousState, newGlobalCurrentState,
91 newSoftPreviousState, newSoftCurrentState,
92 newMapper);
93 }
94
95
96 @Override
97 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
98 final double time, final double theta,
99 final double thetaH, final double oneMinusThetaH) {
100
101 final double coeffDot3 = 0.75 * theta;
102 final double coeffDot1 = coeffDot3 * (4 * theta - 5) + 1;
103 final double coeffDot2 = coeffDot3 * (5 - 6 * theta);
104 final double coeffDot4 = coeffDot3 * (2 * theta - 1);
105 final double[] interpolatedState;
106 final double[] interpolatedDerivatives;
107
108 if (getGlobalPreviousState() != null && theta <= 0.5) {
109 final double s = thetaH / 8.0;
110 final double fourTheta2 = 4 * theta * theta;
111 final double coeff1 = s * (8 - 15 * theta + 2 * fourTheta2);
112 final double coeff2 = 3 * s * (5 * theta - fourTheta2);
113 final double coeff3 = 3 * s * theta;
114 final double coeff4 = s * (-3 * theta + fourTheta2);
115 interpolatedState = previousStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
116 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4);
117 } else {
118 final double s = oneMinusThetaH / -8.0;
119 final double fourTheta2 = 4 * theta * theta;
120 final double coeff1 = s * (1 - 7 * theta + 2 * fourTheta2);
121 final double coeff2 = 3 * s * (1 + theta - fourTheta2);
122 final double coeff3 = 3 * s * (1 + theta);
123 final double coeff4 = s * (1 + theta + fourTheta2);
124 interpolatedState = currentStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
125 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4);
126 }
127
128 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
129
130 }
131
132 }