HighamHall54Integrator.java

  1. /*
  2.  * Licensed to the Hipparchus project 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 Hipparchus project 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. package org.hipparchus.ode.nonstiff;

  18. import org.hipparchus.ode.EquationsMapper;
  19. import org.hipparchus.ode.ODEStateAndDerivative;
  20. import org.hipparchus.ode.nonstiff.interpolators.HighamHall54StateInterpolator;
  21. import org.hipparchus.util.FastMath;


  22. /**
  23.  * This class implements the 5(4) Higham and Hall integrator for
  24.  * Ordinary Differential Equations.
  25.  *
  26.  * <p>This integrator is an embedded Runge-Kutta integrator
  27.  * of order 5(4) used in local extrapolation mode (i.e. the solution
  28.  * is computed using the high order formula) with stepsize control
  29.  * (and automatic step initialization) and continuous output. This
  30.  * method uses 7 functions evaluations per step.</p>
  31.  *
  32.  */

  33. public class HighamHall54Integrator extends EmbeddedRungeKuttaIntegrator {

  34.     /** Name of integration scheme. */
  35.     public static final String METHOD_NAME = "Higham-Hall 5(4)";

  36.     /** Error weights Butcher array. */
  37.     static final double[] STATIC_E = {
  38.         -1.0/20.0, 0.0, 81.0/160.0, -6.0/5.0, 25.0/32.0, 1.0/16.0, -1.0/10.0
  39.     };

  40.     /** Simple constructor.
  41.      * Build a fifth order Higham and Hall integrator with the given step bounds
  42.      * @param minStep minimal step (sign is irrelevant, regardless of
  43.      * integration direction, forward or backward), the last step can
  44.      * be smaller than this
  45.      * @param maxStep maximal step (sign is irrelevant, regardless of
  46.      * integration direction, forward or backward), the last step can
  47.      * be smaller than this
  48.      * @param scalAbsoluteTolerance allowed absolute error
  49.      * @param scalRelativeTolerance allowed relative error
  50.      */
  51.     public HighamHall54Integrator(final double minStep, final double maxStep,
  52.                                   final double scalAbsoluteTolerance,
  53.                                   final double scalRelativeTolerance) {
  54.         super(METHOD_NAME, -1,
  55.               minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
  56.     }

  57.     /** Simple constructor.
  58.      * Build a fifth order Higham and Hall integrator with the given step bounds
  59.      * @param minStep minimal step (sign is irrelevant, regardless of
  60.      * integration direction, forward or backward), the last step can
  61.      * be smaller than this
  62.      * @param maxStep maximal step (sign is irrelevant, regardless of
  63.      * integration direction, forward or backward), the last step can
  64.      * be smaller than this
  65.      * @param vecAbsoluteTolerance allowed absolute error
  66.      * @param vecRelativeTolerance allowed relative error
  67.      */
  68.     public HighamHall54Integrator(final double minStep, final double maxStep,
  69.                                   final double[] vecAbsoluteTolerance,
  70.                                   final double[] vecRelativeTolerance) {
  71.         super(METHOD_NAME, -1,
  72.               minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public double[] getC() {
  77.         return new double[] {
  78.             2.0/9.0, 1.0/3.0, 1.0/2.0, 3.0/5.0, 1.0, 1.0
  79.         };
  80.     }

  81.     /** {@inheritDoc} */
  82.     @Override
  83.     public double[][] getA() {
  84.         return new double[][] {
  85.             {2.0/9.0},
  86.             {1.0/12.0, 1.0/4.0},
  87.             {1.0/8.0, 0.0, 3.0/8.0},
  88.             {91.0/500.0, -27.0/100.0, 78.0/125.0, 8.0/125.0},
  89.             {-11.0/20.0, 27.0/20.0, 12.0/5.0, -36.0/5.0, 5.0},
  90.             {1.0/12.0, 0.0, 27.0/32.0, -4.0/3.0, 125.0/96.0, 5.0/48.0}
  91.         };
  92.     }

  93.     /** {@inheritDoc} */
  94.     @Override
  95.     public double[] getB() {
  96.         return new double[] {
  97.             1.0/12.0, 0.0, 27.0/32.0, -4.0/3.0, 125.0/96.0, 5.0/48.0, 0.0
  98.         };
  99.     }

  100.     /** {@inheritDoc} */
  101.     @Override
  102.     protected HighamHall54StateInterpolator
  103.     createInterpolator(final boolean forward, double[][] yDotK,
  104.                        final ODEStateAndDerivative globalPreviousState,
  105.                        final ODEStateAndDerivative globalCurrentState,
  106.                        final EquationsMapper mapper) {
  107.         return new HighamHall54StateInterpolator(forward, yDotK,
  108.                                                 globalPreviousState, globalCurrentState,
  109.                                                 globalPreviousState, globalCurrentState,
  110.                                                 mapper);
  111.     }

  112.     /** {@inheritDoc} */
  113.     @Override
  114.     public int getOrder() {
  115.         return 5;
  116.     }

  117.     /** {@inheritDoc} */
  118.     @Override
  119.     protected double estimateError(final double[][] yDotK,
  120.                                    final double[] y0, final double[] y1,
  121.                                    final double h) {

  122.         final StepsizeHelper helper = getStepSizeHelper();
  123.         double error = 0;

  124.         for (int j = 0; j < helper.getMainSetDimension(); ++j) {
  125.             double errSum = STATIC_E[0] * yDotK[0][j];
  126.             for (int l = 1; l < STATIC_E.length; ++l) {
  127.                 errSum += STATIC_E[l] * yDotK[l][j];
  128.             }

  129.             final double tol = helper.getTolerance(j, FastMath.max(FastMath.abs(y0[j]), FastMath.abs(y1[j])));
  130.             final double ratio  = h * errSum / tol;
  131.             error += ratio * ratio;

  132.         }

  133.         return FastMath.sqrt(error / helper.getMainSetDimension());

  134.     }

  135. }