LutherFieldIntegrator.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 Luther sixth order Runge-Kutta
  25.  * integrator for Ordinary Differential Equations.

  26.  * <p>
  27.  * This method is described in H. A. Luther 1968 paper <a
  28.  * href="http://www.ams.org/journals/mcom/1968-22-102/S0025-5718-68-99876-1/S0025-5718-68-99876-1.pdf">
  29.  * An explicit Sixth-Order Runge-Kutta Formula</a>.
  30.  * </p>

  31.  * <p>This method is an explicit Runge-Kutta method, its Butcher-array
  32.  * is the following one :
  33.  * <pre>
  34.  *        0   |               0                     0                     0                     0                     0                     0
  35.  *        1   |               1                     0                     0                     0                     0                     0
  36.  *       1/2  |              3/8                   1/8                    0                     0                     0                     0
  37.  *       2/3  |              8/27                  2/27                  8/27                   0                     0                     0
  38.  *   (7-q)/14 | (  -21 +   9q)/392    (  -56 +   8q)/392    (  336 -  48q)/392    (  -63 +   3q)/392                  0                     0
  39.  *   (7+q)/14 | (-1155 - 255q)/1960   ( -280 -  40q)/1960   (    0 - 320q)/1960   (   63 + 363q)/1960   ( 2352 + 392q)/1960                 0
  40.  *        1   | (  330 + 105q)/180    (  120 +   0q)/180    ( -200 + 280q)/180    (  126 - 189q)/180    ( -686 - 126q)/180     ( 490 -  70q)/180
  41.  *            |--------------------------------------------------------------------------------------------------------------------------------------------------
  42.  *            |              1/20                   0                   16/45                  0                   49/180                 49/180         1/20
  43.  * </pre>
  44.  * where q = &radic;21
  45.  *
  46.  * @see EulerFieldIntegrator
  47.  * @see ClassicalRungeKuttaFieldIntegrator
  48.  * @see GillFieldIntegrator
  49.  * @see MidpointFieldIntegrator
  50.  * @see ThreeEighthesFieldIntegrator
  51.  * @param <T> the type of the field elements
  52.  * @since 3.6
  53.  */

  54. public class LutherFieldIntegrator<T extends RealFieldElement<T>>
  55.     extends RungeKuttaFieldIntegrator<T> {

  56.     /** Simple constructor.
  57.      * Build a fourth-order Luther integrator with the given step.
  58.      * @param field field to which the time and state vector elements belong
  59.      * @param step integration step
  60.      */
  61.     public LutherFieldIntegrator(final Field<T> field, final T step) {
  62.         super(field, "Luther", step);
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public T[] getC() {
  67.         final T q = getField().getZero().add(21).sqrt();
  68.         final T[] c = MathArrays.buildArray(getField(), 6);
  69.         c[0] = getField().getOne();
  70.         c[1] = fraction(1, 2);
  71.         c[2] = fraction(2, 3);
  72.         c[3] = q.subtract(7).divide(-14);
  73.         c[4] = q.add(7).divide(14);
  74.         c[5] = getField().getOne();
  75.         return c;
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     public T[][] getA() {
  80.         final T q = getField().getZero().add(21).sqrt();
  81.         final T[][] a = MathArrays.buildArray(getField(), 6, -1);
  82.         for (int i = 0; i < a.length; ++i) {
  83.             a[i] = MathArrays.buildArray(getField(), i + 1);
  84.         }
  85.         a[0][0] = getField().getOne();
  86.         a[1][0] = fraction(3,  8);
  87.         a[1][1] = fraction(1,  8);
  88.         a[2][0] = fraction(8, 27);
  89.         a[2][1] = fraction(2, 27);
  90.         a[2][2] = a[2][0];
  91.         a[3][0] = q.multiply(   9).add(  -21).divide( 392);
  92.         a[3][1] = q.multiply(   8).add(  -56).divide( 392);
  93.         a[3][2] = q.multiply( -48).add(  336).divide( 392);
  94.         a[3][3] = q.multiply(   3).add(  -63).divide( 392);
  95.         a[4][0] = q.multiply(-255).add(-1155).divide(1960);
  96.         a[4][1] = q.multiply( -40).add( -280).divide(1960);
  97.         a[4][2] = q.multiply(-320)           .divide(1960);
  98.         a[4][3] = q.multiply( 363).add(   63).divide(1960);
  99.         a[4][4] = q.multiply( 392).add( 2352).divide(1960);
  100.         a[5][0] = q.multiply( 105).add(  330).divide( 180);
  101.         a[5][1] = fraction(2, 3);
  102.         a[5][2] = q.multiply( 280).add( -200).divide( 180);
  103.         a[5][3] = q.multiply(-189).add(  126).divide( 180);
  104.         a[5][4] = q.multiply(-126).add( -686).divide( 180);
  105.         a[5][5] = q.multiply( -70).add(  490).divide( 180);
  106.         return a;
  107.     }

  108.     /** {@inheritDoc} */
  109.     @Override
  110.     public T[] getB() {

  111.         final T[] b = MathArrays.buildArray(getField(), 7);
  112.         b[0] = fraction( 1,  20);
  113.         b[1] = getField().getZero();
  114.         b[2] = fraction(16,  45);
  115.         b[3] = getField().getZero();
  116.         b[4] = fraction(49, 180);
  117.         b[5] = b[4];
  118.         b[6] = b[0];

  119.         return b;
  120.     }

  121.     /** {@inheritDoc} */
  122.     @Override
  123.     protected LutherFieldStepInterpolator<T>
  124.         createInterpolator(final boolean forward, T[][] yDotK,
  125.                            final FieldODEStateAndDerivative<T> globalPreviousState,
  126.                            final FieldODEStateAndDerivative<T> globalCurrentState,
  127.                            final FieldEquationsMapper<T> mapper) {
  128.         return new LutherFieldStepInterpolator<>(getField(), forward, yDotK,
  129.                                                   globalPreviousState, globalCurrentState,
  130.                                                   globalPreviousState, globalCurrentState,
  131.                                                   mapper);
  132.     }
  133. }