View Javadoc
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  
18  package org.hipparchus.ode.nonstiff;
19  
20  import org.hipparchus.ode.EquationsMapper;
21  import org.hipparchus.ode.ODEStateAndDerivative;
22  
23  /**
24   * This class implements a linear interpolator for step.
25   *
26   * <p>This interpolator computes dense output inside the last
27   * step computed. The interpolation equation is consistent with the
28   * integration scheme :</p>
29   * <ul>
30   *   <li>Using reference point at step start:<br>
31   *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub>) + &theta; h y'
32   *   </li>
33   *   <li>Using reference point at step end:<br>
34   *     y(t<sub>n</sub> + &theta; h) = y (t<sub>n</sub> + h) - (1-&theta;) h y'
35   *   </li>
36   * </ul>
37   *
38   * <p>where &theta; belongs to [0 ; 1] and where y' is the evaluation of
39   * the derivatives already computed during the step.</p>
40   *
41   * @see EulerIntegrator
42   */
43  
44  class EulerStateInterpolator
45      extends RungeKuttaStateInterpolator {
46  
47      /** Serializable version identifier. */
48      private static final long serialVersionUID = 20160328L;
49  
50      /** Simple constructor.
51       * @param forward integration direction indicator
52       * @param yDotK slopes at the intermediate points
53       * @param globalPreviousState start of the global step
54       * @param globalCurrentState end of the global step
55       * @param softPreviousState start of the restricted step
56       * @param softCurrentState end of the restricted step
57       * @param mapper equations mapper for the all equations
58       */
59      EulerStateInterpolator(final boolean forward,
60                             final double[][] yDotK,
61                             final ODEStateAndDerivative globalPreviousState,
62                             final ODEStateAndDerivative globalCurrentState,
63                             final ODEStateAndDerivative softPreviousState,
64                             final ODEStateAndDerivative softCurrentState,
65                             final EquationsMapper mapper) {
66          super(forward, yDotK,
67                globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
68                mapper);
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      protected EulerStateInterpolator create(final boolean newForward, final double[][] newYDotK,
74                                              final ODEStateAndDerivative newGlobalPreviousState,
75                                              final ODEStateAndDerivative newGlobalCurrentState,
76                                              final ODEStateAndDerivative newSoftPreviousState,
77                                              final ODEStateAndDerivative newSoftCurrentState,
78                                              final EquationsMapper newMapper) {
79          return new EulerStateInterpolator(newForward, newYDotK,
80                                            newGlobalPreviousState, newGlobalCurrentState,
81                                            newSoftPreviousState, newSoftCurrentState,
82                                            newMapper);
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
88                                                                             final double time, final double theta,
89                                                                             final double thetaH, final double oneMinusThetaH) {
90          final double[] interpolatedState;
91          final double[] interpolatedDerivatives;
92          if (getGlobalPreviousState() != null && theta <= 0.5) {
93              interpolatedState       = previousStateLinearCombination(thetaH);
94              interpolatedDerivatives = derivativeLinearCombination(1.0);
95          } else {
96              interpolatedState       = currentStateLinearCombination(-oneMinusThetaH);
97              interpolatedDerivatives = derivativeLinearCombination(1.0);
98          }
99  
100         return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
101 
102     }
103 
104 }