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.linear.Array2DRowRealMatrix;
22  import org.hipparchus.ode.ExpandableODE;
23  import org.hipparchus.ode.ODEStateAndDerivative;
24  import org.hipparchus.ode.sampling.AbstractODEStateInterpolator;
25  
26  public class AdamsStateInterpolatorTest extends ODEStateInterpolatorAbstractTest {
27  
28      @Override
29      protected AbstractODEStateInterpolator
30          setUpInterpolator(ReferenceODE eqn, double t0, double[] y0, double t1) {
31          final int        nSteps   = 12;
32          final double     h        = (t1 - t0) / (nSteps - 1);
33          final int        nbPoints = (nSteps + 3) / 2;
34          final double[]   t        = new double[nbPoints];
35          final double[][] y        = new double[nbPoints][];
36          final double[][] yDot     = new double[nbPoints][];
37          for (int i = 0; i < nbPoints; ++i) {
38              t[i]    = t0 + i * h;
39              y[i]    = eqn.theoreticalState(t[i]);
40              yDot[i] = eqn.computeDerivatives(t[i], y[i]);
41          }
42          AdamsNordsieckTransformer transformer = AdamsNordsieckTransformer.getInstance(nSteps);
43          Array2DRowRealMatrix      nordsieck   = transformer.initializeHighOrderDerivatives(h, t, y, yDot);
44  
45          double[] scaled = new double[eqn.getDimension()];
46          for (int i = 0; i < scaled.length; ++i) {
47              scaled[i] = h * yDot[0][i];
48          }
49          double   tCurrent    = t1;
50          double[] yCurrent    = eqn.theoreticalState(tCurrent);
51          double[] yDotCurrent = eqn.computeDerivatives(tCurrent, yCurrent);
52  
53          ODEStateAndDerivative previous = new ODEStateAndDerivative(t[0], y[0], yDot[0]);
54          ODEStateAndDerivative current  = new ODEStateAndDerivative(tCurrent, yCurrent, yDotCurrent);
55          return new AdamsStateInterpolator(h, previous, scaled, nordsieck, t1 >= t0,
56                                            previous, current, new ExpandableODE(eqn).getMapper());
57  
58      }
59  
60      @Override
61      public void interpolationAtBounds() {
62          // as the Adams step interpolator is based on a Taylor expansion since previous step,
63          // the maximum error is at step end and not in the middle of the step
64          // as for Runge-Kutta integrators
65          doInterpolationAtBounds(1.4e-6);
66      }
67  
68      @Override
69      public void interpolationInside() {
70          doInterpolationInside(3.3e-10, 1.4e-6);
71      }
72  
73      @Override
74      public void restrictPrevious() {
75          doRestrictPrevious(1.0e-15, 1.0e-15);
76      }
77  
78      @Override
79      public void restrictCurrent() {
80          doRestrictCurrent(1.0e-15, 1.0e-15);
81      }
82  
83      @Override
84      public void restrictBothEnds() {
85          doRestrictBothEnds(1.0e-15, 1.0e-15);
86      }
87  
88      @Override
89      public void degenerateInterpolation() {
90          doDegenerateInterpolation();
91      }
92  
93  }