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.interpolators;
19
20 import org.hipparchus.ode.EquationsMapper;
21 import org.hipparchus.ode.ODEStateAndDerivative;
22 import org.hipparchus.ode.nonstiff.EulerIntegrator;
23
24 /**
25 * This class implements a linear interpolator for step.
26 *
27 * <p>This interpolator computes dense output inside the last
28 * step computed. The interpolation equation is consistent with the
29 * integration scheme :</p>
30 * <ul>
31 * <li>Using reference point at step start:<br>
32 * y(t<sub>n</sub> + θ h) = y (t<sub>n</sub>) + θ h y'
33 * </li>
34 * <li>Using reference point at step end:<br>
35 * y(t<sub>n</sub> + θ h) = y (t<sub>n</sub> + h) - (1-θ) h y'
36 * </li>
37 * </ul>
38 *
39 * <p>where θ belongs to [0 ; 1] and where y' is the evaluation of
40 * the derivatives already computed during the step.</p>
41 *
42 * @see EulerIntegrator
43 */
44
45 public class EulerStateInterpolator 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 public 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, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 protected EulerStateInterpolator create(final boolean newForward, final double[][] newYDotK,
72 final ODEStateAndDerivative newGlobalPreviousState,
73 final ODEStateAndDerivative newGlobalCurrentState,
74 final ODEStateAndDerivative newSoftPreviousState,
75 final ODEStateAndDerivative newSoftCurrentState,
76 final EquationsMapper newMapper) {
77 return new EulerStateInterpolator(newForward, newYDotK,
78 newGlobalPreviousState, newGlobalCurrentState,
79 newSoftPreviousState, newSoftCurrentState,
80 newMapper);
81 }
82
83 /** {@inheritDoc} */
84 @Override
85 protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
86 final double time, final double theta,
87 final double thetaH, final double oneMinusThetaH) {
88 final double[] interpolatedState;
89 if (getGlobalPreviousState() != null && theta <= 0.5) {
90 interpolatedState = previousStateLinearCombination(thetaH);
91 } else {
92 interpolatedState = currentStateLinearCombination(-oneMinusThetaH);
93 }
94 final double[] interpolatedDerivatives = derivativeLinearCombination(1.0);
95
96 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
97
98 }
99
100 }