General events are defined implicitly
by a g function crossing
zero. This function needs to be continuous in the event neighborhood,
and its sign must remain consistent between events. This implies that
during an ODE integration, events triggered are alternately events
for which the function increases from negative to positive values,
and events for which the function decreases from positive to
negative values.
Sometimes, users are only interested in one type of event (say increasing events for example) and not in the other type. In these cases, looking precisely for all events location and triggering events that will later be ignored is a waste of computing time.
Users can wrap a regular event handler in
an instance of this class and provide this wrapping instance to
the ODE solver
in order to avoid wasting time looking for uninteresting events.
The wrapper will intercept the calls to the g function and to the eventOccurred method in order to ignore uninteresting events. The
wrapped regular event handler will the see only
the interesting events, i.e. either only increasing events or
decreasing events. the number of calls to the g function will also be reduced.
| Modifier and Type | Field and Description |
|---|---|
| private double | extremeT
Extreme time encountered so far. |
| private final FilterType | filter
Filter to use. |
| private boolean | forward
Indicator for forward integration. |
| private static final int | HISTORY_SIZE
Number of past transformers updates stored. |
| private final EventHandler | rawHandler
Wrapped event handler. |
| private final Transformer[] | transformers
Transformers of the g function. |
| private final double[] | updates
Update time of the transformers. |
| Access | Constructor and Description |
|---|---|
| public | EventFilter(final EventHandler
event handler to wrap rawHandler, final FilterType filter to use filter)Wrap an |
| Modifier and Type | Method and Description |
|---|---|
| public EventHandler. | eventOccurred(double
current value of the independent time variable t, double[] array containing the current value of the state vector y, boolean if true, the value of the switching function increases
when times increases around event (note that increase is measured with respect
to physical time, not with respect to integration which may go backward in time) increasing)Implements org. Handle an event and choose what to do next. |
| public double | g(double
current value of the independent time variable t, double[] array containing the current value of the state vector y)Implements org. Compute the value of the switching function. |
| public void | init(double
start value of the independent time variable t0, double[] array containing the start value of the state vector y0, double target time for the integration t)Implements org. Initialize event handler at the start of an ODE integration. |
| public void | resetState(double
current value of the independent time variable t, double[] array containing the current value of the state vector
the new state should be put in the same array y)Implements org. Reset the state prior to continue the integration. |
| extremeT | back to summary |
|---|---|
| private double extremeT Extreme time encountered so far. | |
| filter | back to summary |
|---|---|
| private final FilterType filter Filter to use. | |
| forward | back to summary |
|---|---|
| private boolean forward Indicator for forward integration. | |
| HISTORY_SIZE | back to summary |
|---|---|
| private static final int HISTORY_SIZE Number of past transformers updates stored. | |
| rawHandler | back to summary |
|---|---|
| private final EventHandler rawHandler Wrapped event handler. | |
| transformers | back to summary |
|---|---|
| private final Transformer[] transformers Transformers of the g function. | |
| updates | back to summary |
|---|---|
| private final double[] updates Update time of the transformers. | |
| EventFilter | back to summary |
|---|---|
| public EventFilter(final EventHandler rawHandler, final FilterType filter) Wrap an
| |
| eventOccurred | back to summary |
|---|---|
| public EventHandler. Implements org. Doc from org. Handle an event and choose what to do next. This method is called when the integrator has accepted a step
ending exactly on a sign change of the function, just before
the step handler itself is called (see below for scheduling). It
allows the user to update his internal data to acknowledge the fact
the event has been handled (for example setting a flag in the
The scheduling between this method and the
| |
| g | back to summary |
|---|---|
| public double g(double t, double[] y) Implements org. Doc from org. 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 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
| |
| init | back to summary |
|---|---|
| public void init(double t0, double[] y0, double t) Implements org. Doc from org. 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.
| |
| resetState | back to summary |
|---|---|
| public void resetState(double t, double[] y) Implements org. Doc from org. Reset the state prior to continue the integration. This method is called after the step handler has returned and
before the next step is started, but only when
| |