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