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