View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) 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 ASF 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    *      http://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.apache.commons.math4.legacy.ode.nonstiff;
19  
20  
21  import org.apache.commons.math4.legacy.core.Field;
22  import org.apache.commons.math4.legacy.core.RealFieldElement;
23  import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
24  import org.apache.commons.math4.legacy.exception.MaxCountExceededException;
25  import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
26  import org.junit.Test;
27  
28  public class AdamsBashforthFieldIntegratorTest extends AdamsFieldIntegratorAbstractTest {
29  
30      @Override
31      protected <T extends RealFieldElement<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<>(field, nSteps, minStep, maxStep,
35                          scalAbsoluteTolerance, scalRelativeTolerance);
36      }
37  
38      @Override
39      protected <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
40      createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
41                       final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) {
42          return new AdamsBashforthFieldIntegrator<>(field, nSteps, minStep, maxStep,
43                          vecAbsoluteTolerance, vecRelativeTolerance);
44      }
45  
46      @Override
47      @Test(expected=NumberIsTooSmallException.class)
48      public void testMinStep() {
49          doDimensionCheck(Decimal64Field.getInstance());
50      }
51  
52      @Override
53      @Test
54      public void testIncreasingTolerance() {
55          // the 2.6 and 122 factors are only valid for this test
56          // and has been obtained from trial and error
57          // there are no general relationship between local and global errors
58          doTestIncreasingTolerance(Decimal64Field.getInstance(), 2.6, 122);
59      }
60  
61      @Override
62      @Test(expected = MaxCountExceededException.class)
63      public void exceedMaxEvaluations() {
64          doExceedMaxEvaluations(Decimal64Field.getInstance(), 650);
65      }
66  
67      @Override
68      @Test
69      public void backward() {
70          doBackward(Decimal64Field.getInstance(), 4.3e-8, 4.3e-8, 1.0e-16, "Adams-Bashforth");
71      }
72  
73      @Override
74      @Test
75      public void polynomial() {
76          doPolynomial(Decimal64Field.getInstance(), 5, 0.004, 6.0e-10);
77      }
78  
79      @Override
80      @Test(expected=MathIllegalStateException.class)
81      public void testStartFailure() {
82          doTestStartFailure(Decimal64Field.getInstance());
83      }
84  }