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