View Javadoc
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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.ode.nonstiff;
24  
25  import org.hipparchus.CalculusFieldElement;
26  import org.hipparchus.Field;
27  import org.hipparchus.ode.FieldEquationsMapper;
28  import org.hipparchus.ode.FieldODEStateAndDerivative;
29  
30  /**
31   * This class implements a linear interpolator for step.
32   *
33   * <p>This interpolator computes dense output inside the last
34   * step computed. The interpolation equation is consistent with the
35   * integration scheme :</p>
36   * <ul>
37   *   <li>Using reference point at step start:<br>
38   *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub>) + &theta; h y'
39   *   </li>
40   *   <li>Using reference point at step end:<br>
41   *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub> + h) - (1-&theta;) h y'
42   *   </li>
43   * </ul>
44   *
45   * <p>where &theta; belongs to [0 ; 1] and where y' is the evaluation of
46   * the derivatives already computed during the step.</p>
47   *
48   * @see EulerFieldIntegrator
49   * @param <T> the type of the field elements
50   */
51  
52  class EulerFieldStateInterpolator<T extends CalculusFieldElement<T>>
53      extends RungeKuttaFieldStateInterpolator<T> {
54  
55      /** Simple constructor.
56       * @param field field to which the time and state vector elements belong
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      EulerFieldStateInterpolator(final Field<T> field, final boolean forward,
66                                  final T[][] yDotK,
67                                  final FieldODEStateAndDerivative<T> globalPreviousState,
68                                  final FieldODEStateAndDerivative<T> globalCurrentState,
69                                  final FieldODEStateAndDerivative<T> softPreviousState,
70                                  final FieldODEStateAndDerivative<T> softCurrentState,
71                                  final FieldEquationsMapper<T> mapper) {
72          super(field, forward, yDotK,
73                globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
74                mapper);
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      protected EulerFieldStateInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
80                                                      final FieldODEStateAndDerivative<T> newGlobalPreviousState,
81                                                      final FieldODEStateAndDerivative<T> newGlobalCurrentState,
82                                                      final FieldODEStateAndDerivative<T> newSoftPreviousState,
83                                                      final FieldODEStateAndDerivative<T> newSoftCurrentState,
84                                                      final FieldEquationsMapper<T> newMapper) {
85          return new EulerFieldStateInterpolator<T>(newField, newForward, newYDotK,
86                                                    newGlobalPreviousState, newGlobalCurrentState,
87                                                    newSoftPreviousState, newSoftCurrentState,
88                                                    newMapper);
89      }
90  
91      /** {@inheritDoc} */
92      @SuppressWarnings("unchecked")
93      @Override
94      protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
95                                                                                     final T time, final T theta,
96                                                                                     final T thetaH, final T oneMinusThetaH) {
97          final T[] interpolatedState;
98          final T[] interpolatedDerivatives;
99          if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
100             interpolatedState       = previousStateLinearCombination(thetaH);
101             interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());
102         } else {
103             interpolatedState       = currentStateLinearCombination(oneMinusThetaH.negate());
104             interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());
105         }
106 
107         return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
108 
109     }
110 
111 }