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.RealFieldElement;
021import org.apache.commons.math3.exception.MaxCountExceededException;
022import org.apache.commons.math3.ode.FieldODEStateAndDerivative;
023
024/**
025 * This interface represents a handler that should be called after
026 * each successful step.
027 *
028 * <p>The ODE integrators compute the evolution of the state vector at
029 * some grid points that depend on their own internal algorithm. Once
030 * they have found a new grid point (possibly after having computed
031 * several evaluation of the derivative at intermediate points), they
032 * provide it to objects implementing this interface. These objects
033 * typically either ignore the intermediate steps and wait for the
034 * last one, store the points in an ephemeris, or forward them to
035 * specialized processing or output methods.</p>
036 *
037 * @see org.apache.commons.math3.ode.FirstOrderFieldIntegrator
038 * @see FieldStepInterpolator
039 * @param <T> the type of the field elements
040 * @since 3.6
041 */
042
043public interface FieldStepHandler<T extends RealFieldElement<T>> {
044
045    /** Initialize step handler at the start of an ODE integration.
046     * <p>
047     * This method is called once at the start of the integration. It
048     * may be used by the step handler to initialize some internal data
049     * if needed.
050     * </p>
051     * @param initialState initial time, state vector and derivative
052     * @param finalTime target time for the integration
053     */
054    void init(FieldODEStateAndDerivative<T> initialState, T finalTime);
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(FieldStepInterpolator<T> interpolator, boolean isLast)
073        throws MaxCountExceededException;
074
075}