EulerStateInterpolator.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.EulerIntegrator;

  21. /**
  22.  * This class implements a linear interpolator for step.
  23.  *
  24.  * <p>This interpolator computes dense output inside the last
  25.  * step computed. The interpolation equation is consistent with the
  26.  * integration scheme :</p>
  27.  * <ul>
  28.  *   <li>Using reference point at step start:<br>
  29.  *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub>) + &theta; h y'
  30.  *   </li>
  31.  *   <li>Using reference point at step end:<br>
  32.  *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub> + h) - (1-&theta;) h y'
  33.  *   </li>
  34.  * </ul>
  35.  *
  36.  * <p>where &theta; belongs to [0 ; 1] and where y' is the evaluation of
  37.  * the derivatives already computed during the step.</p>
  38.  *
  39.  * @see EulerIntegrator
  40.  */

  41. public class EulerStateInterpolator extends RungeKuttaStateInterpolator {

  42.     /** Serializable version identifier. */
  43.     private static final long serialVersionUID = 20160328L;

  44.     /** Simple constructor.
  45.      * @param forward integration direction indicator
  46.      * @param yDotK slopes at the intermediate points
  47.      * @param globalPreviousState start of the global step
  48.      * @param globalCurrentState end of the global step
  49.      * @param softPreviousState start of the restricted step
  50.      * @param softCurrentState end of the restricted step
  51.      * @param mapper equations mapper for the all equations
  52.      */
  53.     public EulerStateInterpolator(final boolean forward,
  54.                                   final double[][] yDotK,
  55.                                   final ODEStateAndDerivative globalPreviousState,
  56.                                   final ODEStateAndDerivative globalCurrentState,
  57.                                   final ODEStateAndDerivative softPreviousState,
  58.                                   final ODEStateAndDerivative softCurrentState,
  59.                                   final EquationsMapper mapper) {
  60.         super(forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     protected EulerStateInterpolator create(final boolean newForward, final double[][] newYDotK,
  65.                                             final ODEStateAndDerivative newGlobalPreviousState,
  66.                                             final ODEStateAndDerivative newGlobalCurrentState,
  67.                                             final ODEStateAndDerivative newSoftPreviousState,
  68.                                             final ODEStateAndDerivative newSoftCurrentState,
  69.                                             final EquationsMapper newMapper) {
  70.         return new EulerStateInterpolator(newForward, newYDotK,
  71.                                           newGlobalPreviousState, newGlobalCurrentState,
  72.                                           newSoftPreviousState, newSoftCurrentState,
  73.                                           newMapper);
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
  78.                                                                            final double time, final double theta,
  79.                                                                            final double thetaH, final double oneMinusThetaH) {
  80.         final double[] interpolatedState;
  81.         if (getGlobalPreviousState() != null && theta <= 0.5) {
  82.             interpolatedState       = previousStateLinearCombination(thetaH);
  83.         } else {
  84.             interpolatedState       = currentStateLinearCombination(-oneMinusThetaH);
  85.         }
  86.         final double[] interpolatedDerivatives = derivativeLinearCombination(1.0);

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

  88.     }

  89. }