MidpointFieldIntegrator.java

  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.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */

  21. package org.hipparchus.ode.nonstiff;

  22. import org.hipparchus.CalculusFieldElement;
  23. import org.hipparchus.Field;
  24. import org.hipparchus.ode.FieldEquationsMapper;
  25. import org.hipparchus.ode.FieldODEStateAndDerivative;
  26. import org.hipparchus.ode.nonstiff.interpolators.MidpointFieldStateInterpolator;
  27. import org.hipparchus.util.MathArrays;

  28. /**
  29.  * This class implements a second order Runge-Kutta integrator for
  30.  * Ordinary Differential Equations.
  31.  *
  32.  * <p>This method is an explicit Runge-Kutta method, its Butcher-array
  33.  * is the following one :</p>
  34.  * <pre>
  35.  *    0  |  0    0
  36.  *   1/2 | 1/2   0
  37.  *       |----------
  38.  *       |  0    1
  39.  * </pre>
  40.  *
  41.  * @see EulerFieldIntegrator
  42.  * @see ClassicalRungeKuttaFieldIntegrator
  43.  * @see GillFieldIntegrator
  44.  * @see ThreeEighthesFieldIntegrator
  45.  * @see LutherFieldIntegrator
  46.  *
  47.  * @param <T> the type of the field elements
  48.  */

  49. public class MidpointFieldIntegrator<T extends CalculusFieldElement<T>> extends FixedStepRungeKuttaFieldIntegrator<T> {

  50.     /** Name of integration scheme. */
  51.     public static final String METHOD_NAME = MidpointIntegrator.METHOD_NAME;

  52.     /** Simple constructor.
  53.      * Build a midpoint integrator with the given step.
  54.      * @param field field to which the time and state vector elements belong
  55.      * @param step integration step
  56.      */
  57.     public MidpointFieldIntegrator(final Field<T> field, final T step) {
  58.         super(field, METHOD_NAME, step);
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public T[] getC() {
  63.         final T[] c = MathArrays.buildArray(getField(), 1);
  64.         c[0] = getField().getOne().newInstance(0.5);
  65.         return c;
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     public T[][] getA() {
  70.         final T[][] a = MathArrays.buildArray(getField(), 1, 1);
  71.         a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
  72.         return a;
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public T[] getB() {
  77.         final T[] b = MathArrays.buildArray(getField(), 2);
  78.         b[0] = getField().getZero();
  79.         b[1] = getField().getOne();
  80.         return b;
  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     protected MidpointFieldStateInterpolator<T>
  85.         createInterpolator(final boolean forward, T[][] yDotK,
  86.                            final FieldODEStateAndDerivative<T> globalPreviousState,
  87.                            final FieldODEStateAndDerivative<T> globalCurrentState,
  88.                            final FieldEquationsMapper<T> mapper) {
  89.         return new MidpointFieldStateInterpolator<>(getField(), forward, yDotK, globalPreviousState, globalCurrentState,
  90.                                                     globalPreviousState, globalCurrentState, mapper);
  91.     }

  92. }