ODEStepEndHandler.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.events;

  18. import org.hipparchus.ode.ODEState;
  19. import org.hipparchus.ode.ODEStateAndDerivative;

  20. /** This interface represents a handler for discrete events triggered
  21.  * during ODE integration at each step end.
  22.  * @see org.hipparchus.ode.events
  23.  * @since 3.0
  24.  */
  25. public interface ODEStepEndHandler  {

  26.     /** Initialize step end handler at the start of an ODE integration.
  27.      * <p>
  28.      * This method is called once at the start of the integration. It
  29.      * may be used by the step end handler to initialize some internal data
  30.      * if needed.
  31.      * </p>
  32.      * <p>
  33.      * The default implementation does nothing
  34.      * </p>
  35.      * @param initialState initial time, state vector and derivative
  36.      * @param finalTime target time for the integration
  37.      */
  38.     default void init(ODEStateAndDerivative initialState, double finalTime) {
  39.         // nothing by default
  40.     }

  41.     /** Handle an event and choose what to do next.

  42.      * <p>This method is called when the integrator has accepted a step
  43.      * ending exactly on step end, just <em>after</em>
  44.      * the step handler itself is called (see below for scheduling). It
  45.      * allows the user to update his internal data to acknowledge the fact
  46.      * the event has been handled (for example setting a flag in the {@link
  47.      * org.hipparchus.ode.OrdinaryDifferentialEquation
  48.      * differential equations} to switch the derivatives computation in
  49.      * case of discontinuity), or to direct the integrator to either stop
  50.      * or continue integration, possibly with a reset state or derivatives.</p>
  51.      *
  52.      * <ul>
  53.      *   <li>if {@link Action#STOP} is returned, the integration will be stopped,</li>
  54.      *   <li>if {@link Action#RESET_STATE} is returned, the {@link #resetState
  55.      *   resetState} method will be called once the step handler has
  56.      *   finished its task, and the integrator will also recompute the
  57.      *   derivatives,</li>
  58.      *   <li>if {@link Action#RESET_DERIVATIVES} is returned, the integrator
  59.      *   will recompute the derivatives,
  60.      *   <li>if {@link Action#RESET_EVENTS} is returned, the integrator
  61.      *   will recheck all event handlers,
  62.      *   <li>if {@link Action#CONTINUE} is returned, no specific action will
  63.      *   be taken (apart from having called this method) and integration
  64.      *   will continue.</li>
  65.      * </ul>
  66.      *
  67.      * <p>The scheduling between this method and the {@link
  68.      * org.hipparchus.ode.sampling.ODEStepHandler ODEStepHandler} method {@link
  69.      * org.hipparchus.ode.sampling.ODEStepHandler#handleStep(org.hipparchus.ode.sampling.ODEStateInterpolator)
  70.      * handleStep(interpolator)} is to call {@code handleStep} first and this method afterwards.
  71.      * This scheduling allows user code called by this method and user code called by step
  72.      * handlers to get values of the independent time variable consistent with integration direction.</p>
  73.      *
  74.      * @param state current value of the independent <i>time</i> variable, state vector
  75.      * and derivative at step end
  76.      * @param forward if true, propagation is forward
  77.      * @return indication of what the integrator should do next, this
  78.      * value must be one of {@link Action#STOP}, {@link Action#RESET_STATE},
  79.      * {@link Action#RESET_DERIVATIVES}, {@link Action#RESET_EVENTS}, or
  80.      * {@link Action#CONTINUE}
  81.      */
  82.     Action stepEndOccurred(ODEStateAndDerivative state, boolean forward);

  83.     /** Reset the state prior to continue the integration.
  84.      *
  85.      * <p>This method is called after the step handler has returned and
  86.      * before the next step is started, but only when {@link
  87.      * ODEEventHandler#eventOccurred(ODEStateAndDerivative, ODEEventDetector, boolean)}
  88.      * has itself returned the {@link Action#RESET_STATE}
  89.      * indicator. It allows the user to reset the state vector for the
  90.      * next step, without perturbing the step handler of the finishing
  91.      * step.</p>
  92.      * <p>The default implementation returns its argument.</p>
  93.      * @param state current value of the independent <i>time</i> variable, state vector
  94.      * and derivative at step end
  95.      * @return reset state (note that it does not include the derivatives, they will
  96.      * be added automatically by the integrator afterwards)
  97.      */
  98.     default ODEState resetState(ODEStateAndDerivative state) {
  99.         return state;
  100.     }

  101. }