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    *      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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.ode;
24  
25  import org.hipparchus.ode.events.ODEEventDetector;
26  
27  /**
28   * This class is used as the base class of the problems that are
29   * integrated during the junit tests for the ODE integrators.
30   */
31  public abstract class TestProblemAbstract
32      implements OrdinaryDifferentialEquation {
33  
34      /** Number of functions calls. */
35      private int calls;
36  
37      /** Initial state */
38      private final ODEState s0;
39  
40      /** Final time */
41      private final double t1;
42  
43      /** Error scale */
44      private final double[] errorScale;
45  
46      /**
47       * Simple constructor.
48       * @param t0 initial time
49       * @param y0 initial state vector
50       * @param t1 final time
51       * @param errorScale error scale
52       */
53      protected TestProblemAbstract(double t0, double[] y0, double t1, double[] errorScale) {
54          calls           = 0;
55          s0              = new ODEState(t0, y0);
56          this.t1         = t1;
57          this.errorScale = errorScale.clone();
58      }
59  
60      public int getDimension() {
61          return s0.getPrimaryState().length;
62      }
63  
64      /**
65       * Get the initial time.
66       * @return initial time
67       */
68      public double getInitialTime() {
69          return s0.getTime();
70      }
71  
72      /**
73       * Get the initial state vector.
74       * @return initial state vector
75       */
76      public ODEState getInitialState() {
77          return s0;
78      }
79  
80      /**
81       * Get the final time.
82       * @return final time
83       */
84      public double getFinalTime() {
85          return t1;
86      }
87  
88      /**
89       * Get the error scale.
90       * @return error scale
91       */
92      public double[] getErrorScale() {
93          return errorScale;
94      }
95  
96      /**
97       * Get the event detectors.
98       * @param maxCheck maximum checking interval, must be strictly positive (s)
99       * @param threshold convergence threshold (s)
100      * @param maxIter maximum number of iterations in the event time search
101      * @return events detectors   */
102     public ODEEventDetector[] getEventDetectors(final double maxCheck, final double threshold, final int maxIter) {
103         return new ODEEventDetector[0];
104     }
105 
106     /**
107      * Get the theoretical events times.
108      * @return theoretical events times
109      */
110     public double[] getTheoreticalEventsTimes() {
111         return new double[0];
112     }
113 
114     /**
115      * Get the number of calls.
116      * @return nuber of calls
117      */
118     public int getCalls() {
119         return calls;
120     }
121 
122     public double[] computeDerivatives(double t, double[] y) {
123         ++calls;
124         return doComputeDerivatives(t, y);
125     }
126 
127     abstract public double[] doComputeDerivatives(double t, double[] y);
128 
129     /**
130      * Compute the theoretical state at the specified time.
131      * @param t time at which the state is required
132      * @return state vector at time t
133      */
134     abstract public double[] computeTheoreticalState(double t);
135 
136 }