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    
018    package org.apache.commons.math.ode.jacobians;
019    
020    import org.apache.commons.math.ode.DerivativeException;
021    
022    /**
023     * This interface represents a handler that should be called after
024     * each successful step.
025     *
026     * <p>The ODE integrators compute the evolution of the state vector at
027     * some grid points that depend on their own internal algorithm. Once
028     * they have found a new grid point (possibly after having computed
029     * several evaluation of the derivative at intermediate points), they
030     * provide it to objects implementing this interface. These objects
031     * typically either ignore the intermediate steps and wait for the
032     * last one, store the points in an ephemeris, or forward them to
033     * specialized processing or output methods.</p>
034     *
035     * <p>Note that is is possible to register a {@link
036     * org.apache.commons.math.ode.sampling.StepHandler classical step handler}
037     * in the low level integrator used to build a {@link FirstOrderIntegratorWithJacobians}
038     * rather than implementing this class. The step handlers registered at low level
039     * will see the big compound state whether the step handlers defined by this interface
040     * see the original state, and its jacobians in separate arrays.</p>
041     *
042     * <p>The compound state is guaranteed to contain the original state in the first
043     * elements, followed by the jacobian with respect to initial state (in row order),
044     * followed by the jacobian with respect to parameters (in row order). If for example
045     * the original state dimension is 6 and there are 3 parameters, the compound state will
046     * be a 60 elements array. The first 6 elements will be the original state, the next 36
047     * elements will be the jacobian with respect to initial state, and the remaining 18 elements
048     * will be the jacobian with respect to parameters.</p>
049     *
050     * <p>Dealing with low level step handlers is cumbersome if one really needs the jacobians
051     * in these methods, but it also prevents many data being copied back and forth between
052     * state and jacobians on one side and compound state on the other side. So for performance
053     * reasons, it is recommended to use this interface <em>only</em> if jacobians are really
054     * needed and to use lower level handlers if only state is needed.</p>
055     *
056     * @see FirstOrderIntegratorWithJacobians
057     * @see StepInterpolatorWithJacobians
058     * @version $Revision: 920131 $ $Date: 2010-03-07 17:19:18 -0500 (Sun, 07 Mar 2010) $
059     * @since 2.1
060     */
061    
062    public interface StepHandlerWithJacobians {
063    
064      /** Determines whether this handler needs dense output.
065       * <p>This method allows the integrator to avoid performing extra
066       * computation if the handler does not need dense output.</p>
067       * @return true if the handler needs dense output
068       */
069      boolean requiresDenseOutput();
070    
071      /** Reset the step handler.
072       * Initialize the internal data as required before the first step is
073       * handled.
074       */
075      void reset();
076    
077      /**
078       * Handle the last accepted step
079       * @param interpolator interpolator for the last accepted step. For
080       * efficiency purposes, the various integrators reuse the same
081       * object on each call, so if the instance wants to keep it across
082       * all calls (for example to provide at the end of the integration a
083       * continuous model valid throughout the integration range, as the
084       * {@link org.apache.commons.math.ode.ContinuousOutputModel
085       * ContinuousOutputModel} class does), it should build a local copy
086       * using the clone method of the interpolator and store this copy.
087       * Keeping only a reference to the interpolator and reusing it will
088       * result in unpredictable behavior (potentially crashing the application).
089       * @param isLast true if the step is the last one
090       * @throws DerivativeException this exception is propagated to the
091       * caller if the underlying user function triggers one
092       */
093      void handleStep(StepInterpolatorWithJacobians interpolator, boolean isLast) throws DerivativeException;
094    
095    }