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