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