View Javadoc
1   /*
2    * Licensed to the Hipparchus project 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 Hipparchus project 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  package org.hipparchus.ode.nonstiff;
19  
20  import org.hipparchus.ode.EquationsMapper;
21  import org.hipparchus.ode.ODEStateAndDerivative;
22  import org.hipparchus.ode.nonstiff.interpolators.GillStateInterpolator;
23  import org.hipparchus.util.FastMath;
24  
25  
26  /**
27   * This class implements the Gill fourth order Runge-Kutta
28   * integrator for Ordinary Differential Equations .
29  
30   * <p>This method is an explicit Runge-Kutta method, its Butcher-array
31   * is the following one :</p>
32   * <pre>
33   *    0  |    0        0       0      0
34   *   1/2 |   1/2       0       0      0
35   *   1/2 | (q-1)/2  (2-q)/2    0      0
36   *    1  |    0       -q/2  (2+q)/2   0
37   *       |-------------------------------
38   *       |   1/6    (2-q)/6 (2+q)/6  1/6
39   * </pre>
40   * <p>where q = sqrt(2)</p>
41   *
42   * @see EulerIntegrator
43   * @see ClassicalRungeKuttaIntegrator
44   * @see MidpointIntegrator
45   * @see ThreeEighthesIntegrator
46   * @see LutherIntegrator
47   */
48  
49  public class GillIntegrator extends FixedStepRungeKuttaIntegrator {
50  
51      /** Name of integration scheme. */
52      public static final String METHOD_NAME = "Gill";
53  
54      /** Simple constructor.
55       * Build a fourth-order Gill integrator with the given step.
56       * @param step integration step
57       */
58      public GillIntegrator(final double step) {
59          super(METHOD_NAME, step);
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      public double[] getC() {
65          return new double[] {
66              1.0 / 2.0, 1.0 / 2.0, 1.0
67          };
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public double[][] getA() {
73          return new double[][] {
74              { 1.0 / 2.0 },
75              { (FastMath.sqrt(2.0) - 1.0) / 2.0, (2.0 - FastMath.sqrt(2.0)) / 2.0 },
76              { 0.0, -FastMath.sqrt(2.0) / 2.0, (2.0 + FastMath.sqrt(2.0)) / 2.0 }
77          };
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public double[] getB() {
83          return new double[] {
84              1.0 / 6.0, (2.0 - FastMath.sqrt(2.0)) / 6.0, (2.0 + FastMath.sqrt(2.0)) / 6.0, 1.0 / 6.0
85          };
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      protected GillStateInterpolator createInterpolator(final boolean forward, final double[][] yDotK,
91                                                         final ODEStateAndDerivative globalPreviousState,
92                                                         final ODEStateAndDerivative globalCurrentState,
93                                                         final EquationsMapper mapper) {
94          return new GillStateInterpolator(forward, yDotK, globalPreviousState, globalCurrentState,
95                                          globalPreviousState, globalCurrentState, mapper);
96      }
97  
98  }