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;
019
020import java.util.Collection;
021
022import org.apache.commons.math3.analysis.solvers.UnivariateSolver;
023import org.apache.commons.math3.ode.events.EventHandler;
024import org.apache.commons.math3.ode.sampling.StepHandler;
025
026/**
027 * This interface defines the common parts shared by integrators
028 * for first and second order differential equations.
029 * @see FirstOrderIntegrator
030 * @see SecondOrderIntegrator
031 * @since 2.0
032 */
033public interface ODEIntegrator  {
034
035    /** Get the name of the method.
036     * @return name of the method
037     */
038    String getName();
039
040    /** Add a step handler to this integrator.
041     * <p>The handler will be called by the integrator for each accepted
042     * step.</p>
043     * @param handler handler for the accepted steps
044     * @see #getStepHandlers()
045     * @see #clearStepHandlers()
046     * @since 2.0
047     */
048    void addStepHandler(StepHandler handler);
049
050    /** Get all the step handlers that have been added to the integrator.
051     * @return an unmodifiable collection of the added events handlers
052     * @see #addStepHandler(StepHandler)
053     * @see #clearStepHandlers()
054     * @since 2.0
055     */
056    Collection<StepHandler> getStepHandlers();
057
058    /** Remove all the step handlers that have been added to the integrator.
059     * @see #addStepHandler(StepHandler)
060     * @see #getStepHandlers()
061     * @since 2.0
062     */
063    void clearStepHandlers();
064
065    /** Add an event handler to the integrator.
066     * Uses a default {@link UnivariateSolver}
067     * with an absolute accuracy equal to the given convergence threshold,
068     * as root-finding algorithm to detect the state events.
069     * @param handler event handler
070     * @param maxCheckInterval maximal time interval between switching
071     * function checks (this interval prevents missing sign changes in
072     * case the integration steps becomes very large)
073     * @param convergence convergence threshold in the event time search
074     * @param maxIterationCount upper limit of the iteration count in
075     * the event time search
076     * @see #getEventHandlers()
077     * @see #clearEventHandlers()
078     */
079    void addEventHandler(EventHandler handler, double maxCheckInterval,
080                         double convergence, int maxIterationCount);
081
082    /** Add an event handler to the integrator.
083     * @param handler event handler
084     * @param maxCheckInterval maximal time interval between switching
085     * function checks (this interval prevents missing sign changes in
086     * case the integration steps becomes very large)
087     * @param convergence convergence threshold in the event time search
088     * @param maxIterationCount upper limit of the iteration count in
089     * the event time search
090     * @param solver The root-finding algorithm to use to detect the state
091     * events.
092     * @see #getEventHandlers()
093     * @see #clearEventHandlers()
094     */
095    void addEventHandler(EventHandler handler, double maxCheckInterval,
096                         double convergence, int maxIterationCount,
097                         UnivariateSolver solver);
098
099    /** Get all the event handlers that have been added to the integrator.
100     * @return an unmodifiable collection of the added events handlers
101     * @see #addEventHandler(EventHandler, double, double, int)
102     * @see #clearEventHandlers()
103     */
104    Collection<EventHandler> getEventHandlers();
105
106    /** Remove all the event handlers that have been added to the integrator.
107     * @see #addEventHandler(EventHandler, double, double, int)
108     * @see #getEventHandlers()
109     */
110    void clearEventHandlers();
111
112    /** Get the current value of the step start time t<sub>i</sub>.
113     * <p>This method can be called during integration (typically by
114     * the object implementing the {@link FirstOrderDifferentialEquations
115     * differential equations} problem) if the value of the current step that
116     * is attempted is needed.</p>
117     * <p>The result is undefined if the method is called outside of
118     * calls to <code>integrate</code>.</p>
119     * @return current value of the step start time t<sub>i</sub>
120     */
121    double getCurrentStepStart();
122
123    /** Get the current signed value of the integration stepsize.
124     * <p>This method can be called during integration (typically by
125     * the object implementing the {@link FirstOrderDifferentialEquations
126     * differential equations} problem) if the signed value of the current stepsize
127     * that is tried is needed.</p>
128     * <p>The result is undefined if the method is called outside of
129     * calls to <code>integrate</code>.</p>
130     * @return current signed value of the stepsize
131     */
132    double getCurrentSignedStepsize();
133
134    /** Set the maximal number of differential equations function evaluations.
135     * <p>The purpose of this method is to avoid infinite loops which can occur
136     * for example when stringent error constraints are set or when lots of
137     * discrete events are triggered, thus leading to many rejected steps.</p>
138     * @param maxEvaluations maximal number of function evaluations (negative
139     * values are silently converted to maximal integer value, thus representing
140     * almost unlimited evaluations)
141     */
142    void setMaxEvaluations(int maxEvaluations);
143
144    /** Get the maximal number of functions evaluations.
145     * @return maximal number of functions evaluations
146     */
147    int getMaxEvaluations();
148
149    /** Get the number of evaluations of the differential equations function.
150     * <p>
151     * The number of evaluations corresponds to the last call to the
152     * <code>integrate</code> method. It is 0 if the method has not been called yet.
153     * </p>
154     * @return number of evaluations of the differential equations function
155     */
156    int getEvaluations();
157
158}