1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.hipparchus.ode.nonstiff;
19
20 import org.hipparchus.ode.EquationsMapper;
21 import org.hipparchus.ode.ODEStateAndDerivative;
22
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 class ThreeEighthesStateInterpolator
57 extends RungeKuttaStateInterpolator {
58
59
60 private static final long serialVersionUID = 20160328L;
61
62
63
64
65
66
67
68
69
70
71 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,
79 globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
80 mapper);
81 }
82
83
84 @Override
85 protected ThreeEighthesStateInterpolator create(final boolean newForward, final double[][] newYDotK,
86 final ODEStateAndDerivative newGlobalPreviousState,
87 final ODEStateAndDerivative newGlobalCurrentState,
88 final ODEStateAndDerivative newSoftPreviousState,
89 final ODEStateAndDerivative newSoftCurrentState,
90 final EquationsMapper newMapper) {
91 return new ThreeEighthesStateInterpolator(newForward, newYDotK,
92 newGlobalPreviousState, newGlobalCurrentState,
93 newSoftPreviousState, newSoftCurrentState,
94 newMapper);
95 }
96
97
98 @Override
99 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
100 final double time, final double theta,
101 final double thetaH, final double oneMinusThetaH) {
102
103 final double coeffDot3 = 0.75 * theta;
104 final double coeffDot1 = coeffDot3 * (4 * theta - 5) + 1;
105 final double coeffDot2 = coeffDot3 * (5 - 6 * theta);
106 final double coeffDot4 = coeffDot3 * (2 * theta - 1);
107 final double[] interpolatedState;
108 final double[] interpolatedDerivatives;
109
110 if (getGlobalPreviousState() != null && theta <= 0.5) {
111 final double s = thetaH / 8.0;
112 final double fourTheta2 = 4 * theta * theta;
113 final double coeff1 = s * (8 - 15 * theta + 2 * fourTheta2);
114 final double coeff2 = 3 * s * (5 * theta - fourTheta2);
115 final double coeff3 = 3 * s * theta;
116 final double coeff4 = s * (-3 * theta + fourTheta2);
117 interpolatedState = previousStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
118 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4);
119 } else {
120 final double s = oneMinusThetaH / -8.0;
121 final double fourTheta2 = 4 * theta * theta;
122 final double coeff1 = s * (1 - 7 * theta + 2 * fourTheta2);
123 final double coeff2 = 3 * s * (1 + theta - fourTheta2);
124 final double coeff3 = 3 * s * (1 + theta);
125 final double coeff4 = s * (1 + theta + fourTheta2);
126 interpolatedState = currentStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
127 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4);
128 }
129
130 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
131
132 }
133
134 }