ThreeEighthesFieldIntegrator.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.  *      http://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.apache.commons.math4.legacy.ode.nonstiff;

  18. import org.apache.commons.math4.legacy.core.Field;
  19. import org.apache.commons.math4.legacy.core.RealFieldElement;
  20. import org.apache.commons.math4.legacy.ode.FieldEquationsMapper;
  21. import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative;
  22. import org.apache.commons.math4.legacy.core.MathArrays;

  23. /**
  24.  * This class implements the 3/8 fourth order Runge-Kutta
  25.  * integrator for Ordinary Differential Equations.
  26.  *
  27.  * <p>This method is an explicit Runge-Kutta method, its Butcher-array
  28.  * is the following one :
  29.  * <pre>
  30.  *    0  |  0    0    0    0
  31.  *   1/3 | 1/3   0    0    0
  32.  *   2/3 |-1/3   1    0    0
  33.  *    1  |  1   -1    1    0
  34.  *       |--------------------
  35.  *       | 1/8  3/8  3/8  1/8
  36.  * </pre>
  37.  *
  38.  * @see EulerFieldIntegrator
  39.  * @see ClassicalRungeKuttaFieldIntegrator
  40.  * @see GillFieldIntegrator
  41.  * @see MidpointFieldIntegrator
  42.  * @see LutherFieldIntegrator
  43.  * @param <T> the type of the field elements
  44.  * @since 3.6
  45.  */

  46. public class ThreeEighthesFieldIntegrator<T extends RealFieldElement<T>>
  47.     extends RungeKuttaFieldIntegrator<T> {

  48.     /** Simple constructor.
  49.      * Build a 3/8 integrator with the given step.
  50.      * @param field field to which the time and state vector elements belong
  51.      * @param step integration step
  52.      */
  53.     public ThreeEighthesFieldIntegrator(final Field<T> field, final T step) {
  54.         super(field, "3/8", step);
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public T[] getC() {
  59.         final T[] c = MathArrays.buildArray(getField(), 3);
  60.         c[0] = fraction(1, 3);
  61.         c[1] = c[0].add(c[0]);
  62.         c[2] = getField().getOne();
  63.         return c;
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     public T[][] getA() {
  68.         final T[][] a = MathArrays.buildArray(getField(), 3, -1);
  69.         for (int i = 0; i < a.length; ++i) {
  70.             a[i] = MathArrays.buildArray(getField(), i + 1);
  71.         }
  72.         a[0][0] = fraction(1, 3);
  73.         a[1][0] = a[0][0].negate();
  74.         a[1][1] = getField().getOne();
  75.         a[2][0] = getField().getOne();
  76.         a[2][1] = getField().getOne().negate();
  77.         a[2][2] = getField().getOne();
  78.         return a;
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public T[] getB() {
  83.         final T[] b = MathArrays.buildArray(getField(), 4);
  84.         b[0] = fraction(1, 8);
  85.         b[1] = fraction(3, 8);
  86.         b[2] = b[1];
  87.         b[3] = b[0];
  88.         return b;
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     protected ThreeEighthesFieldStepInterpolator<T>
  93.         createInterpolator(final boolean forward, T[][] yDotK,
  94.                            final FieldODEStateAndDerivative<T> globalPreviousState,
  95.                            final FieldODEStateAndDerivative<T> globalCurrentState,
  96.                            final FieldEquationsMapper<T> mapper) {
  97.         return new ThreeEighthesFieldStepInterpolator<>(getField(), forward, yDotK,
  98.                                                          globalPreviousState, globalCurrentState,
  99.                                                          globalPreviousState, globalCurrentState,
  100.                                                          mapper);
  101.     }
  102. }