1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math4.legacy.ode.nonstiff;
19
20 import org.apache.commons.math4.legacy.core.Field;
21 import org.apache.commons.math4.legacy.core.RealFieldElement;
22 import org.apache.commons.math4.legacy.ode.FieldEquationsMapper;
23 import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative;
24
25
26
27
28
29
30
31
32
33
34
35 class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
36 extends RungeKuttaFieldStepInterpolator<T> {
37
38
39
40
41
42
43
44
45
46
47
48 HighamHall54FieldStepInterpolator(final Field<T> field, final boolean forward,
49 final T[][] yDotK,
50 final FieldODEStateAndDerivative<T> globalPreviousState,
51 final FieldODEStateAndDerivative<T> globalCurrentState,
52 final FieldODEStateAndDerivative<T> softPreviousState,
53 final FieldODEStateAndDerivative<T> softCurrentState,
54 final FieldEquationsMapper<T> mapper) {
55 super(field, forward, yDotK,
56 globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
57 mapper);
58 }
59
60
61 @Override
62 protected HighamHall54FieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
63 final FieldODEStateAndDerivative<T> newGlobalPreviousState,
64 final FieldODEStateAndDerivative<T> newGlobalCurrentState,
65 final FieldODEStateAndDerivative<T> newSoftPreviousState,
66 final FieldODEStateAndDerivative<T> newSoftCurrentState,
67 final FieldEquationsMapper<T> newMapper) {
68 return new HighamHall54FieldStepInterpolator<>(newField, newForward, newYDotK,
69 newGlobalPreviousState, newGlobalCurrentState,
70 newSoftPreviousState, newSoftCurrentState,
71 newMapper);
72 }
73
74
75 @SuppressWarnings("unchecked")
76 @Override
77 protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
78 final T time, final T theta,
79 final T thetaH, final T oneMinusThetaH) {
80
81 final T bDot0 = theta.multiply(theta.multiply(theta.multiply( -10.0 ).add( 16.0 )).add(-15.0 / 2.0)).add(1);
82 final T bDot1 = time.getField().getZero();
83 final T bDot2 = theta.multiply(theta.multiply(theta.multiply( 135.0 / 2.0).add(-729.0 / 8.0)).add(459.0 / 16.0));
84 final T bDot3 = theta.multiply(theta.multiply(theta.multiply(-120.0 ).add( 152.0 )).add(-44.0 ));
85 final T bDot4 = theta.multiply(theta.multiply(theta.multiply( 125.0 / 2.0).add(-625.0 / 8.0)).add(375.0 / 16.0));
86 final T bDot5 = theta.multiply( 5.0 / 8.0).multiply(theta.multiply(2).subtract(1));
87 final T[] interpolatedState;
88 final T[] interpolatedDerivatives;
89
90 if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
91 final T b0 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply( -5.0 / 2.0).add( 16.0 / 3.0)).add(-15.0 / 4.0)).add(1));
92 final T b1 = time.getField().getZero();
93 final T b2 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(135.0 / 8.0).add(-243.0 / 8.0)).add(459.0 / 32.0)));
94 final T b3 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(-30.0 ).add( 152.0 / 3.0)).add(-22.0 )));
95 final T b4 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(125.0 / 8.0).add(-625.0 / 24.0)).add(375.0 / 32.0)));
96 final T b5 = thetaH.multiply(theta.multiply(theta.multiply( 5.0 / 12.0 ).add( -5.0 / 16.0)));
97 interpolatedState = previousStateLinearCombination(b0, b1, b2, b3, b4, b5);
98 interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
99 } else {
100 final T theta2 = theta.multiply(theta);
101 final T h = thetaH.divide(theta);
102 final T b0 = h.multiply( theta.multiply(theta.multiply(theta.multiply(theta.multiply(-5.0 / 2.0).add( 16.0 / 3.0)).add( -15.0 / 4.0)).add( 1.0 )).add( -1.0 / 12.0));
103 final T b1 = time.getField().getZero();
104 final T b2 = h.multiply(theta2.multiply(theta.multiply(theta.multiply( 135.0 / 8.0 ).add(-243.0 / 8.0)).add(459.0 / 32.0)).add( -27.0 / 32.0));
105 final T b3 = h.multiply(theta2.multiply(theta.multiply(theta.multiply( -30.0 ).add( 152.0 / 3.0)).add(-22.0 )).add( 4.0 / 3.0));
106 final T b4 = h.multiply(theta2.multiply(theta.multiply(theta.multiply( 125.0 / 8.0 ).add(-625.0 / 24.0)).add(375.0 / 32.0)).add(-125.0 / 96.0));
107 final T b5 = h.multiply(theta2.multiply(theta.multiply( 5.0 / 12.0 ).add(-5.0 / 16.0)).add( -5.0 / 48.0));
108 interpolatedState = currentStateLinearCombination(b0, b1, b2, b3, b4, b5);
109 interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
110 }
111
112 return new FieldODEStateAndDerivative<>(time, interpolatedState, interpolatedDerivatives);
113 }
114 }