001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.math3.ode.sampling;
019
020import org.apache.commons.math3.exception.MaxCountExceededException;
021
022
023/**
024 * This interface represents a handler that should be called after
025 * each successful step.
026 *
027 * <p>The ODE integrators compute the evolution of the state vector at
028 * some grid points that depend on their own internal algorithm. Once
029 * they have found a new grid point (possibly after having computed
030 * several evaluation of the derivative at intermediate points), they
031 * provide it to objects implementing this interface. These objects
032 * typically either ignore the intermediate steps and wait for the
033 * last one, store the points in an ephemeris, or forward them to
034 * specialized processing or output methods.</p>
035 *
036 * @see org.apache.commons.math3.ode.FirstOrderIntegrator
037 * @see org.apache.commons.math3.ode.SecondOrderIntegrator
038 * @see StepInterpolator
039 * @since 1.2
040 */
041
042public interface StepHandler {
043
044    /** Initialize step handler at the start of an ODE integration.
045     * <p>
046     * This method is called once at the start of the integration. It
047     * may be used by the step handler to initialize some internal data
048     * if needed.
049     * </p>
050     * @param t0 start value of the independent <i>time</i> variable
051     * @param y0 array containing the start value of the state vector
052     * @param t target time for the integration
053     */
054    void init(double t0, double[] y0, double t);
055
056    /**
057     * Handle the last accepted step
058     * @param interpolator interpolator for the last accepted step. For
059     * efficiency purposes, the various integrators reuse the same
060     * object on each call, so if the instance wants to keep it across
061     * all calls (for example to provide at the end of the integration a
062     * continuous model valid throughout the integration range, as the
063     * {@link org.apache.commons.math3.ode.ContinuousOutputModel
064     * ContinuousOutputModel} class does), it should build a local copy
065     * using the clone method of the interpolator and store this copy.
066     * Keeping only a reference to the interpolator and reusing it will
067     * result in unpredictable behavior (potentially crashing the application).
068     * @param isLast true if the step is the last one
069     * @exception MaxCountExceededException if the interpolator throws one because
070     * the number of functions evaluations is exceeded
071     */
072    void handleStep(StepInterpolator interpolator, boolean isLast)
073        throws MaxCountExceededException;
074
075}