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