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.  *      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.ThreeEighthesFieldStateInterpolator;
  27. import org.hipparchus.util.MathArrays;

  28. /**
  29.  * This class implements the 3/8 fourth order Runge-Kutta
  30.  * integrator for 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    0    0
  36.  *   1/3 | 1/3   0    0    0
  37.  *   2/3 |-1/3   1    0    0
  38.  *    1  |  1   -1    1    0
  39.  *       |--------------------
  40.  *       | 1/8  3/8  3/8  1/8
  41.  * </pre>
  42.  *
  43.  * @see EulerFieldIntegrator
  44.  * @see ClassicalRungeKuttaFieldIntegrator
  45.  * @see GillFieldIntegrator
  46.  * @see MidpointFieldIntegrator
  47.  * @see LutherFieldIntegrator
  48.  * @param <T> the type of the field elements
  49.  */

  50. public class ThreeEighthesFieldIntegrator<T extends CalculusFieldElement<T>>
  51.     extends FixedStepRungeKuttaFieldIntegrator<T> {

  52.     /** Name of integration scheme. */
  53.     public static final String METHOD_NAME = ThreeEighthesIntegrator.METHOD_NAME;

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

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public T[] getC() {
  65.         final T[] c = MathArrays.buildArray(getField(), 3);
  66.         c[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 3);
  67.         c[1] = c[0].add(c[0]);
  68.         c[2] = getField().getOne();
  69.         return c;
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public T[][] getA() {
  74.         final T[][] a = MathArrays.buildArray(getField(), 3, -1);
  75.         for (int i = 0; i < a.length; ++i) {
  76.             a[i] = MathArrays.buildArray(getField(), i + 1);
  77.         }
  78.         a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 3);
  79.         a[1][0] = a[0][0].negate();
  80.         a[1][1] = getField().getOne();
  81.         a[2][0] = getField().getOne();
  82.         a[2][1] = getField().getOne().negate();
  83.         a[2][2] = getField().getOne();
  84.         return a;
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public T[] getB() {
  89.         final T[] b = MathArrays.buildArray(getField(), 4);
  90.         b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 8);
  91.         b[1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 3, 8);
  92.         b[2] = b[1];
  93.         b[3] = b[0];
  94.         return b;
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     protected ThreeEighthesFieldStateInterpolator<T>
  99.         createInterpolator(final boolean forward, T[][] yDotK,
  100.                            final FieldODEStateAndDerivative<T> globalPreviousState,
  101.                            final FieldODEStateAndDerivative<T> globalCurrentState,
  102.                            final FieldEquationsMapper<T> mapper) {
  103.         return new ThreeEighthesFieldStateInterpolator<>(getField(), forward, yDotK, globalPreviousState, globalCurrentState,
  104.                                                          globalPreviousState, globalCurrentState, mapper);
  105.     }

  106. }