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.interpolators;
24
25 import org.hipparchus.CalculusFieldElement;
26 import org.hipparchus.Field;
27 import org.hipparchus.ode.FieldEquationsMapper;
28 import org.hipparchus.ode.FieldODEStateAndDerivative;
29 import org.hipparchus.ode.nonstiff.EulerFieldIntegrator;
30
31 /**
32 * This class implements a linear interpolator for step.
33 *
34 * <p>This interpolator computes dense output inside the last
35 * step computed. The interpolation equation is consistent with the
36 * integration scheme :</p>
37 * <ul>
38 * <li>Using reference point at step start:<br>
39 * y(t<sub>n</sub> + θ h) = y (t<sub>n</sub>) + θ h y'
40 * </li>
41 * <li>Using reference point at step end:<br>
42 * y(t<sub>n</sub> + θ h) = y (t<sub>n</sub> + h) - (1-θ) h y'
43 * </li>
44 * </ul>
45 *
46 * <p>where θ belongs to [0 ; 1] and where y' is the evaluation of
47 * the derivatives already computed during the step.</p>
48 *
49 * @see EulerFieldIntegrator
50 * @param <T> the type of the field elements
51 */
52
53 public class EulerFieldStateInterpolator<T extends CalculusFieldElement<T>>
54 extends RungeKuttaFieldStateInterpolator<T> {
55
56 /** Simple constructor.
57 * @param field field to which the time and state vector elements belong
58 * @param forward integration direction indicator
59 * @param yDotK slopes at the intermediate points
60 * @param globalPreviousState start of the global step
61 * @param globalCurrentState end of the global step
62 * @param softPreviousState start of the restricted step
63 * @param softCurrentState end of the restricted step
64 * @param mapper equations mapper for the all equations
65 */
66 public EulerFieldStateInterpolator(final Field<T> field, final boolean forward,
67 final T[][] yDotK,
68 final FieldODEStateAndDerivative<T> globalPreviousState,
69 final FieldODEStateAndDerivative<T> globalCurrentState,
70 final FieldODEStateAndDerivative<T> softPreviousState,
71 final FieldODEStateAndDerivative<T> softCurrentState,
72 final FieldEquationsMapper<T> mapper) {
73 super(field, forward, yDotK, 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<>(newField, newForward, newYDotK, newGlobalPreviousState,
86 newGlobalCurrentState, newSoftPreviousState, newSoftCurrentState, newMapper);
87 }
88
89 /** {@inheritDoc} */
90 @SuppressWarnings("unchecked")
91 @Override
92 protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
93 final T time, final T theta,
94 final T thetaH, final T oneMinusThetaH) {
95 final T[] interpolatedState;
96 if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
97 interpolatedState = previousStateLinearCombination(thetaH);
98 } else {
99 interpolatedState = currentStateLinearCombination(oneMinusThetaH.negate());
100 }
101 final T[] interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());
102
103 return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
104
105 }
106
107 }