pathsim.events.condition module

class pathsim.events.condition.Condition(func_evt=None, func_act=None, tolerance=0.0001)[source]

Bases: Event

Subclass of base ‘Event’ that triggers if the event function evaluates to ‘True’, i.e. the condition is satisfied.

Monitors system state by evaluating an event function (func_evt) with boolean output. The event is considered detected when the event function evaluates to ‘True’ for the first time. Subsequent evaluations to ‘True’ are not considered unless the event is reset.

func_evt(time) -> event?

If an event is detected, some action (func_act) is performed on the system state.

func_evt(time) == True -> event -> func_act(time)

Note

Condition event functions evaluate to boolean and are therefore not smooth. Therefore uses bisection method for event location instead of secant method.

Example

Initialize a conditional event handler like this:

#define the event function
def evt(t):
    return t > 10

#define the action function (callback)
def act(t):
    #do something at event resolution
    pass

#initialize the event manager
E = Condition(
    func_evt=evt,  #the event function
    func_act=act   #the action function
    )
detect(t)[source]

Evaluate the event function and check if condition is satisfied.

The event function is not differentiable, so we use bisection to narrow down its location to some tolerance.

Parameters:

t (float) – evaluation time for detection

Returns:

  • detected (bool) – was an event detected?

  • close (bool) – are we close to the event?

  • ratio (float) – adjust timestep to locate event

resolve(t)[source]

Resolve the event and record the time (t) at which it occurs. Resolves event using the action function (func_act) if it is defined.

Deactivates the event tracking upon first resolution.

Parameters:

t (float) – evaluation time for event resolution