1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.hipparchus.ode.nonstiff;
24
25 import org.hipparchus.CalculusFieldElement;
26 import org.hipparchus.Field;
27 import org.hipparchus.ode.FieldEquationsMapper;
28 import org.hipparchus.ode.FieldODEStateAndDerivative;
29 import org.hipparchus.ode.nonstiff.interpolators.HighamHall54FieldStateInterpolator;
30 import org.hipparchus.util.FastMath;
31 import org.hipparchus.util.MathArrays;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class HighamHall54FieldIntegrator<T extends CalculusFieldElement<T>>
48 extends EmbeddedRungeKuttaFieldIntegrator<T> {
49
50
51 public static final String METHOD_NAME = HighamHall54Integrator.METHOD_NAME;
52
53
54
55
56
57
58
59
60
61
62
63
64
65 public HighamHall54FieldIntegrator(final Field<T> field,
66 final double minStep, final double maxStep,
67 final double scalAbsoluteTolerance,
68 final double scalRelativeTolerance) {
69 super(field, METHOD_NAME, -1,
70 minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public HighamHall54FieldIntegrator(final Field<T> field,
86 final double minStep, final double maxStep,
87 final double[] vecAbsoluteTolerance,
88 final double[] vecRelativeTolerance) {
89 super(field, HighamHall54Integrator.METHOD_NAME, -1,
90 minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
91 }
92
93
94 @Override
95 public T[] getC() {
96 final T[] c = MathArrays.buildArray(getField(), 6);
97 c[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 9);
98 c[1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 3);
99 c[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
100 c[3] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 3, 5);
101 c[4] = getField().getOne();
102 c[5] = getField().getOne();
103 return c;
104 }
105
106
107 @Override
108 public T[][] getA() {
109 final T[][] a = MathArrays.buildArray(getField(), 6, -1);
110 for (int i = 0; i < a.length; ++i) {
111 a[i] = MathArrays.buildArray(getField(), i + 1);
112 }
113 a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 9);
114 a[1][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 12);
115 a[1][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 4);
116 a[2][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 8);
117 a[2][1] = getField().getZero();
118 a[2][2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 3, 8);
119 a[3][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 91, 500);
120 a[3][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), -27, 100);
121 a[3][2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 78, 125);
122 a[3][3] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 8, 125);
123 a[4][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), -11, 20);
124 a[4][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 27, 20);
125 a[4][2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 12, 5);
126 a[4][3] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), -36, 5);
127 a[4][4] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 5, 1);
128 a[5][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 12);
129 a[5][1] = getField().getZero();
130 a[5][2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 27, 32);
131 a[5][3] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), -4, 3);
132 a[5][4] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 125, 96);
133 a[5][5] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 5, 48);
134 return a;
135 }
136
137
138 @Override
139 public T[] getB() {
140 final T[] b = MathArrays.buildArray(getField(), 7);
141 b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 12);
142 b[1] = getField().getZero();
143 b[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 27, 32);
144 b[3] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), -4, 3);
145 b[4] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 125, 96);
146 b[5] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 5, 48);
147 b[6] = getField().getZero();
148 return b;
149 }
150
151
152 @Override
153 protected HighamHall54FieldStateInterpolator<T>
154 createInterpolator(final boolean forward, T[][] yDotK,
155 final FieldODEStateAndDerivative<T> globalPreviousState,
156 final FieldODEStateAndDerivative<T> globalCurrentState, final FieldEquationsMapper<T> mapper) {
157 return new HighamHall54FieldStateInterpolator<>(getField(), forward, yDotK,
158 globalPreviousState, globalCurrentState,
159 globalPreviousState, globalCurrentState,
160 mapper);
161 }
162
163
164 @Override
165 public int getOrder() {
166 return 5;
167 }
168
169
170 @Override
171 protected double estimateError(final T[][] yDotK, final T[] y0, final T[] y1, final T h) {
172
173 final StepsizeHelper helper = getStepSizeHelper();
174 double error = 0;
175
176 for (int j = 0; j < helper.getMainSetDimension(); ++j) {
177 double errSum = HighamHall54Integrator.STATIC_E[0] * yDotK[0][j].getReal();
178 for (int l = 1; l < HighamHall54Integrator.STATIC_E.length; ++l) {
179 errSum += HighamHall54Integrator.STATIC_E[l] * yDotK[l][j].getReal();
180 }
181 final double tol = helper.getTolerance(j, FastMath.max(FastMath.abs(y0[j].getReal()), FastMath.abs(y1[j].getReal())));
182 final double ratio = h.getReal() * errSum / tol;
183 error += ratio * ratio;
184
185 }
186
187 return FastMath.sqrt(error / helper.getMainSetDimension());
188
189 }
190
191 }