HighamHall54StateInterpolator.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.HighamHall54Integrator;

  21. /**
  22.  * This class represents an interpolator over the last step during an
  23.  * ODE integration for the 5(4) Higham and Hall integrator.
  24.  *
  25.  * @see HighamHall54Integrator
  26.  *
  27.  */

  28. public class HighamHall54StateInterpolator extends RungeKuttaStateInterpolator {

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

  31.     /** Simple constructor.
  32.      * @param forward integration direction indicator
  33.      * @param yDotK slopes at the intermediate points
  34.      * @param globalPreviousState start of the global step
  35.      * @param globalCurrentState end of the global step
  36.      * @param softPreviousState start of the restricted step
  37.      * @param softCurrentState end of the restricted step
  38.      * @param mapper equations mapper for the all equations
  39.      */
  40.     public HighamHall54StateInterpolator(final boolean forward,
  41.                                          final double[][] yDotK,
  42.                                          final ODEStateAndDerivative globalPreviousState,
  43.                                          final ODEStateAndDerivative globalCurrentState,
  44.                                          final ODEStateAndDerivative softPreviousState,
  45.                                          final ODEStateAndDerivative softCurrentState,
  46.                                          final EquationsMapper mapper) {
  47.         super(forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
  48.     }

  49.     /** {@inheritDoc} */
  50.     @Override
  51.     protected HighamHall54StateInterpolator create(final boolean newForward, final double[][] newYDotK,
  52.                                                    final ODEStateAndDerivative newGlobalPreviousState,
  53.                                                    final ODEStateAndDerivative newGlobalCurrentState,
  54.                                                    final ODEStateAndDerivative newSoftPreviousState,
  55.                                                    final ODEStateAndDerivative newSoftCurrentState,
  56.                                                    final EquationsMapper newMapper) {
  57.         return new HighamHall54StateInterpolator(newForward, newYDotK,
  58.                                                 newGlobalPreviousState, newGlobalCurrentState,
  59.                                                 newSoftPreviousState, newSoftCurrentState,
  60.                                                 newMapper);
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
  65.                                                                            final double time, final double theta,
  66.                                                                            final double thetaH, final double oneMinusThetaH) {

  67.         final double bDot0 = 1 + theta * (-15.0/2.0 + theta * (16.0 - 10.0 * theta));
  68.         final double bDot1 = 0;
  69.         final double bDot2 = theta * (459.0/16.0 + theta * (-729.0/8.0 + 135.0/2.0 * theta));
  70.         final double bDot3 = theta * (-44.0 + theta * (152.0 - 120.0 * theta));
  71.         final double bDot4 = theta * (375.0/16.0 + theta * (-625.0/8.0 + 125.0/2.0 * theta));
  72.         final double bDot5 = theta * 5.0/8.0 * (2 * theta - 1);

  73.         final double[] interpolatedState;
  74.         final double[] interpolatedDerivatives;
  75.         if (getGlobalPreviousState() != null && theta <= 0.5) {
  76.             final double b0 = thetaH * (1.0 + theta * (-15.0/4.0  + theta * (16.0/3.0 - 5.0/2.0 * theta)));
  77.             final double b1 = 0;
  78.             final double b2 = thetaH * (      theta * (459.0/32.0 + theta * (-243.0/8.0 + theta * 135.0/8.0)));
  79.             final double b3 = thetaH * (      theta * (-22.0      + theta * (152.0/3.0  + theta * -30.0)));
  80.             final double b4 = thetaH * (      theta * (375.0/32.0 + theta * (-625.0/24.0 + theta * 125.0/8.0)));
  81.             final double b5 = thetaH * (      theta * (-5.0/16.0  + theta *  5.0/12.0));
  82.             interpolatedState       = previousStateLinearCombination(b0 , b1, b2, b3, b4, b5);
  83.             interpolatedDerivatives = derivativeLinearCombination(bDot0 , bDot1, bDot2, bDot3, bDot4, bDot5);
  84.         } else {
  85.             final double theta2 = theta * theta;
  86.             final double h      = thetaH / theta;
  87.             final double b0 = h * (-1.0/12.0 + theta * (1.0 + theta * (-15.0/4.0 + theta * (16.0/3.0 + theta * -5.0/2.0))));
  88.             final double b1 = 0;
  89.             final double b2 = h * (-27.0/32.0 + theta2 * (459.0/32.0 + theta * (-243.0/8.0 + theta * 135.0/8.0)));
  90.             final double b3 = h * (4.0/3.0 + theta2 * (-22.0 + theta * (152.0/3.0  + theta * -30.0)));
  91.             final double b4 = h * (-125.0/96.0 + theta2 * (375.0/32.0 + theta * (-625.0/24.0 + theta * 125.0/8.0)));
  92.             final double b5 = h * (-5.0/48.0 + theta2 * (-5.0/16.0 + theta * 5.0/12.0));
  93.             interpolatedState       = currentStateLinearCombination(b0 , b1, b2, b3, b4, b5);
  94.             interpolatedDerivatives = derivativeLinearCombination(bDot0 , bDot1, bDot2, bDot3, bDot4, bDot5);
  95.         }

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

  97.     }

  98. }