Event detection is executed at each integration time step. Only threshold functions of signal ports that may cause a state change are evaluated. Comparison is based on the sign (negative, 0, positive) of the signal port function value. The current value is stored and if a change of sign is detected, this is flagged. Note that a small tolerance around 0 is applied to handle numerical imprecision. Event detection may fail when the comparison function has an even number of roots in the one time interval of numerical integration. However, because the comparison function applies signals directly generated by the dynamic model behavior, it is likely that such an interval is too large for simulating the continuous dynamics to begin with.
When an event is detected, it is localized by a bisectional search.
This is a robust technique that finds the first time of occurrence of
an event within a prespecified margin [Cellier1979].
Next, a corresponding time step is made,
in Algorithm 1.
After this,
enabled state changes of all junctions are executed
and given the new hybrid bond graph structure,
the model variables are recomputed. If algebraic constraints between
state variables or between state variables and sources
become active, this may cause a discontinuous change in
state variable values.
The new model variable values may cause further events to occur and
corresponding junction state changes are executed. The state vector
is restored to its value that triggered the very first junction
state change and based on this state the new hybrid bond graph model
variable values are re-calculated. This iteration proceeds until no
further junction state changes occur,
in Algorithm 1.
If a change between the last mode of continuous behavior,
,
to a new mode,
,
has occurred,
the state vector
is updated. In case of modeled time scale abstraction,
this may again cause further
events to occur, and the event iteration starts anew. Once event iteration
has converged and updating the state vector causes no further junction
state changes, continuous simulation resumes.
Details of the hybrid system simulation algorithm are presented
elsewhere [Mosterman1997,Mosterman & Biswas1997b].