ClassicalRungeKuttaIntegrator.java

  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. package org.hipparchus.ode.nonstiff;

  18. import org.hipparchus.ode.EquationsMapper;
  19. import org.hipparchus.ode.ODEStateAndDerivative;
  20. import org.hipparchus.ode.nonstiff.interpolators.ClassicalRungeKuttaStateInterpolator;

  21. /**
  22.  * This class implements the classical fourth order Runge-Kutta
  23.  * integrator for Ordinary Differential Equations (it is the most
  24.  * often used Runge-Kutta method).
  25.  *
  26.  * <p>This method is an explicit Runge-Kutta method, its Butcher-array
  27.  * is the following one :</p>
  28.  * <pre>
  29.  *    0  |  0    0    0    0
  30.  *   1/2 | 1/2   0    0    0
  31.  *   1/2 |  0   1/2   0    0
  32.  *    1  |  0    0    1    0
  33.  *       |--------------------
  34.  *       | 1/6  1/3  1/3  1/6
  35.  * </pre>
  36.  *
  37.  * @see EulerIntegrator
  38.  * @see GillIntegrator
  39.  * @see MidpointIntegrator
  40.  * @see ThreeEighthesIntegrator
  41.  * @see LutherIntegrator
  42.  */

  43. public class ClassicalRungeKuttaIntegrator extends FixedStepRungeKuttaIntegrator {

  44.     /** Name of integration scheme. */
  45.     public static final String METHOD_NAME = "classical Runge-Kutta";

  46.     /** Simple constructor.
  47.      * Build a fourth-order Runge-Kutta integrator with the given
  48.      * step.
  49.      * @param step integration step
  50.      */
  51.     public ClassicalRungeKuttaIntegrator(final double step) {
  52.         super(METHOD_NAME, step);
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public double[] getC() {
  57.         return new double[] {
  58.             1.0 / 2.0, 1.0 / 2.0, 1.0
  59.         };
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public double[][] getA() {
  64.         return new double[][] {
  65.             { 1.0 / 2.0 },
  66.             { 0.0, 1.0 / 2.0 },
  67.             { 0.0, 0.0, 1.0 }
  68.         };
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public double[] getB() {
  73.         return new double[] {
  74.             1.0 / 6.0, 1.0 / 3.0, 1.0 / 3.0, 1.0 / 6.0
  75.         };
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     protected ClassicalRungeKuttaStateInterpolator createInterpolator(final boolean forward, final double[][] yDotK,
  80.                                                                       final ODEStateAndDerivative globalPreviousState,
  81.                                                                       final ODEStateAndDerivative globalCurrentState,
  82.                                                                       final EquationsMapper mapper) {
  83.         return new ClassicalRungeKuttaStateInterpolator(forward, yDotK, globalPreviousState, globalCurrentState,
  84.                                                        globalPreviousState, globalCurrentState, mapper);
  85.     }

  86. }