Class AbstractODEDetector<T extends AbstractODEDetector<T>>
- java.lang.Object
-
- org.hipparchus.ode.events.AbstractODEDetector<T>
-
- Type Parameters:
T
- type of the detector
- All Implemented Interfaces:
ODEEventDetector
- Direct Known Subclasses:
EventSlopeFilter
public abstract class AbstractODEDetector<T extends AbstractODEDetector<T>> extends Object implements ODEEventDetector
Base class for #@linkODEEventDetector
.- Since:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_ITER
Default maximum number of iterations in the event time search.static double
DEFAULT_MAXCHECK
Default maximum checking interval (s).static double
DEFAULT_THRESHOLD
Default convergence threshold (s).
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractODEDetector(AdaptableInterval maxCheck, int maxIter, BracketedUnivariateSolver<UnivariateFunction> solver, ODEEventHandler handler)
Build a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract T
create(AdaptableInterval newMaxCheck, int newmaxIter, BracketedUnivariateSolver<UnivariateFunction> newSolver, ODEEventHandler newHandler)
Build a new instance.abstract double
g(ODEStateAndDerivative s)
Compute the value of the switching function.ODEEventHandler
getHandler()
Get the underlying event handler.AdaptableInterval
getMaxCheckInterval()
Get the maximal time interval between events handler checks.int
getMaxIterationCount()
Get the upper limit in the iteration count for event localization.BracketedUnivariateSolver<UnivariateFunction>
getSolver()
Get the root-finding algorithm to use to detect state events.void
init(ODEStateAndDerivative s0, double t)
Initialize event handler at the start of an ODE integration.boolean
isForward()
Check if the current propagation is forward or backward.T
withHandler(ODEEventHandler newHandler)
Setup the event handler to call at event occurrences.T
withMaxCheck(double newMaxCheck)
Setup the maximum checking interval.T
withMaxCheck(AdaptableInterval newMaxCheck)
Setup the maximum checking interval.T
withMaxIter(int newMaxIter)
Setup the maximum number of iterations in the event time search.T
withSolver(BracketedUnivariateSolver<UnivariateFunction> newSolver)
Setup the root-finding algorithm to use to detect state events.T
withThreshold(double newThreshold)
Setup the convergence threshold.
-
-
-
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
-
AbstractODEDetector
protected AbstractODEDetector(AdaptableInterval maxCheck, int maxIter, BracketedUnivariateSolver<UnivariateFunction> solver, ODEEventHandler handler)
Build a new instance.- Parameters:
maxCheck
- maximum checking interval, must be strictly positive (s)maxIter
- maximum number of iterations in the event time searchsolver
- root-finding algorithm to use to detect state eventshandler
- event handler to call at event occurrences
-
-
Method Detail
-
init
public void init(ODEStateAndDerivative s0, double 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 interfaceODEEventDetector
- Parameters:
s0
- initial time, state vector and derivativet
- target time for the integration
-
g
public abstract double g(ODEStateAndDerivative 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 for the integrator to detect an event the sign of the switching function must have opposite signs just before and after the event. If this consistency is not preserved the integrator may not detect any events.
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 timestate.getTime()
. Wheng(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 eventg(state)
was decreasing from positive values to 0, and after the eventg(state)
would be increasing from 0 to positive values again. Consistency is broken here! The solution here is to haveg(state) = sign * h(state)
, where sign is a variable with initial value set to+1
. Each timeeventOccurred
is called,sign
is reset to-sign
. This allows theg(state)
function to remain continuous (and even smooth) even across events, despiteh(state)
is not. Basically, the event is used to foldh(state)
at bounce points, andsign
is used to unfold it back, so the solvers sees ag(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 theeventOccurred
method of any other event handler in the same integrator returnsAction.RESET_EVENTS
,Action.RESET_DERIVATIVES
, orAction.RESET_STATE
.- Specified by:
g
in interfaceODEEventDetector
- Parameters:
s
- current value of the independent time variable, state vector and derivative- Returns:
- value of the g switching function
- See Also:
org.hipparchus.ode.events
-
getMaxCheckInterval
public AdaptableInterval getMaxCheckInterval()
Get the maximal time interval between events handler checks.- Specified by:
getMaxCheckInterval
in interfaceODEEventDetector
- Returns:
- maximal time interval between events handler checks
-
getMaxIterationCount
public int getMaxIterationCount()
Get the upper limit in the iteration count for event localization.- Specified by:
getMaxIterationCount
in interfaceODEEventDetector
- Returns:
- upper limit in the iteration count for event localization
-
getSolver
public BracketedUnivariateSolver<UnivariateFunction> getSolver()
Get the root-finding algorithm to use to detect state events.- Specified by:
getSolver
in interfaceODEEventDetector
- Returns:
- root-finding algorithm to use to detect state events
-
withMaxCheck
public T withMaxCheck(double newMaxCheck)
Setup the maximum checking interval.This will override a maximum checking interval if it has been configured previously.
- Parameters:
newMaxCheck
- maximum checking interval- Returns:
- a new detector with updated configuration (the instance is not changed)
-
withMaxCheck
public T withMaxCheck(AdaptableInterval newMaxCheck)
Setup the maximum checking interval.This will override a maximum checking interval if it has been configured previously.
- Parameters:
newMaxCheck
- maximum checking interval- 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(double newThreshold)
Setup the convergence threshold.This is equivalent to call
withSolver(new BracketingNthOrderBrentSolver(0, newThreshold, 0, 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(BracketedUnivariateSolver)
-
withSolver
public T withSolver(BracketedUnivariateSolver<UnivariateFunction> 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(double)
-
withHandler
public T withHandler(ODEEventHandler 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)
-
getHandler
public ODEEventHandler getHandler()
Get the underlying event handler.- Specified by:
getHandler
in interfaceODEEventDetector
- Returns:
- underlying event handler
-
create
protected abstract T create(AdaptableInterval newMaxCheck, int newmaxIter, BracketedUnivariateSolver<UnivariateFunction> newSolver, ODEEventHandler newHandler)
Build a new instance.- Parameters:
newMaxCheck
- maximum checking intervalnewmaxIter
- maximum number of iterations in the event time searchnewSolver
- root-finding algorithm to use to detect state eventsnewHandler
- 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
-
-