View Javadoc
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  
18  package org.hipparchus.ode.events;
19  
20  import org.hipparchus.ode.ODEState;
21  import org.hipparchus.ode.ODEStateAndDerivative;
22  
23  /** This interface represents a handler for discrete events triggered
24   * during ODE integration at each step end.
25   * @see org.hipparchus.ode.events
26   * @since 3.0
27   */
28  @FunctionalInterface
29  public interface ODEStepEndHandler  {
30  
31      /** Initialize step end handler at the start of an ODE integration.
32       * <p>
33       * This method is called once at the start of the integration. It
34       * may be used by the step end handler to initialize some internal data
35       * if needed.
36       * </p>
37       * <p>
38       * The default implementation does nothing
39       * </p>
40       * @param initialState initial time, state vector and derivative
41       * @param finalTime target time for the integration
42       */
43      default void init(ODEStateAndDerivative initialState, double finalTime) {
44          // nothing by default
45      }
46  
47      /** Handle an event and choose what to do next.
48  
49       * <p>This method is called when the integrator has accepted a step
50       * ending exactly on step end, just <em>after</em>
51       * the step handler itself is called (see below for scheduling). It
52       * allows the user to update his internal data to acknowledge the fact
53       * the event has been handled (for example setting a flag in the {@link
54       * org.hipparchus.ode.OrdinaryDifferentialEquation
55       * differential equations} to switch the derivatives computation in
56       * case of discontinuity), or to direct the integrator to either stop
57       * or continue integration, possibly with a reset state or derivatives.</p>
58       *
59       * <ul>
60       *   <li>if {@link Action#STOP} is returned, the integration will be stopped,</li>
61       *   <li>if {@link Action#RESET_STATE} is returned, the {@link #resetState
62       *   resetState} method will be called once the step handler has
63       *   finished its task, and the integrator will also recompute the
64       *   derivatives,</li>
65       *   <li>if {@link Action#RESET_DERIVATIVES} is returned, the integrator
66       *   will recompute the derivatives,
67       *   <li>if {@link Action#RESET_EVENTS} is returned, the integrator
68       *   will recheck all event handlers,
69       *   <li>if {@link Action#CONTINUE} is returned, no specific action will
70       *   be taken (apart from having called this method) and integration
71       *   will continue.</li>
72       * </ul>
73       *
74       * <p>The scheduling between this method and the {@link
75       * org.hipparchus.ode.sampling.ODEStepHandler ODEStepHandler} method {@link
76       * org.hipparchus.ode.sampling.ODEStepHandler#handleStep(org.hipparchus.ode.sampling.ODEStateInterpolator)
77       * handleStep(interpolator)} is to call {@code handleStep} first and this method afterwards.
78       * This scheduling allows user code called by this method and user code called by step
79       * handlers to get values of the independent time variable consistent with integration direction.</p>
80       *
81       * @param state current value of the independent <i>time</i> variable, state vector
82       * and derivative at step end
83       * @param forward if true, propagation is forward
84       * @return indication of what the integrator should do next, this
85       * value must be one of {@link Action#STOP}, {@link Action#RESET_STATE},
86       * {@link Action#RESET_DERIVATIVES}, {@link Action#RESET_EVENTS}, or
87       * {@link Action#CONTINUE}
88       */
89      Action stepEndOccurred(ODEStateAndDerivative state, boolean forward);
90  
91      /** Reset the state prior to continue the integration.
92       *
93       * <p>This method is called after the step handler has returned and
94       * before the next step is started, but only when {@link
95       * ODEEventHandler#eventOccurred(ODEStateAndDerivative, ODEEventDetector, boolean)}
96       * has itself returned the {@link Action#RESET_STATE}
97       * indicator. It allows the user to reset the state vector for the
98       * next step, without perturbing the step handler of the finishing
99       * step.</p>
100      * <p>The default implementation returns its argument.</p>
101      * @param state current value of the independent <i>time</i> variable, state vector
102      * and derivative at step end
103      * @return reset state (note that it does not include the derivatives, they will
104      * be added automatically by the integrator afterwards)
105      */
106     default ODEState resetState(ODEStateAndDerivative state) {
107         return state;
108     }
109 
110 }