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 class ClassicalRungeKuttaStateInterpolator
55 extends RungeKuttaStateInterpolator {
56
57
58 private static final long serialVersionUID = 20160328L;
59
60
61
62
63
64
65
66
67
68
69 ClassicalRungeKuttaStateInterpolator(final boolean forward,
70 final double[][] yDotK,
71 final ODEStateAndDerivative globalPreviousState,
72 final ODEStateAndDerivative globalCurrentState,
73 final ODEStateAndDerivative softPreviousState,
74 final ODEStateAndDerivative softCurrentState,
75 final EquationsMapper mapper) {
76 super(forward, yDotK,
77 globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
78 mapper);
79 }
80
81
82 @Override
83 protected ClassicalRungeKuttaStateInterpolator 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 ClassicalRungeKuttaStateInterpolator(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 oneMinusTheta = 1.0 - theta;
102 final double oneMinus2Theta = 1.0 - theta * 2.0;
103 final double coeffDot1 = oneMinusTheta * oneMinus2Theta;
104 final double coeffDot23 = theta * oneMinusTheta * 2;
105 final double coeffDot4 = -theta * oneMinus2Theta;
106 final double[] interpolatedState;
107 final double[] interpolatedDerivatives;
108
109 if (getGlobalPreviousState() != null && theta <= 0.5) {
110 final double fourTheta2 = theta * theta * 4;
111 final double s = thetaH / 6.0;
112 final double coeff1 = s * (fourTheta2 - theta * 9 + 6);
113 final double coeff23 = s * (theta * 6 - fourTheta2);
114 final double coeff4 = s * (fourTheta2 - theta * 3);
115 interpolatedState = previousStateLinearCombination(coeff1, coeff23, coeff23, coeff4);
116 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot23, coeffDot23, coeffDot4);
117 } else {
118 final double fourTheta = theta * 4;
119 final double s = oneMinusThetaH / 6.0;
120 final double coeff1 = s * (theta * (-fourTheta + 5) - 1);
121 final double coeff23 = s * (theta * ( fourTheta - 2) - 2);
122 final double coeff4 = s * (theta * (-fourTheta - 1) - 1);
123 interpolatedState = currentStateLinearCombination(coeff1, coeff23, coeff23, coeff4);
124 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot23, coeffDot23, coeffDot4);
125 }
126
127 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
128
129 }
130
131 }