ODEIntegrator.java

  1. /*
  2.  * Licensed to the Hipparchus project 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 Hipparchus project 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.  *      https://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. package org.hipparchus.ode;

  18. import java.util.List;

  19. import org.hipparchus.exception.MathIllegalArgumentException;
  20. import org.hipparchus.exception.MathIllegalStateException;
  21. import org.hipparchus.ode.events.ODEEventDetector;
  22. import org.hipparchus.ode.events.ODEStepEndHandler;
  23. import org.hipparchus.ode.sampling.ODEStepHandler;

  24. /** This interface represents a first order integrator for
  25.  * differential equations.

  26.  * <p>The classes which are devoted to solve first order differential
  27.  * equations should implement this interface. The problems which can
  28.  * be handled should implement the {@link
  29.  * OrdinaryDifferentialEquation} interface.</p>
  30.  *
  31.  * @see OrdinaryDifferentialEquation
  32.  * @see org.hipparchus.ode.sampling.ODEStepHandler
  33.  * @see org.hipparchus.ode.events.ODEEventHandler
  34.  */
  35. public interface ODEIntegrator  {

  36.     /** Get the name of the method.
  37.      * @return name of the method
  38.      */
  39.     String getName();

  40.     /** Add a step handler to this integrator.
  41.      * <p>The handler will be called by the integrator for each accepted
  42.      * step.</p>
  43.      * @param handler handler for the accepted steps
  44.      * @see #getStepHandlers()
  45.      * @see #clearStepHandlers()
  46.      */
  47.     void addStepHandler(ODEStepHandler handler);

  48.     /** Get all the step handlers that have been added to the integrator.
  49.      * @return an unmodifiable collection of the added events handlers
  50.      * @see #addStepHandler(ODEStepHandler)
  51.      * @see #clearStepHandlers()
  52.      */
  53.     List<ODEStepHandler> getStepHandlers();

  54.     /** Remove all the step handlers that have been added to the integrator.
  55.      * @see #addStepHandler(ODEStepHandler)
  56.      * @see #getStepHandlers()
  57.      */
  58.     void clearStepHandlers();

  59.     /** Add an event detector to the integrator.
  60.      * @param detector event detector
  61.      * @see #getEventDetectors()
  62.      * @see #clearEventDetectors()
  63.      * @since 3.0
  64.      */
  65.     void addEventDetector(ODEEventDetector detector);

  66.     /** Get all the event detectors that have been added to the integrator.
  67.      * @return an unmodifiable list of the added events detectors
  68.      * @see #addEventDetector(ODEEventDetector)
  69.      * @see #clearEventDetectors()
  70.      * @since 3.0
  71.      */
  72.     List<ODEEventDetector> getEventDetectors();

  73.     /** Remove all the event handlers that have been added to the integrator.
  74.      * @see #addEventDetector(ODEEventDetector)
  75.      * @see #getEventDetectors()
  76.      * @since 3.0
  77.      */
  78.     void clearEventDetectors();

  79.     /** Add a handler for step ends to the integrator.
  80.      * <p>
  81.      * The {@link ODEStepEndHandler#stepEndOccurred(ODEStateAndDerivative, boolean)
  82.      * stepEndOccurred(state, forward)} method of the {@code handler} will be called
  83.      * at each step end.
  84.      * </p>
  85.      * @param handler handler for step ends
  86.      * @see #getStepEndHandlers()
  87.      * @see #clearStepEndHandlers()
  88.      * @since 3.0
  89.      */
  90.     void addStepEndHandler(ODEStepEndHandler handler);

  91.     /** Get all the handlers for step ends that have been added to the integrator.
  92.      * @return an unmodifiable list of the added step end handlers
  93.      * @see #addStepEndHandler(ODEStepEndHandler)
  94.      * @see #clearStepEndHandlers()
  95.      * @since 3.0
  96.      */
  97.     List<ODEStepEndHandler> getStepEndHandlers();

  98.     /** Remove all the handlers for step ends that have been added to the integrator.
  99.      * @see #addStepEndHandler(ODEStepEndHandler)
  100.      * @see #getStepEndHandlers()
  101.      * @since 3.0
  102.      */
  103.     void clearStepEndHandlers();

  104.     /** Get the state at step start time t<sub>i</sub>.
  105.      * <p>This method can be called during integration (typically by
  106.      * the object implementing the {@link OrdinaryDifferentialEquation
  107.      * differential equations} problem) if the value of the current step that
  108.      * is attempted is needed.</p>
  109.      * <p>The result is undefined if the method is called outside of
  110.      * calls to <code>integrate</code>.</p>
  111.      * @return state at step start time t<sub>i</sub>
  112.      */
  113.     ODEStateAndDerivative getStepStart();

  114.     /** Get the current signed value of the integration stepsize.
  115.      * <p>This method can be called during integration (typically by
  116.      * the object implementing the {@link OrdinaryDifferentialEquation
  117.      * differential equations} problem) if the signed value of the current stepsize
  118.      * that is tried is needed.</p>
  119.      * <p>The result is undefined if the method is called outside of
  120.      * calls to <code>integrate</code>.</p>
  121.      * @return current signed value of the stepsize
  122.      */
  123.     double getCurrentSignedStepsize();

  124.     /** Set the maximal number of differential equations function evaluations.
  125.      * <p>The purpose of this method is to avoid infinite loops which can occur
  126.      * for example when stringent error constraints are set or when lots of
  127.      * discrete events are triggered, thus leading to many rejected steps.</p>
  128.      * @param maxEvaluations maximal number of function evaluations (negative
  129.      * values are silently converted to maximal integer value, thus representing
  130.      * almost unlimited evaluations)
  131.      */
  132.     void setMaxEvaluations(int maxEvaluations);

  133.     /** Get the maximal number of functions evaluations.
  134.      * @return maximal number of functions evaluations
  135.      */
  136.     int getMaxEvaluations();

  137.     /** Get the number of evaluations of the differential equations function.
  138.      * <p>
  139.      * The number of evaluations corresponds to the last call to the
  140.      * <code>integrate</code> method. It is 0 if the method has not been called yet.
  141.      * </p>
  142.      * @return number of evaluations of the differential equations function
  143.      */
  144.     int getEvaluations();

  145.     /** Integrate the differential equations up to the given time.
  146.      * <p>This method solves an Initial Value Problem (IVP).</p>
  147.      * <p>Since this method stores some internal state variables made
  148.      * available in its public interface during integration ({@link
  149.      * #getCurrentSignedStepsize()}), it is <em>not</em> thread-safe.</p>
  150.      * @param equations differential equations to integrate
  151.      * @param initialState initial state (time, primary and secondary state vectors)
  152.      * @param finalTime target time for the integration
  153.      * (can be set to a value smaller than {@code t0} for backward integration)
  154.      * @return final state, its time will be the same as {@code finalTime} if
  155.      * integration reached its target, but may be different if some {@link
  156.      * org.hipparchus.ode.events.ODEEventHandler} stops it at some point.
  157.      * @exception MathIllegalArgumentException if integration step is too small
  158.      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
  159.      * @exception MathIllegalArgumentException if the location of an event cannot be bracketed
  160.      */
  161.     ODEStateAndDerivative integrate(ExpandableODE equations,
  162.                                     ODEState initialState, double finalTime)
  163.         throws MathIllegalArgumentException, MathIllegalStateException;

  164.     /** Integrate the differential equations up to the given time.
  165.      * <p>This method solves an Initial Value Problem (IVP).</p>
  166.      * <p>Since this method stores some internal state variables made
  167.      * available in its public interface during integration ({@link
  168.      * #getCurrentSignedStepsize()}), it is <em>not</em> thread-safe.</p>
  169.      * @param equations differential equations to integrate
  170.      * @param initialState initial state (time, primary and secondary state vectors)
  171.      * @param finalTime target time for the integration
  172.      * (can be set to a value smaller than {@code t0} for backward integration)
  173.      * @return final state, its time will be the same as {@code finalTime} if
  174.      * integration reached its target, but may be different if some {@link
  175.      * org.hipparchus.ode.events.ODEEventHandler} stops it at some point.
  176.      * @exception MathIllegalArgumentException if integration step is too small
  177.      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
  178.      * @exception MathIllegalArgumentException if the location of an event cannot be bracketed
  179.      */
  180.     default ODEStateAndDerivative integrate(OrdinaryDifferentialEquation equations,
  181.                                             ODEState initialState, double finalTime)
  182.         throws MathIllegalArgumentException, MathIllegalStateException {
  183.         return integrate(new ExpandableODE(equations), initialState, finalTime);
  184.     }

  185. }