Event Base¶
- class pathsim.events._event.Event(func_evt=None, func_act=None, tolerance=0.0001)[source]¶
Bases:
objectThis is the base class of the event handling system.
Monitors system state by evaluating an event function (func_evt) with scalar output.
func_evt(time) -> event?
If an event is detected, some action (func_act) is performed on the states of the blocks.
func_evt(time) == True -> event -> func_act(time)
The methods are structured such that event detection can be separated from event resolution. This is required for adaptive timestep solvers to approach the event and only resolve it when the event tolerance (‘tolerance’) is satisfied.
If no action function (func_act) is specified, the event will only be detected but other than that, no action will be triggered. For general state monitoring.
- Parameters:
func_evt (callable) – event function, where zeros are events
func_act (callable) – action function for event resolution
tolerance (float) – tolerance to check if detection is close to actual event
- _history¶
history of event function evaluation after buffering
- reset()[source]¶
Reset the recorded event times. Resetting the history is not required because of the ‘buffer’ method. Reactivates event tracking.
- buffer(t)[source]¶
Buffer the event function evaluation before the timestep is taken and the evaluation time.
- Parameters:
t (float) – evaluation time for buffering history
- estimate(t)[source]¶
Estimate the time of the next event, based on history or internal schedule.
This improves simulation performance by estimating events before the simulation step such that fewer steps have to be rejected for event location.
- detect(t)[source]¶
Evaluate the event function and decide if an event has occured. Can also use the history of the event function evaluation from before the timestep.
Notes
This does nothing and needs to be implemented for specific events!!!
- Parameters:
t (float) – evaluation time for detection
- Returns:
detected (bool) – was an event detected?
close (bool) – are we close to the event?
ratio (float) – interpolated event location as ratio of timestep