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

  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.HighamHall54FieldIntegrator;

  27. /**
  28.  * This class represents an interpolator over the last step during an
  29.  * ODE integration for the 5(4) Higham and Hall integrator.
  30.  *
  31.  * @see HighamHall54FieldIntegrator
  32.  *
  33.  * @param <T> the type of the field elements
  34.  */

  35. public class HighamHall54FieldStateInterpolator<T extends CalculusFieldElement<T>>
  36.     extends RungeKuttaFieldStateInterpolator<T> {

  37.     /** Simple constructor.
  38.      * @param field field to which the time and state vector elements belong
  39.      * @param forward integration direction indicator
  40.      * @param yDotK slopes at the intermediate points
  41.      * @param globalPreviousState start of the global step
  42.      * @param globalCurrentState end of the global step
  43.      * @param softPreviousState start of the restricted step
  44.      * @param softCurrentState end of the restricted step
  45.      * @param mapper equations mapper for the all equations
  46.      */
  47.     public HighamHall54FieldStateInterpolator(final Field<T> field, final boolean forward,
  48.                                               final T[][] yDotK,
  49.                                               final FieldODEStateAndDerivative<T> globalPreviousState,
  50.                                               final FieldODEStateAndDerivative<T> globalCurrentState,
  51.                                               final FieldODEStateAndDerivative<T> softPreviousState,
  52.                                               final FieldODEStateAndDerivative<T> softCurrentState,
  53.                                               final FieldEquationsMapper<T> mapper) {
  54.         super(field, forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
  55.                 mapper);
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     protected HighamHall54FieldStateInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
  60.                                                            final FieldODEStateAndDerivative<T> newGlobalPreviousState,
  61.                                                            final FieldODEStateAndDerivative<T> newGlobalCurrentState,
  62.                                                            final FieldODEStateAndDerivative<T> newSoftPreviousState,
  63.                                                            final FieldODEStateAndDerivative<T> newSoftCurrentState,
  64.                                                            final FieldEquationsMapper<T> newMapper) {
  65.         return new HighamHall54FieldStateInterpolator<>(newField, newForward, newYDotK,
  66.                                                          newGlobalPreviousState, newGlobalCurrentState,
  67.                                                          newSoftPreviousState, newSoftCurrentState,
  68.                                                          newMapper);
  69.     }

  70.     /** {@inheritDoc} */
  71.     @SuppressWarnings("unchecked")
  72.     @Override
  73.     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
  74.                                                                                    final T time, final T theta,
  75.                                                                                    final T thetaH, final T oneMinusThetaH) {

  76.         final T bDot0 = theta.multiply(theta.multiply(theta.multiply( -10.0      ).add( 16.0       )).add(-15.0 /  2.0)).add(1);
  77.         final T bDot1 = time.getField().getZero();
  78.         final T bDot2 = theta.multiply(theta.multiply(theta.multiply( 135.0 / 2.0).add(-729.0 / 8.0)).add(459.0 / 16.0));
  79.         final T bDot3 = theta.multiply(theta.multiply(theta.multiply(-120.0      ).add( 152.0      )).add(-44.0       ));
  80.         final T bDot4 = theta.multiply(theta.multiply(theta.multiply( 125.0 / 2.0).add(-625.0 / 8.0)).add(375.0 / 16.0));
  81.         final T bDot5 = theta.multiply(  5.0 /  8.0).multiply(theta.multiply(2).subtract(1));
  82.         final T[] interpolatedState;
  83.         final T[] interpolatedDerivatives;

  84.         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
  85.             final T b0 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply( -5.0 / 2.0).add(  16.0 /  3.0)).add(-15.0 /  4.0)).add(1));
  86.             final T b1 = time.getField().getZero();
  87.             final T b2 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(135.0 / 8.0).add(-243.0 /  8.0)).add(459.0 / 32.0)));
  88.             final T b3 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(-30.0      ).add( 152.0 /  3.0)).add(-22.0       )));
  89.             final T b4 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(125.0 / 8.0).add(-625.0 / 24.0)).add(375.0 / 32.0)));
  90.             final T b5 = thetaH.multiply(theta.multiply(theta.multiply(                                   5.0 / 12.0 ).add( -5.0 / 16.0)));
  91.             interpolatedState       = previousStateLinearCombination(b0, b1, b2, b3, b4, b5);
  92.             interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
  93.         } else {
  94.             final T theta2 = theta.multiply(theta);
  95.             final T h      = thetaH.divide(theta);
  96.             final T b0 = h.multiply( theta.multiply(theta.multiply(theta.multiply(theta.multiply(-5.0 / 2.0).add( 16.0 / 3.0)).add( -15.0 /  4.0)).add(  1.0       )).add(  -1.0 / 12.0));
  97.             final T b1 = time.getField().getZero();
  98.             final T b2 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               135.0 / 8.0 ).add(-243.0 /  8.0)).add(459.0 / 32.0)).add( -27.0 / 32.0));
  99.             final T b3 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               -30.0       ).add( 152.0 /  3.0)).add(-22.0       )).add(  4.0  /  3.0));
  100.             final T b4 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               125.0 / 8.0 ).add(-625.0 / 24.0)).add(375.0 / 32.0)).add(-125.0 / 96.0));
  101.             final T b5 = h.multiply(theta2.multiply(theta.multiply(                                                                   5.0 / 12.0 ).add(-5.0  / 16.0)).add(  -5.0 / 48.0));
  102.             interpolatedState       = currentStateLinearCombination(b0, b1, b2, b3, b4, b5);
  103.             interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
  104.         }

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

  106.     }

  107. }