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


  28. /**
  29.  * This class implements the Luther sixth order Runge-Kutta
  30.  * integrator for Ordinary Differential Equations.

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

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

  58. public class LutherFieldIntegrator<T extends CalculusFieldElement<T>>
  59.     extends FixedStepRungeKuttaFieldIntegrator<T> {

  60.     /** Name of integration scheme. */
  61.     public static final String METHOD_NAME = LutherIntegrator.METHOD_NAME;

  62.     /** Simple constructor.
  63.      * Build a fourth-order Luther integrator with the given step.
  64.      * @param field field to which the time and state vector elements belong
  65.      * @param step integration step
  66.      */
  67.     public LutherFieldIntegrator(final Field<T> field, final T step) {
  68.         super(field, METHOD_NAME, step);
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public T[] getC() {
  73.         final T q = getField().getZero().add(21).sqrt();
  74.         final T[] c = MathArrays.buildArray(getField(), 6);
  75.         c[0] = getField().getOne();
  76.         c[1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
  77.         c[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 3);
  78.         c[3] = q.subtract(7).divide(-14);
  79.         c[4] = q.add(7).divide(14);
  80.         c[5] = getField().getOne();
  81.         return c;
  82.     }

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

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     public T[] getB() {

  117.         final T[] b = MathArrays.buildArray(getField(), 7);
  118.         b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(),  1,  20);
  119.         b[1] = getField().getZero();
  120.         b[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 16,  45);
  121.         b[3] = getField().getZero();
  122.         b[4] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 49, 180);
  123.         b[5] = b[4];
  124.         b[6] = b[0];

  125.         return b;

  126.     }

  127.     /** {@inheritDoc} */
  128.     @Override
  129.     protected LutherFieldStateInterpolator<T>
  130.         createInterpolator(final boolean forward, T[][] yDotK,
  131.                            final FieldODEStateAndDerivative<T> globalPreviousState,
  132.                            final FieldODEStateAndDerivative<T> globalCurrentState,
  133.                            final FieldEquationsMapper<T> mapper) {
  134.         return new LutherFieldStateInterpolator<>(getField(), forward, yDotK,
  135.                                                   globalPreviousState, globalCurrentState,
  136.                                                   globalPreviousState, globalCurrentState,
  137.                                                   mapper);
  138.     }

  139. }