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.interpolators;
19  
20  
21  import org.hipparchus.analysis.differentiation.DSFactory;
22  import org.hipparchus.analysis.differentiation.DerivativeStructure;
23  import org.hipparchus.ode.EquationsMapper;
24  import org.hipparchus.ode.ExpandableODE;
25  import org.hipparchus.ode.ODEStateAndDerivative;
26  import org.hipparchus.ode.sampling.AbstractODEStateInterpolator;
27  import org.junit.jupiter.api.Test;
28  
29  class GraggBulirschStoerStateInterpolatorTest extends ODEStateInterpolatorAbstractTest {
30  
31      protected AbstractODEStateInterpolator setUpInterpolator(final ReferenceODE eqn,
32                                                               final double t0, final double[] y0,
33                                                               final double t1) {
34  
35          // evaluate scaled derivatives at mid-step
36          final int derivationOrder = 7;
37          DerivativeStructure middleT = new DSFactory(1, derivationOrder).variable(0, 0.5 * (t0 + t1));
38          DerivativeStructure[] derivatives =  eqn.theoreticalState(middleT);
39  
40          final double[][] yMidDots = new double[derivationOrder + 1][eqn.getDimension()];
41          final double     h        = t1 - t0;
42          double           hK       = 1.0;
43          for (int k = 0; k < yMidDots.length; ++k) {
44              for (int i = 0; i < derivatives.length; ++i) {
45                  yMidDots[k][i] = hK * derivatives[i].getPartialDerivative(k);
46              }
47              hK *= h;
48          }
49  
50          EquationsMapper mapper = new ExpandableODE(eqn).getMapper();
51          ODEStateAndDerivative s0 = mapper.mapStateAndDerivative(t0, y0, eqn.computeDerivatives(t0, y0));
52          double[] y1 = eqn.theoreticalState(t1);
53          ODEStateAndDerivative s1 = mapper.mapStateAndDerivative(t1, y1, eqn.computeDerivatives(t1, y1));
54  
55          GraggBulirschStoerStateInterpolator interpolator =
56                          new GraggBulirschStoerStateInterpolator(t1 >= t0, s0, s1, s0, s1,
57                                                                  mapper, yMidDots, derivationOrder);
58          return interpolator;
59  
60      }
61  
62      @Override
63      @Test
64      public void interpolationAtBounds() {
65          doInterpolationAtBounds(1.0e-15);
66      }
67  
68      @Override
69      @Test
70      public void interpolationInside() {
71          doInterpolationInside(3.5e-18, 1.2e-16);
72      }
73  
74      @Override
75      @Test
76      public void restrictPrevious() {
77          doRestrictPrevious(1.0e-15, 1.0e-15);
78      }
79  
80      @Override
81      @Test
82      public void restrictCurrent() {
83          doRestrictCurrent(1.0e-15, 1.0e-15);
84      }
85  
86      @Override
87      @Test
88      public void restrictBothEnds() {
89          doRestrictBothEnds(1.0e-15, 1.0e-15);
90      }
91  
92      @Override
93      @Test
94      public void degenerateInterpolation() {
95          doDegenerateInterpolation();
96      }
97  
98  }