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