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.sampling;
19  
20  import org.apache.commons.math4.legacy.exception.MaxCountExceededException;
21  
22  
23  /**
24   * This interface represents a handler that should be called after
25   * each successful step.
26   *
27   * <p>The ODE integrators compute the evolution of the state vector at
28   * some grid points that depend on their own internal algorithm. Once
29   * they have found a new grid point (possibly after having computed
30   * several evaluation of the derivative at intermediate points), they
31   * provide it to objects implementing this interface. These objects
32   * typically either ignore the intermediate steps and wait for the
33   * last one, store the points in an ephemeris, or forward them to
34   * specialized processing or output methods.</p>
35   *
36   * @see org.apache.commons.math4.legacy.ode.FirstOrderIntegrator
37   * @see org.apache.commons.math4.legacy.ode.SecondOrderIntegrator
38   * @see StepInterpolator
39   * @since 1.2
40   */
41  
42  public interface StepHandler {
43  
44      /** Initialize step handler at the start of an ODE integration.
45       * <p>
46       * This method is called once at the start of the integration. It
47       * may be used by the step handler to initialize some internal data
48       * if needed.
49       * </p>
50       * @param t0 start value of the independent <i>time</i> variable
51       * @param y0 array containing the start value of the state vector
52       * @param t target time for the integration
53       */
54      void init(double t0, double[] y0, double t);
55  
56      /**
57       * Handle the last accepted step.
58       * @param interpolator interpolator for the last accepted step. For
59       * efficiency purposes, the various integrators reuse the same
60       * object on each call, so if the instance wants to keep it across
61       * all calls (for example to provide at the end of the integration a
62       * continuous model valid throughout the integration range, as the
63       * {@link org.apache.commons.math4.legacy.ode.ContinuousOutputModel
64       * ContinuousOutputModel} class does), it should build a local copy
65       * using the clone method of the interpolator and store this copy.
66       * Keeping only a reference to the interpolator and reusing it will
67       * result in unpredictable behavior (potentially crashing the application).
68       * @param isLast true if the step is the last one
69       * @exception MaxCountExceededException if the interpolator throws one because
70       * the number of functions evaluations is exceeded
71       */
72      void handleStep(StepInterpolator interpolator, boolean isLast)
73          throws MaxCountExceededException;
74  }