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