cosapp.multimode.event

Classes

Event(name, context[, desc, trigger, final])

Class for events, to be used as local variables

EventState()

Interface describing the inner state of an event

FilteredEvent(event, condition)

Inner state of an event triggered by another event, filtered by a Boolean condition.

MergedEvents(*events)

Inner state of an event triggered by the merging of of other, external events.

SynchronizedEvent(event)

Inner state of an event synchronized with another event.

UndefinedEvent()

Inner state of an undefined, never occurring event

ZeroCrossingEvent(event, zeroxing)

Inner state of an event triggered by a zero-crossing expression

class cosapp.multimode.event.Event(name: str, context: System, desc: str = '', trigger: str | ZeroCrossing | EventState | Event | None = None, final: bool = False)[source]

Bases: object

Class for events, to be used as local variables

cancel() None[source]

Cancels the event.

property context: System

context in which the event is defined

Type:

System

property contextual_name: str

Join context system name and event name.

If the event has no context, only its name is returned.

Type:

str

property desc: str

Event description

Type:

str

filter(condition: str) FilteredEvent[source]

Filters event with an additional boolean condition.

Parameters:

  • condition [str]:

    Evaluable boolean condition.

Returns:

  • trigger [FilteredEvent]:

    The filtered event state, to be used as trigger.

property final: bool
full_name(trim_root=False) str[source]

Returns full name up to root context.

Parameters:

trim_root (bool (optional, default False)) – Exclude root context name if True.

Returns:

The event full name

Return type:

str

initialize() None[source]

Initialize the event using current state of owner system.

property is_primitive: bool
static merge(*events: Event) MergedEvents[source]

Merges events into a trigger condition.

Parameters:

  • *events [Event]:

    Enumeration of events to be merged.

Returns:

  • trigger [MergedEvents]:

    The merged event state, to be used as trigger.

property name: str

Event name

Type:

str

classmethod name_check(name: str)[source]
property present: bool
reevaluate() None[source]

Reevaluates the current state of the event; used to update information about zero-crossing events after an integration time step was interrupted by the triggering of an event.

reset() None[source]

Resets the event.

step() bool[source]

bool : Indicates whether the event was just triggered.

Performs a step.

tick() None[source]

Ticks the event, and locks it if it is a primitive event that has just been triggered.

to_trigger() bool[source]

bool : Indicates whether the event has to be triggered in the next discrete step

property trigger: ZeroCrossing | EventState | Event
value() Any[source]

Returns the value associated with the event.

class cosapp.multimode.event.EventState[source]

Bases: ABC

Interface describing the inner state of an event

initialize() None[source]
property is_primitive: bool

True if event triggering condition is self-contained, False otherwise

Type:

bool

lock() None[source]
abstract must_emit() bool[source]
reevaluate() None[source]
reset() None[source]
tick() None[source]
to_emit() bool[source]
value() Any[source]

Returns value associated with event. By default, equivalent to must_emit().

class cosapp.multimode.event.FilteredEvent(event: Event, condition: str)[source]

Bases: EventState

Inner state of an event triggered by another event, filtered by a Boolean condition.

must_emit() bool[source]
class cosapp.multimode.event.MergedEvents(*events: Event)[source]

Bases: EventState

Inner state of an event triggered by the merging of of other, external events.

must_emit() bool[source]

Returns True if at least one event is present, False otherwise.

class cosapp.multimode.event.SynchronizedEvent(event: Event)[source]

Bases: EventState

Inner state of an event synchronized with another event.

must_emit() bool[source]
class cosapp.multimode.event.UndefinedEvent[source]

Bases: EventState

Inner state of an undefined, never occurring event

must_emit() bool[source]
class cosapp.multimode.event.ZeroCrossingEvent(event: Event, zeroxing: ZeroCrossing)[source]

Bases: EventState

Inner state of an event triggered by a zero-crossing expression

initialize() None[source]

Initialize the event using the current value of the zero-crossing function. If the value is nil, it is discarded, and the event is simply reset. This prevents the event from occurring at the beginning of a simulation.

property is_primitive: bool

True if event triggering condition is self-contained, False otherwise

Type:

bool

lock() None[source]

Locks the event

must_emit() bool[source]

Checks whether the event is triggered in the current discrete step.

reevaluate()[source]

Forces the reevaluation of the zero-crossing function

reset() None[source]

Reset the event, in such a way that the event will not occur after the next zero-crossing function evaluation.

tick()[source]

Performs a tick and checks whether the event can be unlocked

to_emit() bool[source]

Checks whether the event will have to be triggered in a new discrete step

value() float[source]

Evaluates and returns the zero-crossing function defining the event.

zero_detected(next_value) bool[source]

Is a zero detected between previous value and next_value?