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


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

  31.  * <p>This method is an explicit Runge-Kutta method, its Butcher-array
  32.  * is the following one :</p>
  33.  * <pre>
  34.  *    0  |    0        0       0      0
  35.  *   1/2 |   1/2       0       0      0
  36.  *   1/2 | (q-1)/2  (2-q)/2    0      0
  37.  *    1  |    0       -q/2  (2+q)/2   0
  38.  *       |-------------------------------
  39.  *       |   1/6    (2-q)/6 (2+q)/6  1/6
  40.  * </pre>
  41.  * <p>where q = sqrt(2)</p>
  42.  *
  43.  * @see EulerFieldIntegrator
  44.  * @see ClassicalRungeKuttaFieldIntegrator
  45.  * @see MidpointFieldIntegrator
  46.  * @see ThreeEighthesFieldIntegrator
  47.  * @see LutherFieldIntegrator
  48.  * @param <T> the type of the field elements
  49.  */

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

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

  54.     /** Simple constructor.
  55.      * Build a fourth-order Gill 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 GillFieldIntegrator(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, 2);
  67.         c[1] = c[0];
  68.         c[2] = getField().getOne();
  69.         return c;
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public T[][] getA() {

  74.         final T two     = getField().getZero().add(2);
  75.         final T sqrtTwo = two.sqrt();

  76.         final T[][] a = MathArrays.buildArray(getField(), 3, -1);
  77.         for (int i = 0; i < a.length; ++i) {
  78.             a[i] = MathArrays.buildArray(getField(), i + 1);
  79.         }
  80.         a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
  81.         a[1][0] = sqrtTwo.subtract(1).multiply(0.5);
  82.         a[1][1] = sqrtTwo.subtract(2).multiply(-0.5);
  83.         a[2][0] = getField().getZero();
  84.         a[2][1] = sqrtTwo.multiply(-0.5);
  85.         a[2][2] = sqrtTwo.add(2).multiply(0.5);
  86.         return a;
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public T[] getB() {

  91.         final T two     = getField().getZero().add(2);
  92.         final T sqrtTwo = two.sqrt();

  93.         final T[] b = MathArrays.buildArray(getField(), 4);
  94.         b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 6);
  95.         b[1] = sqrtTwo.subtract(2).divide(-6);
  96.         b[2] = sqrtTwo.add(2).divide(6);
  97.         b[3] = b[0];

  98.         return b;

  99.     }

  100.     /** {@inheritDoc} */
  101.     @Override
  102.     protected GillFieldStateInterpolator<T>
  103.         createInterpolator(final boolean forward, T[][] yDotK,
  104.                            final FieldODEStateAndDerivative<T> globalPreviousState,
  105.                            final FieldODEStateAndDerivative<T> globalCurrentState,
  106.                            final FieldEquationsMapper<T> mapper) {
  107.         return new GillFieldStateInterpolator<>(getField(), forward, yDotK, globalPreviousState, globalCurrentState,
  108.                                                 globalPreviousState, globalCurrentState, mapper);
  109.     }

  110. }