1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math4.legacy.ode.nonstiff;
19
20 import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator;
21
22
23
24
25
26
27
28
29
30
31 class HighamHall54StepInterpolator
32 extends RungeKuttaStepInterpolator {
33
34
35 private static final long serialVersionUID = 20111120L;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public HighamHall54StepInterpolator() {
51 super();
52 }
53
54
55
56
57
58
59
60 HighamHall54StepInterpolator(final HighamHall54StepInterpolator interpolator) {
61 super(interpolator);
62 }
63
64
65 @Override
66 protected StepInterpolator doCopy() {
67 return new HighamHall54StepInterpolator(this);
68 }
69
70
71
72 @Override
73 protected void computeInterpolatedStateAndDerivatives(final double theta,
74 final double oneMinusThetaH) {
75
76 final double bDot0 = 1 + theta * (-15.0/2.0 + theta * (16.0 - 10.0 * theta));
77 final double bDot2 = theta * (459.0/16.0 + theta * (-729.0/8.0 + 135.0/2.0 * theta));
78 final double bDot3 = theta * (-44.0 + theta * (152.0 - 120.0 * theta));
79 final double bDot4 = theta * (375.0/16.0 + theta * (-625.0/8.0 + 125.0/2.0 * theta));
80 final double bDot5 = theta * 5.0/8.0 * (2 * theta - 1);
81
82 if (previousState != null && theta <= 0.5) {
83 final double hTheta = h * theta;
84 final double b0 = hTheta * (1.0 + theta * (-15.0/4.0 + theta * (16.0/3.0 - 5.0/2.0 * theta)));
85 final double b2 = hTheta * ( theta * (459.0/32.0 + theta * (-243.0/8.0 + theta * 135.0/8.0)));
86 final double b3 = hTheta * ( theta * (-22.0 + theta * (152.0/3.0 + theta * -30.0)));
87 final double b4 = hTheta * ( theta * (375.0/32.0 + theta * (-625.0/24.0 + theta * 125.0/8.0)));
88 final double b5 = hTheta * ( theta * (-5.0/16.0 + theta * 5.0/12.0));
89 for (int i = 0; i < interpolatedState.length; ++i) {
90 final double yDot0 = yDotK[0][i];
91 final double yDot2 = yDotK[2][i];
92 final double yDot3 = yDotK[3][i];
93 final double yDot4 = yDotK[4][i];
94 final double yDot5 = yDotK[5][i];
95 interpolatedState[i] =
96 previousState[i] + b0 * yDot0 + b2 * yDot2 + b3 * yDot3 + b4 * yDot4 + b5 * yDot5;
97 interpolatedDerivatives[i] =
98 bDot0 * yDot0 + bDot2 * yDot2 + bDot3 * yDot3 + bDot4 * yDot4 + bDot5 * yDot5;
99 }
100 } else {
101 final double theta2 = theta * theta;
102 final double b0 = h * (-1.0/12.0 + theta * (1.0 + theta * (-15.0/4.0 + theta * (16.0/3.0 + theta * -5.0/2.0))));
103 final double b2 = h * (-27.0/32.0 + theta2 * (459.0/32.0 + theta * (-243.0/8.0 + theta * 135.0/8.0)));
104 final double b3 = h * (4.0/3.0 + theta2 * (-22.0 + theta * (152.0/3.0 + theta * -30.0)));
105 final double b4 = h * (-125.0/96.0 + theta2 * (375.0/32.0 + theta * (-625.0/24.0 + theta * 125.0/8.0)));
106 final double b5 = h * (-5.0/48.0 + theta2 * (-5.0/16.0 + theta * 5.0/12.0));
107 for (int i = 0; i < interpolatedState.length; ++i) {
108 final double yDot0 = yDotK[0][i];
109 final double yDot2 = yDotK[2][i];
110 final double yDot3 = yDotK[3][i];
111 final double yDot4 = yDotK[4][i];
112 final double yDot5 = yDotK[5][i];
113 interpolatedState[i] =
114 currentState[i] + b0 * yDot0 + b2 * yDot2 + b3 * yDot3 + b4 * yDot4 + b5 * yDot5;
115 interpolatedDerivatives[i] =
116 bDot0 * yDot0 + bDot2 * yDot2 + bDot3 * yDot3 + bDot4 * yDot4 + bDot5 * yDot5;
117 }
118 }
119 }
120 }