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.exception.MathIllegalArgumentException;
22  import org.hipparchus.exception.MathIllegalStateException;
23  import org.hipparchus.ode.FieldODEStateAndDerivative;
24  import org.hipparchus.ode.sampling.FieldODEStateInterpolator;
25  
26  /** This interface handles the state for either one {@link FieldODEEventHandler
27   * event handler} or one {@link FieldODEStepEndHandler step end handler}
28   * during integration steps.
29   * @since 3.0
30   * @param <T> the type of the field elements
31   */
32  public interface FieldEventState<T extends CalculusFieldElement<T>> {
33  
34      /** Initialize handler at the start of an integration.
35       * <p>
36       * This method is called once at the start of the integration. It
37       * may be used by the event handler to initialize some internal data
38       * if needed.
39       * </p>
40       * @param s0 initial state
41       * @param t target time for the integration
42       *
43       */
44      void init(FieldODEStateAndDerivative<T> s0, T t);
45  
46      /** Get the occurrence time of the event triggered in the current step.
47       * @return occurrence time of the event triggered in the current
48       * step or infinity if no events are triggered
49       */
50      T getEventTime();
51  
52      /** Evaluate the impact of the proposed step on the event handler.
53       * @param interpolator step interpolator for the proposed step
54       * @return true if the event handler triggers an event before
55       * the end of the proposed step
56       * @exception MathIllegalStateException if the interpolator throws one because
57       * the number of functions evaluations is exceeded
58       * @exception MathIllegalArgumentException if the event cannot be bracketed
59       */
60      boolean evaluateStep(FieldODEStateInterpolator<T> interpolator)
61          throws MathIllegalArgumentException, MathIllegalStateException;
62  
63      /**
64       * Notify the user's listener of the event. The event occurs wholly within this method
65       * call including a call to {@link FieldODEEventHandler#resetState(FieldODEEventDetector,
66       * FieldODEStateAndDerivative)} if necessary.
67       *
68       * @param state the state at the time of the event. This must be at the same time as
69       *              the current value of {@link #getEventTime()}.
70       * @return the user's requested action and the new state if the action is {@link
71       * Action#RESET_STATE}. Otherwise the new state is {@code state}. The stop time
72       * indicates what time propagation should stop if the action is {@link Action#STOP}.
73       * This guarantees the integration will stop on or after the root, so that integration
74       * may be restarted safely.
75       */
76      FieldEventOccurrence<T> doEvent(FieldODEStateAndDerivative<T> state);
77  
78  }