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.CalculusFieldElement;
21  import org.hipparchus.Field;
22  import org.hipparchus.exception.MathIllegalArgumentException;
23  import org.hipparchus.exception.MathIllegalStateException;
24  import org.hipparchus.util.Binary64Field;
25  import org.junit.jupiter.api.Test;
26  
27  import static org.junit.jupiter.api.Assertions.assertThrows;
28  
29  class AdamsBashforthFieldIntegratorTest extends AdamsFieldIntegratorAbstractTest {
30  
31      protected <T extends CalculusFieldElement<T>> AdamsFieldIntegrator<T>
32      createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
33                       final double scalAbsoluteTolerance, final double scalRelativeTolerance) {
34          return new AdamsBashforthFieldIntegrator<T>(field, nSteps, minStep, maxStep,
35                          scalAbsoluteTolerance, scalRelativeTolerance);
36      }
37  
38      protected <T extends CalculusFieldElement<T>> AdamsFieldIntegrator<T>
39      createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
40                       final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) {
41          return new AdamsBashforthFieldIntegrator<T>(field, nSteps, minStep, maxStep,
42                          vecAbsoluteTolerance, vecRelativeTolerance);
43      }
44  
45      @Test
46      void testNbPoints() {
47          doNbPointsTest();
48      }
49  
50      @Test
51      public void testMinStep() {
52          assertThrows(MathIllegalArgumentException.class, () -> {
53              doDimensionCheck(Binary64Field.getInstance());
54          });
55      }
56  
57      @Test
58      public void testIncreasingTolerance() {
59          // the 2.6 and 122 factors are only valid for this test
60          // and has been obtained from trial and error
61          // there are no general relationship between local and global errors
62          doTestIncreasingTolerance(Binary64Field.getInstance(), 2.6, 122);
63      }
64  
65      @Test
66      public void exceedMaxEvaluations() {
67          assertThrows(MathIllegalStateException.class, () -> {
68              doExceedMaxEvaluations(Binary64Field.getInstance(), 650);
69          });
70      }
71  
72      @Test
73      public void backward() {
74          doBackward(Binary64Field.getInstance(), 4.3e-8, 4.3e-8, 1.0e-16, "Adams-Bashforth");
75      }
76  
77      @Test
78      public void polynomial() {
79          doPolynomial(Binary64Field.getInstance(), 5, 9.0e-4, 9.3e-10);
80      }
81  
82      @Test
83      public void testSecondaryEquations() {
84          doTestSecondaryEquations(Binary64Field.getInstance(), 4.3e-10, 8.9e-16);
85      }
86  
87      @Test
88      public void testStartFailure() {
89          assertThrows(MathIllegalStateException.class, () -> {
90              doTestStartFailure(Binary64Field.getInstance());
91          });
92      }
93  
94  }