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.ThreeEighthesFieldStateInterpolator;
30 import org.hipparchus.util.MathArrays;
31
32 /**
33 * This class implements the 3/8 fourth order Runge-Kutta
34 * integrator for Ordinary Differential Equations.
35 *
36 * <p>This method is an explicit Runge-Kutta method, its Butcher-array
37 * is the following one :</p>
38 * <pre>
39 * 0 | 0 0 0 0
40 * 1/3 | 1/3 0 0 0
41 * 2/3 |-1/3 1 0 0
42 * 1 | 1 -1 1 0
43 * |--------------------
44 * | 1/8 3/8 3/8 1/8
45 * </pre>
46 *
47 * @see EulerFieldIntegrator
48 * @see ClassicalRungeKuttaFieldIntegrator
49 * @see GillFieldIntegrator
50 * @see MidpointFieldIntegrator
51 * @see LutherFieldIntegrator
52 * @param <T> the type of the field elements
53 */
54
55 public class ThreeEighthesFieldIntegrator<T extends CalculusFieldElement<T>>
56 extends FixedStepRungeKuttaFieldIntegrator<T> {
57
58 /** Name of integration scheme. */
59 public static final String METHOD_NAME = ThreeEighthesIntegrator.METHOD_NAME;
60
61 /** Simple constructor.
62 * Build a 3/8 integrator with the given step.
63 * @param field field to which the time and state vector elements belong
64 * @param step integration step
65 */
66 public ThreeEighthesFieldIntegrator(final Field<T> field, final T step) {
67 super(field, METHOD_NAME, step);
68 }
69
70 /** {@inheritDoc} */
71 @Override
72 public T[] getC() {
73 final T[] c = MathArrays.buildArray(getField(), 3);
74 c[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 3);
75 c[1] = c[0].add(c[0]);
76 c[2] = getField().getOne();
77 return c;
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public T[][] getA() {
83 final T[][] a = MathArrays.buildArray(getField(), 3, -1);
84 for (int i = 0; i < a.length; ++i) {
85 a[i] = MathArrays.buildArray(getField(), i + 1);
86 }
87 a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 3);
88 a[1][0] = a[0][0].negate();
89 a[1][1] = getField().getOne();
90 a[2][0] = getField().getOne();
91 a[2][1] = getField().getOne().negate();
92 a[2][2] = getField().getOne();
93 return a;
94 }
95
96 /** {@inheritDoc} */
97 @Override
98 public T[] getB() {
99 final T[] b = MathArrays.buildArray(getField(), 4);
100 b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 8);
101 b[1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 3, 8);
102 b[2] = b[1];
103 b[3] = b[0];
104 return b;
105 }
106
107 /** {@inheritDoc} */
108 @Override
109 protected ThreeEighthesFieldStateInterpolator<T>
110 createInterpolator(final boolean forward, T[][] yDotK,
111 final FieldODEStateAndDerivative<T> globalPreviousState,
112 final FieldODEStateAndDerivative<T> globalCurrentState,
113 final FieldEquationsMapper<T> mapper) {
114 return new ThreeEighthesFieldStateInterpolator<>(getField(), forward, yDotK, globalPreviousState, globalCurrentState,
115 globalPreviousState, globalCurrentState, mapper);
116 }
117
118 }