1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * This is not the original file distributed by the Apache Software Foundation
20 * It has been modified by the Hipparchus project
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.LutherFieldStateInterpolator;
30 import org.hipparchus.util.MathArrays;
31
32
33 /**
34 * This class implements the Luther sixth order Runge-Kutta
35 * integrator for Ordinary Differential Equations.
36
37 * <p>
38 * This method is described in H. A. Luther 1968 paper <a
39 * href="http://www.ams.org/journals/mcom/1968-22-102/S0025-5718-68-99876-1/S0025-5718-68-99876-1.pdf">
40 * An explicit Sixth-Order Runge-Kutta Formula</a>.
41 * </p>
42
43 * <p>This method is an explicit Runge-Kutta method, its Butcher-array
44 * is the following one :</p>
45 * <pre>
46 * 0 | 0 0 0 0 0 0
47 * 1 | 1 0 0 0 0 0
48 * 1/2 | 3/8 1/8 0 0 0 0
49 * 2/3 | 8/27 2/27 8/27 0 0 0
50 * (7-q)/14 | ( -21 + 9q)/392 ( -56 + 8q)/392 ( 336 - 48q)/392 ( -63 + 3q)/392 0 0
51 * (7+q)/14 | (-1155 - 255q)/1960 ( -280 - 40q)/1960 ( 0 - 320q)/1960 ( 63 + 363q)/1960 ( 2352 + 392q)/1960 0
52 * 1 | ( 330 + 105q)/180 ( 120 + 0q)/180 ( -200 + 280q)/180 ( 126 - 189q)/180 ( -686 - 126q)/180 ( 490 - 70q)/180
53 * |--------------------------------------------------------------------------------------------------------------------------------------------------
54 * | 1/20 0 16/45 0 49/180 49/180 1/20
55 * </pre>
56 * <p>where q = √21</p>
57 *
58 * @see EulerFieldIntegrator
59 * @see ClassicalRungeKuttaFieldIntegrator
60 * @see GillFieldIntegrator
61 * @see MidpointFieldIntegrator
62 * @see ThreeEighthesFieldIntegrator
63 * @param <T> the type of the field elements
64 */
65
66 public class LutherFieldIntegrator<T extends CalculusFieldElement<T>>
67 extends FixedStepRungeKuttaFieldIntegrator<T> {
68
69 /** Name of integration scheme. */
70 public static final String METHOD_NAME = LutherIntegrator.METHOD_NAME;
71
72 /** Simple constructor.
73 * Build a fourth-order Luther integrator with the given step.
74 * @param field field to which the time and state vector elements belong
75 * @param step integration step
76 */
77 public LutherFieldIntegrator(final Field<T> field, final T step) {
78 super(field, METHOD_NAME, step);
79 }
80
81 /** {@inheritDoc} */
82 @Override
83 public T[] getC() {
84 final T q = getField().getZero().add(21).sqrt();
85 final T[] c = MathArrays.buildArray(getField(), 6);
86 c[0] = getField().getOne();
87 c[1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
88 c[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 3);
89 c[3] = q.subtract(7).divide(-14);
90 c[4] = q.add(7).divide(14);
91 c[5] = getField().getOne();
92 return c;
93 }
94
95 /** {@inheritDoc} */
96 @Override
97 public T[][] getA() {
98 final T q = getField().getZero().add(21).sqrt();
99 final T[][] a = MathArrays.buildArray(getField(), 6, -1);
100 for (int i = 0; i < a.length; ++i) {
101 a[i] = MathArrays.buildArray(getField(), i + 1);
102 }
103 a[0][0] = getField().getOne();
104 a[1][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 3, 8);
105 a[1][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 8);
106 a[2][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 8, 27);
107 a[2][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 27);
108 a[2][2] = a[2][0];
109 a[3][0] = q.multiply( 9).add( -21).divide( 392);
110 a[3][1] = q.multiply( 8).add( -56).divide( 392);
111 a[3][2] = q.multiply( -48).add( 336).divide( 392);
112 a[3][3] = q.multiply( 3).add( -63).divide( 392);
113 a[4][0] = q.multiply(-255).add(-1155).divide(1960);
114 a[4][1] = q.multiply( -40).add( -280).divide(1960);
115 a[4][2] = q.multiply(-320) .divide(1960);
116 a[4][3] = q.multiply( 363).add( 63).divide(1960);
117 a[4][4] = q.multiply( 392).add( 2352).divide(1960);
118 a[5][0] = q.multiply( 105).add( 330).divide( 180);
119 a[5][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 3);
120 a[5][2] = q.multiply( 280).add( -200).divide( 180);
121 a[5][3] = q.multiply(-189).add( 126).divide( 180);
122 a[5][4] = q.multiply(-126).add( -686).divide( 180);
123 a[5][5] = q.multiply( -70).add( 490).divide( 180);
124 return a;
125 }
126
127 /** {@inheritDoc} */
128 @Override
129 public T[] getB() {
130
131 final T[] b = MathArrays.buildArray(getField(), 7);
132 b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 20);
133 b[1] = getField().getZero();
134 b[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 16, 45);
135 b[3] = getField().getZero();
136 b[4] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 49, 180);
137 b[5] = b[4];
138 b[6] = b[0];
139
140 return b;
141
142 }
143
144 /** {@inheritDoc} */
145 @Override
146 protected LutherFieldStateInterpolator<T>
147 createInterpolator(final boolean forward, T[][] yDotK,
148 final FieldODEStateAndDerivative<T> globalPreviousState,
149 final FieldODEStateAndDerivative<T> globalCurrentState,
150 final FieldEquationsMapper<T> mapper) {
151 return new LutherFieldStateInterpolator<>(getField(), forward, yDotK,
152 globalPreviousState, globalCurrentState,
153 globalPreviousState, globalCurrentState,
154 mapper);
155 }
156
157 }