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 import org.hipparchus.util.FastMath;
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 GillStateInterpolator
55 extends RungeKuttaStateInterpolator {
56
57
58 private static final double ONE_MINUS_INV_SQRT_2 = 1 - FastMath.sqrt(0.5);
59
60
61 private static final double ONE_PLUS_INV_SQRT_2 = 1 + FastMath.sqrt(0.5);
62
63
64 private static final long serialVersionUID = 20160328L;
65
66
67
68
69
70
71
72
73
74
75 GillStateInterpolator(final boolean forward,
76 final double[][] yDotK,
77 final ODEStateAndDerivative globalPreviousState,
78 final ODEStateAndDerivative globalCurrentState,
79 final ODEStateAndDerivative softPreviousState,
80 final ODEStateAndDerivative softCurrentState,
81 final EquationsMapper mapper) {
82 super(forward, yDotK,
83 globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
84 mapper);
85 }
86
87
88 @Override
89 protected GillStateInterpolator create(final boolean newForward, final double[][] newYDotK,
90 final ODEStateAndDerivative newGlobalPreviousState,
91 final ODEStateAndDerivative newGlobalCurrentState,
92 final ODEStateAndDerivative newSoftPreviousState,
93 final ODEStateAndDerivative newSoftCurrentState,
94 final EquationsMapper newMapper) {
95 return new GillStateInterpolator(newForward, newYDotK,
96 newGlobalPreviousState, newGlobalCurrentState,
97 newSoftPreviousState, newSoftCurrentState,
98 newMapper);
99 }
100
101
102 @Override
103 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
104 final double time, final double theta,
105 final double thetaH, final double oneMinusThetaH) {
106
107 final double twoTheta = 2 * theta;
108 final double fourTheta2 = twoTheta * twoTheta;
109 final double coeffDot1 = theta * (twoTheta - 3) + 1;
110 final double cDot23 = twoTheta * (1 - theta);
111 final double coeffDot2 = cDot23 * ONE_MINUS_INV_SQRT_2;
112 final double coeffDot3 = cDot23 * ONE_PLUS_INV_SQRT_2;
113 final double coeffDot4 = theta * (twoTheta - 1);
114
115 final double[] interpolatedState;
116 final double[] interpolatedDerivatives;
117 if (getGlobalPreviousState() != null && theta <= 0.5) {
118 final double s = thetaH / 6.0;
119 final double c23 = s * (6 * theta - fourTheta2);
120 final double coeff1 = s * (6 - 9 * theta + fourTheta2);
121 final double coeff2 = c23 * ONE_MINUS_INV_SQRT_2;
122 final double coeff3 = c23 * ONE_PLUS_INV_SQRT_2;
123 final double coeff4 = s * (-3 * theta + fourTheta2);
124 interpolatedState = previousStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
125 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3 , coeffDot4);
126 } else {
127 final double s = oneMinusThetaH / -6.0;
128 final double c23 = s * (2 + twoTheta - fourTheta2);
129 final double coeff1 = s * (1 - 5 * theta + fourTheta2);
130 final double coeff2 = c23 * ONE_MINUS_INV_SQRT_2;
131 final double coeff3 = c23 * ONE_PLUS_INV_SQRT_2;
132 final double coeff4 = s * (1 + theta + fourTheta2);
133 interpolatedState = currentStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
134 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3 , coeffDot4);
135 }
136
137 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
138
139 }
140
141 }