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