MidpointIntegrator.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.MidpointStateInterpolator;

  21. /**
  22.  * This class implements a second order Runge-Kutta integrator for
  23.  * Ordinary Differential Equations.
  24.  *
  25.  * <p>This method is an explicit Runge-Kutta method, its Butcher-array
  26.  * is the following one :</p>
  27.  * <pre>
  28.  *    0  |  0    0
  29.  *   1/2 | 1/2   0
  30.  *       |----------
  31.  *       |  0    1
  32.  * </pre>
  33.  *
  34.  * @see EulerIntegrator
  35.  * @see ClassicalRungeKuttaIntegrator
  36.  * @see GillIntegrator
  37.  * @see ThreeEighthesIntegrator
  38.  * @see LutherIntegrator
  39.  *
  40.  */

  41. public class MidpointIntegrator extends FixedStepRungeKuttaIntegrator {

  42.     /** Name of integration scheme. */
  43.     public static final String METHOD_NAME = "midpoint";

  44.     /** Simple constructor.
  45.      * Build a midpoint integrator with the given step.
  46.      * @param step integration step
  47.      */
  48.     public MidpointIntegrator(final double step) {
  49.         super(METHOD_NAME, step);
  50.     }

  51.     /** {@inheritDoc} */
  52.     @Override
  53.     public double[] getC() {
  54.         return new double[] {
  55.             1.0 / 2.0
  56.         };
  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public double[][] getA() {
  61.         return new double[][] {
  62.             { 1.0 / 2.0 }
  63.         };
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     public double[] getB() {
  68.         return new double[] {
  69.             0.0, 1.0
  70.         };
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     protected MidpointStateInterpolator createInterpolator(final boolean forward, final double[][] yDotK,
  75.                                                            final ODEStateAndDerivative globalPreviousState,
  76.                                                            final ODEStateAndDerivative globalCurrentState,
  77.                                                            final EquationsMapper mapper) {
  78.         return new MidpointStateInterpolator(forward, yDotK, globalPreviousState, globalCurrentState,
  79.                                             globalPreviousState, globalCurrentState, mapper);
  80.     }

  81. }