# Class EventsManager¶

class EventsManager

Tools to handle a set of Events for the Simulation.

The EventsManager handles a set of events (from user time-discretisation, sensors, non-smooth …), and is supposed to provide to the simulation the values of “current” and “next” events to define the time-integration interval.

Events:

• currentEvent: starting time for integration. Initialized with t0 of the simulation time-discretisation.

• ETD: corresponds to the instant t[k+1] of the Simulation (user) TimeDiscretisation.

• ENonSmooth: for EventDriven simulation only. Present only if one or more non-smooth events have been detected between currentEvent and the next event.

• Sensor or Actuators Events. To each Sensor or Actuator declared in the ControlManager, corresponds an Event in the manager. When this event is processed, its time value is increased to next instant in the time-discretisation of the sensor/actuator.

Examples:

• for a TimeStepping, with one Sensor, the EventsManager looks like:

{currentEvent(tk), ESensor(tsensor), ETD(tk+1)}

• for an EventDriven, with one actuator, an non-smooth event detected at time tns:

{currentEvent(tk), EActuator(tact), ENonSmooth(tns), ETD(tk+1)}.

After each process, the time values of each event are updated and nextEvent points to the first event after currentEvent.

Public Functions

EventsManager(SP::TimeDiscretisation td)

default constructor

Parameters

virtual ~EventsManager()

destructor

SP::Event currentEvent() const

get the current event

Return

a pointer to Event

double currentTimeStep()

Get current timestep.

Return

the current timestep

void display() const

display EventsManager data

EventsContainer &events()

return all the events

Return

a reference to the events set

unsigned long int getGapLimitEvents() const

Get the gap limit between two events.

Return

the gap limit

double getTkp1() const

get time instant k+1 of the time discretisation

Return

a double. If the simulation is near the end (t_{k+1} >= T), it returns NaN.

double getTkp2() const

get time instant k+2 of the time discretisation

Return

a double. If the simulation is near the end (t_{k+2} >= T), it returns NaN.

double getTkp3() const

get time instant k+3 of the time discretisation.

It is used when we have to reschedule a TD Event in scheduleNonSmoothEvent

Return

a double. If the simulation is near the end (t_{k+3} >= T), it returns NaN.

bool hasNextEvent() const

check if there are some unprocessed events

Return

true if there are unprocessed events

void initialize(double T)

Initialize: just set the final time.

Parameters
• T: the final time of the Simulation

Event &insertEvent(int type, double time)

insert an event of a certain type.

The event is created on the fly.

Return

a reference to the Event

Parameters
• type: the type of the event

• time: the time of the event

Event &insertEvent(int type, SP::TimeDiscretisation td)

insert an event of a certain type.

The event is created on the fly, and the SP::TimeDiscretisation given in argument is stored inside

Return

a reference to the Event

Parameters

bool needsIntegration() const

is an integration step required ? The current event and the next one may have the same time instant in which case no integration as to be performed

Return

true if the simulation needs to be integrate, no otherwise

SP::Event nextEvent() const

get the next event to be processed.

Return

a pointer to Event

double nextTime() const

get the time of next event, in double format

Return

the time of the next events

void noSaveInMemory(const Simulation &sim)

Warning

use this at your own risk, many integrators needs previous values to integrate properly

Parameters

void preUpdate(Simulation &sim)

Function to be called once after initialization.

It is used to process NonSmoothEvents at the beginning of the Simulation, if there is any.

Parameters

void processEvents(Simulation &sim)

Process the next event, update the indexSets if necessary.

Parameters

void scheduleNonSmoothEvent(Simulation &sim, double time, bool yes_update = true)

add a new Event in the allEvents list and update nextEvent value

Parameters
• sim: the simulation that owns this EventsManager

• time: the time (double format) of occurence of the event

• yes_update: indicator to update or not the next event (default value is true)

void setGapLimitEvents(unsigned long int var)

Set the gap limit between two events.

Parameters
• var: the new _GapLimit2Events

double startingTime() const

get the time of current event, in double format

Return

the time of the last processed events

const TimeDiscretisation &timeDiscretisation() const

Return

the TimeDiscretisation in use for the time integration

void updateT(double T)

update final time

Parameters
• T: the new final time