DormandPrince853StateInterpolator.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.interpolators;

  18. import org.hipparchus.ode.EquationsMapper;
  19. import org.hipparchus.ode.ODEStateAndDerivative;
  20. import org.hipparchus.ode.nonstiff.DormandPrince853Integrator;

  21. /**
  22.  * This class represents an interpolator over the last step during an
  23.  * ODE integration for the 8(5,3) Dormand-Prince integrator.
  24.  *
  25.  * @see DormandPrince853Integrator
  26.  *
  27.  */

  28. public class DormandPrince853StateInterpolator extends RungeKuttaStateInterpolator {

  29.     /** Serializable version identifier. */
  30.     private static final long serialVersionUID = 20160328L;

  31.     /** Interpolation weights. */
  32.     private static final double[][] D = {
  33.         {
  34.             // this row is the same as the b array
  35.                     104257.0 / 1920240.0,
  36.                          0.0,
  37.                          0.0,
  38.                          0.0,
  39.                          0.0,
  40.                    3399327.0 / 763840.0,
  41.                   66578432.0 / 35198415.0,
  42.                -1674902723.0 / 288716400.0,
  43.             54980371265625.0 / 176692375811392.0,
  44.                    -734375.0 / 4826304.0,
  45.                  171414593.0 / 851261400.0,
  46.                     137909.0 / 3084480.0,
  47.                          0.0,
  48.                          0.0,
  49.                          0.0,
  50.                          0.0,
  51.         }, {
  52.                     1815983.0 / 1920240.0,
  53.                           0.0,
  54.                           0.0,
  55.                           0.0,
  56.                           0.0,
  57.                    -3399327.0 / 763840.0,
  58.                   -66578432.0 / 35198415.0,
  59.                  1674902723.0 / 288716400.0,
  60.             -54980371265625.0 / 176692375811392.0,
  61.                      734375.0 / 4826304.0,
  62.                  -171414593.0 / 851261400.0,
  63.                     -137909.0 / 3084480.0,
  64.                           0.0,
  65.                           0.0,
  66.                           0.0,
  67.                           0.0,
  68.         }, {
  69.                     -855863.0 / 960120.0,
  70.                           0.0,
  71.                           0.0,
  72.                           0.0,
  73.                           0.0,
  74.                     3399327.0 / 381920.0,
  75.                   133156864.0 / 35198415.0,
  76.                 -1674902723.0 / 144358200.0,
  77.              54980371265625.0 / 88346187905696.0,
  78.                     -734375.0 / 2413152.0,
  79.                   171414593.0 / 425630700.0,
  80.                      137909.0 / 1542240.0,
  81.                          -1.0,
  82.                           0.0,
  83.                           0.0,
  84.                           0.0
  85.         }, {
  86.                -17751989329.0 / 2106076560.0,
  87.                           0.0,
  88.                           0.0,
  89.                           0.0,
  90.                           0.0,
  91.                  4272954039.0 / 7539864640.0,
  92.               -118476319744.0 / 38604839385.0,
  93.                755123450731.0 / 316657731600.0,
  94.         3692384461234828125.0 / 1744130441634250432.0,
  95.                 -4612609375.0 / 5293382976.0,
  96.               2091772278379.0 / 933644586600.0,
  97.                  2136624137.0 / 3382989120.0,
  98.                     -126493.0 / 1421424.0,
  99.                    98350000.0 / 5419179.0,
  100.                   -18878125.0 / 2053168.0,
  101.                 -1944542619.0 / 438351368.0
  102.         }, {
  103.                 32941697297.0 / 3159114840.0,
  104.                           0.0,
  105.                           0.0,
  106.                           0.0,
  107.                           0.0,
  108.                456696183123.0 / 1884966160.0,
  109.              19132610714624.0 / 115814518155.0,
  110.            -177904688592943.0 / 474986597400.0,
  111.        -4821139941836765625.0 / 218016305204281304.0,
  112.                 30702015625.0 / 3970037232.0,
  113.             -85916079474274.0 / 2800933759800.0,
  114.                 -5919468007.0 / 634310460.0,
  115.                     2479159.0 / 157936.0,
  116.                   -18750000.0 / 602131.0,
  117.                   -19203125.0 / 2053168.0,
  118.                 15700361463.0 / 438351368.0
  119.         }, {
  120.                 12627015655.0 / 631822968.0,
  121.                           0.0,
  122.                           0.0,
  123.                           0.0,
  124.                           0.0,
  125.                -72955222965.0 / 188496616.0,
  126.             -13145744952320.0 / 69488710893.0,
  127.              30084216194513.0 / 56998391688.0,
  128.         -296858761006640625.0 / 25648977082856624.0,
  129.                   569140625.0 / 82709109.0,
  130.                -18684190637.0 / 18672891732.0,
  131.                    69644045.0 / 89549712.0,
  132.                   -11847025.0 / 4264272.0,
  133.                  -978650000.0 / 16257537.0,
  134.                   519371875.0 / 6159504.0,
  135.                  5256837225.0 / 438351368.0
  136.         }, {
  137.                  -450944925.0 / 17550638.0,
  138.                           0.0,
  139.                           0.0,
  140.                           0.0,
  141.                           0.0,
  142.                -14532122925.0 / 94248308.0,
  143.               -595876966400.0 / 2573655959.0,
  144.                188748653015.0 / 527762886.0,
  145.         2545485458115234375.0 / 27252038150535163.0,
  146.                 -1376953125.0 / 36759604.0,
  147.                 53995596795.0 / 518691437.0,
  148.                   210311225.0 / 7047894.0,
  149.                    -1718875.0 / 39484.0,
  150.                    58000000.0 / 602131.0,
  151.                    -1546875.0 / 39484.0,
  152.                 -1262172375.0 / 8429834.0
  153.         }
  154.     };

  155.     /** Simple constructor.
  156.      * @param forward integration direction indicator
  157.      * @param yDotK slopes at the intermediate points
  158.      * @param globalPreviousState start of the global step
  159.      * @param globalCurrentState end of the global step
  160.      * @param softPreviousState start of the restricted step
  161.      * @param softCurrentState end of the restricted step
  162.      * @param mapper equations mapper for the all equations
  163.      */
  164.     public DormandPrince853StateInterpolator(final boolean forward,
  165.                                              final double[][] yDotK,
  166.                                              final ODEStateAndDerivative globalPreviousState,
  167.                                              final ODEStateAndDerivative globalCurrentState,
  168.                                              final ODEStateAndDerivative softPreviousState,
  169.                                              final ODEStateAndDerivative softCurrentState,
  170.                                              final EquationsMapper mapper) {
  171.         super(forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
  172.     }

  173.     /** {@inheritDoc} */
  174.     @Override
  175.     protected DormandPrince853StateInterpolator create(final boolean newForward, final double[][] newYDotK,
  176.                                                        final ODEStateAndDerivative newGlobalPreviousState,
  177.                                                        final ODEStateAndDerivative newGlobalCurrentState,
  178.                                                        final ODEStateAndDerivative newSoftPreviousState,
  179.                                                        final ODEStateAndDerivative newSoftCurrentState,
  180.                                                        final EquationsMapper newMapper) {
  181.         return new DormandPrince853StateInterpolator(newForward, newYDotK,
  182.                                                      newGlobalPreviousState, newGlobalCurrentState,
  183.                                                      newSoftPreviousState, newSoftCurrentState,
  184.                                                      newMapper);
  185.     }

  186.     /** {@inheritDoc} */
  187.     @Override
  188.     protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
  189.                                                                            final double time, final double theta,
  190.                                                                            final double thetaH, final double oneMinusThetaH) {

  191.         final double eta      = 1.0 - theta;
  192.         final double twoTheta = 2 * theta;
  193.         final double theta2   = theta * theta;
  194.         final double dot1     = 1.0 - twoTheta;
  195.         final double dot2     = theta * (2 - 3 * theta);
  196.         final double dot3     = twoTheta * (theta * (twoTheta - 3) + 1);
  197.         final double dot4     = theta2   * (theta * (5 * theta - 8) + 3);
  198.         final double dot5     = theta2   * (theta * (theta * (15 - 6 * theta) - 12) + 3);
  199.         final double dot6     = theta2   * (theta * (theta * (theta * (18 - 7 * theta) - 15) + 4));
  200.         final double[] interpolatedState;
  201.         final double[] interpolatedDerivatives;


  202.         if (getGlobalPreviousState() != null && theta <= 0.5) {
  203.             final double f0 = thetaH;
  204.             final double f1 = f0 * eta;
  205.             final double f2 = f1 * theta;
  206.             final double f3 = f2 * eta;
  207.             final double f4 = f3 * theta;
  208.             final double f5 = f4 * eta;
  209.             final double f6 = f5 * theta;
  210.             final double[] p = new double[16];
  211.             final double[] q = new double[16];
  212.             for (int i = 0; i < p.length; ++i) {
  213.                 p[i] = f0 * D[0][i] +   f1 * D[1][i] +   f2 * D[2][i] +   f3 * D[3][i] +
  214.                        f4 * D[4][i] +   f5 * D[5][i] +   f6 * D[6][i];
  215.                 q[i] = D[0][i] + dot1 * D[1][i] + dot2 * D[2][i] + dot3 * D[3][i] +
  216.                                  dot4 * D[4][i] + dot5 * D[5][i] + dot6 * D[6][i];
  217.             }
  218.             interpolatedState       = previousStateLinearCombination(p[0], p[1], p[ 2], p[ 3], p[ 4], p[ 5], p[ 6], p[ 7],
  219.                                                                      p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
  220.             interpolatedDerivatives = derivativeLinearCombination(q[0], q[1], q[ 2], q[ 3], q[ 4], q[ 5], q[ 6], q[ 7],
  221.                                                                   q[8], q[9], q[10], q[11], q[12], q[13], q[14], q[15]);
  222.         } else {
  223.             final double f0 = -oneMinusThetaH;
  224.             final double f1 = -f0 * theta;
  225.             final double f2 =  f1 * theta;
  226.             final double f3 =  f2 * eta;
  227.             final double f4 =  f3 * theta;
  228.             final double f5 =  f4 * eta;
  229.             final double f6 =  f5 * theta;
  230.             final double[] p = new double[16];
  231.             final double[] q = new double[16];
  232.             for (int i = 0; i < p.length; ++i) {
  233.                 p[i] = f0 * D[0][i] +   f1 * D[1][i] +   f2 * D[2][i] +   f3 * D[3][i] +
  234.                        f4 * D[4][i] +   f5 * D[5][i] +   f6 * D[6][i];
  235.                 q[i] = D[0][i] + dot1 * D[1][i] + dot2 * D[2][i] + dot3 * D[3][i] +
  236.                                  dot4 * D[4][i] + dot5 * D[5][i] + dot6 * D[6][i];
  237.             }
  238.             interpolatedState       = currentStateLinearCombination(p[0], p[1], p[ 2], p[ 3], p[ 4], p[ 5], p[ 6], p[ 7],
  239.                                                                     p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
  240.             interpolatedDerivatives = derivativeLinearCombination(q[0], q[1], q[ 2], q[ 3], q[ 4], q[ 5], q[ 6], q[ 7],
  241.                                                                   q[8], q[9], q[10], q[11], q[12], q[13], q[14], q[15]);
  242.         }

  243.         return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);

  244.     }

  245. }