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