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