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.GillIntegrator;
23 import org.hipparchus.util.FastMath;
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 public class GillStateInterpolator 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 public 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, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
83 }
84
85
86 @Override
87 protected GillStateInterpolator create(final boolean newForward, final double[][] newYDotK,
88 final ODEStateAndDerivative newGlobalPreviousState,
89 final ODEStateAndDerivative newGlobalCurrentState,
90 final ODEStateAndDerivative newSoftPreviousState,
91 final ODEStateAndDerivative newSoftCurrentState,
92 final EquationsMapper newMapper) {
93 return new GillStateInterpolator(newForward, newYDotK,
94 newGlobalPreviousState, newGlobalCurrentState,
95 newSoftPreviousState, newSoftCurrentState,
96 newMapper);
97 }
98
99
100 @Override
101 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
102 final double time, final double theta,
103 final double thetaH, final double oneMinusThetaH) {
104
105 final double twoTheta = 2 * theta;
106 final double fourTheta2 = twoTheta * twoTheta;
107 final double coeffDot1 = theta * (twoTheta - 3) + 1;
108 final double cDot23 = twoTheta * (1 - theta);
109 final double coeffDot2 = cDot23 * ONE_MINUS_INV_SQRT_2;
110 final double coeffDot3 = cDot23 * ONE_PLUS_INV_SQRT_2;
111 final double coeffDot4 = theta * (twoTheta - 1);
112
113 final double[] interpolatedState;
114 final double[] interpolatedDerivatives;
115 if (getGlobalPreviousState() != null && theta <= 0.5) {
116 final double s = thetaH / 6.0;
117 final double c23 = s * (6 * theta - fourTheta2);
118 final double coeff1 = s * (6 - 9 * theta + fourTheta2);
119 final double coeff2 = c23 * ONE_MINUS_INV_SQRT_2;
120 final double coeff3 = c23 * ONE_PLUS_INV_SQRT_2;
121 final double coeff4 = s * (-3 * theta + fourTheta2);
122 interpolatedState = previousStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
123 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3 , coeffDot4);
124 } else {
125 final double s = oneMinusThetaH / -6.0;
126 final double c23 = s * (2 + twoTheta - fourTheta2);
127 final double coeff1 = s * (1 - 5 * theta + fourTheta2);
128 final double coeff2 = c23 * ONE_MINUS_INV_SQRT_2;
129 final double coeff3 = c23 * ONE_PLUS_INV_SQRT_2;
130 final double coeff4 = s * (1 + theta + fourTheta2);
131 interpolatedState = currentStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
132 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3 , coeffDot4);
133 }
134
135 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
136
137 }
138
139 }