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 class MidpointStateInterpolator
47 extends RungeKuttaStateInterpolator {
48
49
50 private static final long serialVersionUID = 20160328L;
51
52
53
54
55
56
57
58
59
60
61 MidpointStateInterpolator(final boolean forward,
62 final double[][] yDotK,
63 final ODEStateAndDerivative globalPreviousState,
64 final ODEStateAndDerivative globalCurrentState,
65 final ODEStateAndDerivative softPreviousState,
66 final ODEStateAndDerivative softCurrentState,
67 final EquationsMapper mapper) {
68 super(forward, yDotK,
69 globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
70 mapper);
71 }
72
73
74 @Override
75 protected MidpointStateInterpolator create(final boolean newForward, final double[][] newYDotK,
76 final ODEStateAndDerivative newGlobalPreviousState,
77 final ODEStateAndDerivative newGlobalCurrentState,
78 final ODEStateAndDerivative newSoftPreviousState,
79 final ODEStateAndDerivative newSoftCurrentState,
80 final EquationsMapper newMapper) {
81 return new MidpointStateInterpolator(newForward, newYDotK,
82 newGlobalPreviousState, newGlobalCurrentState,
83 newSoftPreviousState, newSoftCurrentState,
84 newMapper);
85 }
86
87
88 @Override
89 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
90 final double time, final double theta,
91 final double thetaH, final double oneMinusThetaH) {
92 final double coeffDot2 = 2 * theta;
93 final double coeffDot1 = 1 - coeffDot2;
94
95 final double[] interpolatedState;
96 final double[] interpolatedDerivatives;
97 if (getGlobalPreviousState() != null && theta <= 0.5) {
98
99 final double coeff1 = theta * oneMinusThetaH;
100 final double coeff2 = theta * thetaH;
101 interpolatedState = previousStateLinearCombination(coeff1, coeff2);
102 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2);
103 } else {
104 final double coeff1 = oneMinusThetaH * theta;
105 final double coeff2 = -oneMinusThetaH * (1.0 + theta);
106 interpolatedState = currentStateLinearCombination(coeff1, coeff2);
107 interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2);
108 }
109
110 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
111
112 }
113
114 }