ThreeEighthesStateInterpolator.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.ThreeEighthesIntegrator;

  21. /**
  22.  * This class implements a step interpolator for the 3/8 fourth
  23.  * order Runge-Kutta integrator.
  24.  *
  25.  * <p>This interpolator allows to compute dense output inside the last
  26.  * step computed. The interpolation equation is consistent with the
  27.  * integration scheme :</p>
  28.  * <ul>
  29.  *   <li>Using reference point at step start:<br>
  30.  *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub>)
  31.  *                      + &theta; (h/8) [ (8 - 15 &theta; +  8 &theta;<sup>2</sup>) y'<sub>1</sub>
  32.  *                                     +  3 * (15 &theta; - 12 &theta;<sup>2</sup>) y'<sub>2</sub>
  33.  *                                     +        3 &theta;                           y'<sub>3</sub>
  34.  *                                     +      (-3 &theta; +  4 &theta;<sup>2</sup>) y'<sub>4</sub>
  35.  *                                    ]
  36.  *   </li>
  37.  *   <li>Using reference point at step end:<br>
  38.  *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub> + h)
  39.  *                      - (1 - &theta;) (h/8) [(1 - 7 &theta; + 8 &theta;<sup>2</sup>) y'<sub>1</sub>
  40.  *                                         + 3 (1 +   &theta; - 4 &theta;<sup>2</sup>) y'<sub>2</sub>
  41.  *                                         + 3 (1 +   &theta;)                         y'<sub>3</sub>
  42.  *                                         +   (1 +   &theta; + 4 &theta;<sup>2</sup>) y'<sub>4</sub>
  43.  *                                          ]
  44.  *   </li>
  45.  * </ul>
  46.  *
  47.  * <p>where &theta; belongs to [0 ; 1] and where y'<sub>1</sub> to y'<sub>4</sub> are the four
  48.  * evaluations of the derivatives already computed during the
  49.  * step.</p>
  50.  *
  51.  * @see ThreeEighthesIntegrator
  52.  */

  53. public class ThreeEighthesStateInterpolator extends RungeKuttaStateInterpolator {

  54.     /** Serializable version identifier. */
  55.     private static final long serialVersionUID = 20160328L;

  56.     /** Simple constructor.
  57.      * @param forward integration direction indicator
  58.      * @param yDotK slopes at the intermediate points
  59.      * @param globalPreviousState start of the global step
  60.      * @param globalCurrentState end of the global step
  61.      * @param softPreviousState start of the restricted step
  62.      * @param softCurrentState end of the restricted step
  63.      * @param mapper equations mapper for the all equations
  64.      */
  65.     public ThreeEighthesStateInterpolator(final boolean forward,
  66.                                           final double[][] yDotK,
  67.                                           final ODEStateAndDerivative globalPreviousState,
  68.                                           final ODEStateAndDerivative globalCurrentState,
  69.                                           final ODEStateAndDerivative softPreviousState,
  70.                                           final ODEStateAndDerivative softCurrentState,
  71.                                           final EquationsMapper mapper) {
  72.         super(forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     protected ThreeEighthesStateInterpolator create(final boolean newForward, final double[][] newYDotK,
  77.                                                     final ODEStateAndDerivative newGlobalPreviousState,
  78.                                                     final ODEStateAndDerivative newGlobalCurrentState,
  79.                                                     final ODEStateAndDerivative newSoftPreviousState,
  80.                                                     final ODEStateAndDerivative newSoftCurrentState,
  81.                                                     final EquationsMapper newMapper) {
  82.         return new ThreeEighthesStateInterpolator(newForward, newYDotK,
  83.                 newGlobalPreviousState, newGlobalCurrentState,
  84.                 newSoftPreviousState, newSoftCurrentState,
  85.                 newMapper);
  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
  90.                                                                            final double time, final double theta,
  91.                                                                            final double thetaH, final double oneMinusThetaH) {

  92.         final double coeffDot3  = 0.75 * theta;
  93.         final double coeffDot1  = coeffDot3 * (4 * theta - 5) + 1;
  94.         final double coeffDot2  = coeffDot3 * (5 - 6 * theta);
  95.         final double coeffDot4  = coeffDot3 * (2 * theta - 1);
  96.         final double[] interpolatedState;
  97.         final double[] interpolatedDerivatives;

  98.         if (getGlobalPreviousState() != null && theta <= 0.5) {
  99.             final double s          = thetaH / 8.0;
  100.             final double fourTheta2 = 4 * theta * theta;
  101.             final double coeff1     = s * (8 - 15 * theta + 2 * fourTheta2);
  102.             final double coeff2     = 3 * s * (5 * theta - fourTheta2);
  103.             final double coeff3     = 3 * s * theta;
  104.             final double coeff4     = s * (-3 * theta + fourTheta2);
  105.             interpolatedState       = previousStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
  106.             interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4);
  107.         } else {
  108.             final double s          = oneMinusThetaH / -8.0;
  109.             final double fourTheta2 = 4 * theta * theta;
  110.             final double coeff1     = s * (1 - 7 * theta + 2 * fourTheta2);
  111.             final double coeff2     = 3 * s * (1 + theta - fourTheta2);
  112.             final double coeff3     = 3 * s * (1 + theta);
  113.             final double coeff4     = s * (1 + theta + fourTheta2);
  114.             interpolatedState       = currentStateLinearCombination(coeff1, coeff2, coeff3, coeff4);
  115.             interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4);
  116.         }

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

  118.     }

  119. }