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 represents an interpolator over the last step during an
32   * ODE integration for the 5(4) Higham and Hall integrator.
33   *
34   * @see HighamHall54FieldIntegrator
35   *
36   * @param <T> the type of the field elements
37   */
38  
39  class HighamHall54FieldStateInterpolator<T extends CalculusFieldElement<T>>
40      extends RungeKuttaFieldStateInterpolator<T> {
41  
42      /** Simple constructor.
43       * @param field field to which the time and state vector elements belong
44       * @param forward integration direction indicator
45       * @param yDotK slopes at the intermediate points
46       * @param globalPreviousState start of the global step
47       * @param globalCurrentState end of the global step
48       * @param softPreviousState start of the restricted step
49       * @param softCurrentState end of the restricted step
50       * @param mapper equations mapper for the all equations
51       */
52      HighamHall54FieldStateInterpolator(final Field<T> field, final boolean forward,
53                                         final T[][] yDotK,
54                                         final FieldODEStateAndDerivative<T> globalPreviousState,
55                                         final FieldODEStateAndDerivative<T> globalCurrentState,
56                                         final FieldODEStateAndDerivative<T> softPreviousState,
57                                         final FieldODEStateAndDerivative<T> softCurrentState,
58                                         final FieldEquationsMapper<T> mapper) {
59          super(field, forward, yDotK,
60                globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
61                mapper);
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      protected HighamHall54FieldStateInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
67                                                             final FieldODEStateAndDerivative<T> newGlobalPreviousState,
68                                                             final FieldODEStateAndDerivative<T> newGlobalCurrentState,
69                                                             final FieldODEStateAndDerivative<T> newSoftPreviousState,
70                                                             final FieldODEStateAndDerivative<T> newSoftCurrentState,
71                                                             final FieldEquationsMapper<T> newMapper) {
72          return new HighamHall54FieldStateInterpolator<T>(newField, newForward, newYDotK,
73                                                           newGlobalPreviousState, newGlobalCurrentState,
74                                                           newSoftPreviousState, newSoftCurrentState,
75                                                           newMapper);
76      }
77  
78      /** {@inheritDoc} */
79      @SuppressWarnings("unchecked")
80      @Override
81      protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
82                                                                                     final T time, final T theta,
83                                                                                     final T thetaH, final T oneMinusThetaH) {
84  
85          final T bDot0 = theta.multiply(theta.multiply(theta.multiply( -10.0      ).add( 16.0       )).add(-15.0 /  2.0)).add(1);
86          final T bDot1 = time.getField().getZero();
87          final T bDot2 = theta.multiply(theta.multiply(theta.multiply( 135.0 / 2.0).add(-729.0 / 8.0)).add(459.0 / 16.0));
88          final T bDot3 = theta.multiply(theta.multiply(theta.multiply(-120.0      ).add( 152.0      )).add(-44.0       ));
89          final T bDot4 = theta.multiply(theta.multiply(theta.multiply( 125.0 / 2.0).add(-625.0 / 8.0)).add(375.0 / 16.0));
90          final T bDot5 = theta.multiply(  5.0 /  8.0).multiply(theta.multiply(2).subtract(1));
91          final T[] interpolatedState;
92          final T[] interpolatedDerivatives;
93  
94          if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
95              final T b0 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply( -5.0 / 2.0).add(  16.0 /  3.0)).add(-15.0 /  4.0)).add(1));
96              final T b1 = time.getField().getZero();
97              final T b2 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(135.0 / 8.0).add(-243.0 /  8.0)).add(459.0 / 32.0)));
98              final T b3 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(-30.0      ).add( 152.0 /  3.0)).add(-22.0       )));
99              final T b4 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(125.0 / 8.0).add(-625.0 / 24.0)).add(375.0 / 32.0)));
100             final T b5 = thetaH.multiply(theta.multiply(theta.multiply(                                   5.0 / 12.0 ).add( -5.0 / 16.0)));
101             interpolatedState       = previousStateLinearCombination(b0, b1, b2, b3, b4, b5);
102             interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
103         } else {
104             final T theta2 = theta.multiply(theta);
105             final T h      = thetaH.divide(theta);
106             final T b0 = h.multiply( theta.multiply(theta.multiply(theta.multiply(theta.multiply(-5.0 / 2.0).add( 16.0 / 3.0)).add( -15.0 /  4.0)).add(  1.0       )).add(  -1.0 / 12.0));
107             final T b1 = time.getField().getZero();
108             final T b2 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               135.0 / 8.0 ).add(-243.0 /  8.0)).add(459.0 / 32.0)).add( -27.0 / 32.0));
109             final T b3 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               -30.0       ).add( 152.0 /  3.0)).add(-22.0       )).add(  4.0  /  3.0));
110             final T b4 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               125.0 / 8.0 ).add(-625.0 / 24.0)).add(375.0 / 32.0)).add(-125.0 / 96.0));
111             final T b5 = h.multiply(theta2.multiply(theta.multiply(                                                                   5.0 / 12.0 ).add(-5.0  / 16.0)).add(  -5.0 / 48.0));
112             interpolatedState       = currentStateLinearCombination(b0, b1, b2, b3, b4, b5);
113             interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
114         }
115 
116         return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
117 
118     }
119 
120 }