File kernel/src/simulationTools/EventsManager.hpp

Go to the source code of this file

Management of a Set (STL) of Events for the Simulation process.


typedef std::vector<SP::Event> EventsContainer

set of events, with an ordering based on Event time value (mpz_t) to compare Events


const unsigned long int GAPLIMIT_DEFAULT = 100
class EventsManager
#include <EventsManager.hpp>

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.


  • 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.


  • 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


virtual ~EventsManager()


SP::Event currentEvent() const

get the current event

a pointer to Event

double currentTimeStep()

Get current timestep.

the current timestep

void display() const

display EventsManager data

EventsContainer &events()

return all the events

a reference to the events set

unsigned long int getGapLimitEvents() const

Get the gap limit between two events.

the gap limit

double getTk()
double getTkp1() const

get time instant k+1 of the time discretisation

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

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

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

true if there are unprocessed events

void initialize(double T)

Initialize: just set the final time.


Event &insertEvent(int type, double time)

insert an event of a certain type.

The event is created on the fly.

a reference to the Event
  • 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

a reference to the Event

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

true if the simulation needs to be integrate, no otherwise

SP::Event nextEvent() const

get the next event to be processed.

a pointer to Event

double nextTime() const

get the time of next event, in double format

the time of the next events

void noSaveInMemory(const Simulation &sim)

Change TimeDiscretisationEvent to TimeDiscretisationEventNoSaveInMemory.

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

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.


void processEvents(Simulation &sim)

Process the next event, update the indexSets if necessary.


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

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

  • 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.

  • var: the new _GapLimit2Events

double startingTime() const

get the time of current event, in double format

the time of the last processed events

const TimeDiscretisation &timeDiscretisation() const

get TimeDiscretisation

the TimeDiscretisation in use for the time integration

void updateT(double T)

update final time

  • T: the new final time

Protected Functions


default constructor


serialization hooks

unsigned int insertEv(SP::Event e)

Insert an event in the event stack.

the position of the inserted event in the stack
  • e: the event to insert

void update(Simulation &sim)

Update the set of events.


Protected Attributes

SP::Event _eNonSmooth

Placeholder for the non smooth event.

EventsContainer _events

list of events The first element is the last processed event.

All the others are unprocessed events. This list is not fixed and can be updated at any time depending on the simulation, user add …

unsigned int _k

Current index (for time instants)

bool _NSeventInsteadOfTD

boolean to remember that a TD_EVENT has been deleted since a NS_EVENT was too close

double _T

End of the Simulation.

SP::TimeDiscretisation _td

TimeDiscretisation for the time integration.

Protected Static Attributes

unsigned long int _GapLimit2Events

unsigned long int variable to check if two events are too close