EulerFieldStateInterpolator.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.EulerFieldIntegrator;

  27. /**
  28.  * This class implements a linear interpolator for step.
  29.  *
  30.  * <p>This interpolator computes dense output inside the last
  31.  * step computed. The interpolation equation is consistent with the
  32.  * integration scheme :</p>
  33.  * <ul>
  34.  *   <li>Using reference point at step start:<br>
  35.  *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub>) + &theta; h y'
  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) - (1-&theta;) h y'
  39.  *   </li>
  40.  * </ul>
  41.  *
  42.  * <p>where &theta; belongs to [0 ; 1] and where y' is the evaluation of
  43.  * the derivatives already computed during the step.</p>
  44.  *
  45.  * @see EulerFieldIntegrator
  46.  * @param <T> the type of the field elements
  47.  */

  48. public class EulerFieldStateInterpolator<T extends CalculusFieldElement<T>>
  49.     extends RungeKuttaFieldStateInterpolator<T> {

  50.     /** Simple constructor.
  51.      * @param field field to which the time and state vector elements belong
  52.      * @param forward integration direction indicator
  53.      * @param yDotK slopes at the intermediate points
  54.      * @param globalPreviousState start of the global step
  55.      * @param globalCurrentState end of the global step
  56.      * @param softPreviousState start of the restricted step
  57.      * @param softCurrentState end of the restricted step
  58.      * @param mapper equations mapper for the all equations
  59.      */
  60.     public EulerFieldStateInterpolator(final Field<T> field, final boolean forward,
  61.                                        final T[][] yDotK,
  62.                                        final FieldODEStateAndDerivative<T> globalPreviousState,
  63.                                        final FieldODEStateAndDerivative<T> globalCurrentState,
  64.                                        final FieldODEStateAndDerivative<T> softPreviousState,
  65.                                        final FieldODEStateAndDerivative<T> softCurrentState,
  66.                                        final FieldEquationsMapper<T> mapper) {
  67.         super(field, forward, yDotK, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
  68.               mapper);
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     protected EulerFieldStateInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
  73.                                                     final FieldODEStateAndDerivative<T> newGlobalPreviousState,
  74.                                                     final FieldODEStateAndDerivative<T> newGlobalCurrentState,
  75.                                                     final FieldODEStateAndDerivative<T> newSoftPreviousState,
  76.                                                     final FieldODEStateAndDerivative<T> newSoftCurrentState,
  77.                                                     final FieldEquationsMapper<T> newMapper) {
  78.         return new EulerFieldStateInterpolator<>(newField, newForward, newYDotK, newGlobalPreviousState,
  79.                 newGlobalCurrentState, newSoftPreviousState, newSoftCurrentState, newMapper);
  80.     }

  81.     /** {@inheritDoc} */
  82.     @SuppressWarnings("unchecked")
  83.     @Override
  84.     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
  85.                                                                                    final T time, final T theta,
  86.                                                                                    final T thetaH, final T oneMinusThetaH) {
  87.         final T[] interpolatedState;
  88.         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
  89.             interpolatedState       = previousStateLinearCombination(thetaH);
  90.         } else {
  91.             interpolatedState       = currentStateLinearCombination(oneMinusThetaH.negate());
  92.         }
  93.         final T[] interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());

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

  95.     }

  96. }