Class AbstractFieldODEDetector<T extends AbstractFieldODEDetector<T,​E>,​E extends CalculusFieldElement<E>>

    • Field Detail

      • DEFAULT_MAXCHECK

        public static final double DEFAULT_MAXCHECK
        Default maximum checking interval (s).
        See Also:
        Constant Field Values
      • DEFAULT_THRESHOLD

        public static final double DEFAULT_THRESHOLD
        Default convergence threshold (s).
        See Also:
        Constant Field Values
      • DEFAULT_MAX_ITER

        public static final int DEFAULT_MAX_ITER
        Default maximum number of iterations in the event time search.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractFieldODEDetector

        protected AbstractFieldODEDetector​(FieldAdaptableInterval<E> maxCheck,
                                           int maxIter,
                                           BracketedRealFieldUnivariateSolver<E> solver,
                                           FieldODEEventHandler<E> handler)
        Build a new instance.
        Parameters:
        maxCheck - maximum checking interval, must be strictly positive (s)
        maxIter - maximum number of iterations in the event time search
        solver - root-finding algorithm to use to detect state events
        handler - event handler to call at event occurrences
    • Method Detail

      • init

        public void init​(FieldODEStateAndDerivative<E> s0,
                         E t)
        Initialize event handler at the start of an ODE integration.

        This method is called once at the start of the integration. It may be used by the event handler to initialize some internal data if needed.

        The default implementation does nothing

        This implementation sets the direction of integration and initializes the event handler. If a subclass overrides this method it should call super.init(s0, t).

        Specified by:
        init in interface FieldODEEventDetector<T extends AbstractFieldODEDetector<T,​E>>
        Parameters:
        s0 - initial time, state vector and derivative
        t - target time for the integration
      • g

        public abstract E g​(FieldODEStateAndDerivative<E> s)
        Compute the value of the switching function.

        The discrete events are generated when the sign of this switching function changes. The integrator will take care to change the stepsize in such a way these events occur exactly at step boundaries. The switching function must be continuous in its roots neighborhood (but not necessarily smooth), as the integrator will need to find its roots to locate precisely the events.

        Also note that the integrator expect that once an event has occurred, the sign of the switching function at the start of the next step (i.e. just after the event) is the opposite of the sign just before the event. This consistency between the steps must be preserved, otherwise exceptions related to root not being bracketed will occur.

        This need for consistency is sometimes tricky to achieve. A typical example is using an event to model a ball bouncing on the floor. The first idea to represent this would be to have g(state) = h(state) where h is the height above the floor at time state.getTime(). When g(state) reaches 0, the ball is on the floor, so it should bounce and the typical way to do this is to reverse its vertical velocity. However, this would mean that before the event g(state) was decreasing from positive values to 0, and after the event g(state) would be increasing from 0 to positive values again. Consistency is broken here! The solution here is to have g(state) = sign * h(state), where sign is a variable with initial value set to +1. Each time eventOccurred method is called, sign is reset to -sign. This allows the g(state) function to remain continuous (and even smooth) even across events, despite h(state) is not. Basically, the event is used to fold h(state) at bounce points, and sign is used to unfold it back, so the solvers sees a g(state) function which behaves smoothly even across events.

        This method is idempotent, that is calling this multiple times with the same state will result in the same value, with two exceptions. First, the definition of the g function may change when an event occurs on the handler, as in the above example. Second, the definition of the g function may change when the event occurs method of any other event handler in the same integrator returns Action.RESET_EVENTS, Action.RESET_DERIVATIVES, or Action.RESET_STATE.

        Specified by:
        g in interface FieldODEEventDetector<T extends AbstractFieldODEDetector<T,​E>>
        Parameters:
        s - current value of the independent time variable, state vector and derivative
        Returns:
        value of the g switching function
      • withMaxCheck

        public T withMaxCheck​(E newMaxCheck)
        Setup the maximum checking interval.

        This will override a maximum checking interval if it has been configured previously.

        Parameters:
        newMaxCheck - maximum checking interval (s)
        Returns:
        a new detector with updated configuration (the instance is not changed)
      • withMaxCheck

        public T withMaxCheck​(FieldAdaptableInterval<E> newMaxCheck)
        Setup the maximum checking interval.

        This will override a maximum checking interval if it has been configured previously.

        Parameters:
        newMaxCheck - maximum checking interval (s)
        Returns:
        a new detector with updated configuration (the instance is not changed)
        Since:
        3.0
      • withMaxIter

        public T withMaxIter​(int newMaxIter)
        Setup the maximum number of iterations in the event time search.

        This will override a number of iterations if it has been configured previously.

        Parameters:
        newMaxIter - maximum number of iterations in the event time search
        Returns:
        a new detector with updated configuration (the instance is not changed)
      • withThreshold

        public T withThreshold​(E newThreshold)
        Setup the convergence threshold.

        This is equivalent to call withSolver(new FieldBracketingNthOrderBrentSolver<>(zero, newThreshold, zero, 5), so it will override a solver if one has been configured previously.

        Parameters:
        newThreshold - convergence threshold
        Returns:
        a new detector with updated configuration (the instance is not changed)
        See Also:
        withSolver(BracketedRealFieldUnivariateSolver)
      • withSolver

        public T withSolver​(BracketedRealFieldUnivariateSolver<E> newSolver)
        Setup the root-finding algorithm to use to detect state events.

        This will override a solver if it has been configured previously.

        Parameters:
        newSolver - root-finding algorithm to use to detect state events
        Returns:
        a new detector with updated configuration (the instance is not changed)
        See Also:
        withThreshold(CalculusFieldElement)
      • withHandler

        public T withHandler​(FieldODEEventHandler<E> newHandler)
        Setup the event handler to call at event occurrences.

        This will override a handler if it has been configured previously.

        Parameters:
        newHandler - event handler to call at event occurrences
        Returns:
        a new detector with updated configuration (the instance is not changed)
      • create

        protected abstract T create​(FieldAdaptableInterval<E> newMaxCheck,
                                    int newMaxIter,
                                    BracketedRealFieldUnivariateSolver<E> newSolver,
                                    FieldODEEventHandler<E> newHandler)
        Build a new instance.
        Parameters:
        newMaxCheck - maximum checking interval
        newMaxIter - maximum number of iterations in the event time search
        newSolver - root-finding algorithm to use to detect state events
        newHandler - event handler to call at event occurrences
        Returns:
        a new instance of the appropriate sub-type
      • isForward

        public boolean isForward()
        Check if the current propagation is forward or backward.
        Returns:
        true if the current propagation is forward