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 represents an interpolator over the last step during an
25   * ODE integration for the 5(4) Higham and Hall integrator.
26   *
27   * @see HighamHall54Integrator
28   *
29   */
30  
31  class HighamHall54StateInterpolator
32      extends RungeKuttaStateInterpolator {
33  
34      /** Serializable version identifier */
35      private static final long serialVersionUID = 20111120L;
36  
37      /** Simple constructor.
38       * @param forward integration direction indicator
39       * @param yDotK slopes at the intermediate points
40       * @param globalPreviousState start of the global step
41       * @param globalCurrentState end of the global step
42       * @param softPreviousState start of the restricted step
43       * @param softCurrentState end of the restricted step
44       * @param mapper equations mapper for the all equations
45       */
46      HighamHall54StateInterpolator(final boolean forward,
47                                    final double[][] yDotK,
48                                    final ODEStateAndDerivative globalPreviousState,
49                                    final ODEStateAndDerivative globalCurrentState,
50                                    final ODEStateAndDerivative softPreviousState,
51                                    final ODEStateAndDerivative softCurrentState,
52                                    final EquationsMapper mapper) {
53          super(forward, yDotK,
54                globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
55                mapper);
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      protected HighamHall54StateInterpolator create(final boolean newForward, final double[][] newYDotK,
61                                                     final ODEStateAndDerivative newGlobalPreviousState,
62                                                     final ODEStateAndDerivative newGlobalCurrentState,
63                                                     final ODEStateAndDerivative newSoftPreviousState,
64                                                     final ODEStateAndDerivative newSoftCurrentState,
65                                                     final EquationsMapper newMapper) {
66          return new HighamHall54StateInterpolator(newForward, newYDotK,
67                                                  newGlobalPreviousState, newGlobalCurrentState,
68                                                  newSoftPreviousState, newSoftCurrentState,
69                                                  newMapper);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      protected ODEStateAndDerivative computeInterpolatedStateAndDerivatives(final EquationsMapper mapper,
75                                                                             final double time, final double theta,
76                                                                             final double thetaH, final double oneMinusThetaH) {
77  
78          final double bDot0 = 1 + theta * (-15.0/2.0 + theta * (16.0 - 10.0 * theta));
79          final double bDot1 = 0;
80          final double bDot2 = theta * (459.0/16.0 + theta * (-729.0/8.0 + 135.0/2.0 * theta));
81          final double bDot3 = theta * (-44.0 + theta * (152.0 - 120.0 * theta));
82          final double bDot4 = theta * (375.0/16.0 + theta * (-625.0/8.0 + 125.0/2.0 * theta));
83          final double bDot5 = theta * 5.0/8.0 * (2 * theta - 1);
84  
85          final double[] interpolatedState;
86          final double[] interpolatedDerivatives;
87          if (getGlobalPreviousState() != null && theta <= 0.5) {
88              final double b0 = thetaH * (1.0 + theta * (-15.0/4.0  + theta * (16.0/3.0 - 5.0/2.0 * theta)));
89              final double b1 = 0;
90              final double b2 = thetaH * (      theta * (459.0/32.0 + theta * (-243.0/8.0 + theta * 135.0/8.0)));
91              final double b3 = thetaH * (      theta * (-22.0      + theta * (152.0/3.0  + theta * -30.0)));
92              final double b4 = thetaH * (      theta * (375.0/32.0 + theta * (-625.0/24.0 + theta * 125.0/8.0)));
93              final double b5 = thetaH * (      theta * (-5.0/16.0  + theta *  5.0/12.0));
94              interpolatedState       = previousStateLinearCombination(b0 , b1, b2, b3, b4, b5);
95              interpolatedDerivatives = derivativeLinearCombination(bDot0 , bDot1, bDot2, bDot3, bDot4, bDot5);
96          } else {
97              final double theta2 = theta * theta;
98              final double h      = thetaH / theta;
99              final double b0 = h * (-1.0/12.0 + theta * (1.0 + theta * (-15.0/4.0 + theta * (16.0/3.0 + theta * -5.0/2.0))));
100             final double b1 = 0;
101             final double b2 = h * (-27.0/32.0 + theta2 * (459.0/32.0 + theta * (-243.0/8.0 + theta * 135.0/8.0)));
102             final double b3 = h * (4.0/3.0 + theta2 * (-22.0 + theta * (152.0/3.0  + theta * -30.0)));
103             final double b4 = h * (-125.0/96.0 + theta2 * (375.0/32.0 + theta * (-625.0/24.0 + theta * 125.0/8.0)));
104             final double b5 = h * (-5.0/48.0 + theta2 * (-5.0/16.0 + theta * 5.0/12.0));
105             interpolatedState       = currentStateLinearCombination(b0 , b1, b2, b3, b4, b5);
106             interpolatedDerivatives = derivativeLinearCombination(bDot0 , bDot1, bDot2, bDot3, bDot4, bDot5);
107         }
108 
109         return mapper.mapStateAndDerivative(time, interpolatedState, interpolatedDerivatives);
110 
111     }
112 
113 }