FieldODEStepEndHandler.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.CalculusFieldElement;
  19. import org.hipparchus.ode.FieldODEState;
  20. import org.hipparchus.ode.FieldODEStateAndDerivative;

  21. /** This interface represents a handler for discrete events triggered
  22.  * during ODE integration at each step end.
  23.  * @see org.hipparchus.ode.events
  24.  * @since 3.0
  25.  * @param <T> the type of the field elements
  26.  */
  27. public interface FieldODEStepEndHandler<T extends CalculusFieldElement<T>>  {

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

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

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

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

  103. }