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.

Typedefs

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

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

Variables

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

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.

Main functions

  • initialize(): process all events which have the same time as currentEvent

  • processEvents(): process all events simultaneous to nextEvent, increment them to next step, update index sets, increment currentEvent.

Public Functions

EventsManager(SP::TimeDiscretisation td)

constructor

Parameters

td – the TimeDiscretisation used in the Simulation

inline virtual ~EventsManager()

destructor

void initialize(double T)

Initialize: just set the final time.

Parameters

T – the final time of the Simulation

inline void setGapLimitEvents(unsigned long int var)

Set the gap limit between two events.

Parameters

var – the new _GapLimit2Events

inline unsigned long int getGapLimitEvents() const

Get the gap limit between two events.

Returns

the gap limit

void noSaveInMemory(const Simulation &sim)

Change TimeDiscretisationEvent to TimeDiscretisationEventNoSaveInMemory.

Warning

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

Parameters

sim – the Simulation that owns this EventsManager

inline SP::Event currentEvent() const

get the current event

Returns

a pointer to Event

inline SP::Event nextEvent() const

get the next event to be processed.

Returns

a pointer to Event

inline EventsContainer &events()

return all the events

Returns

a reference to the events set

inline bool hasNextEvent() const

check if there are some unprocessed events

Returns

true if there are unprocessed events

double startingTime() const

get the time of current event, in double format

Returns

the time of the last processed events

double nextTime() const

get the time of next event, in double format

Returns

the time of the next events

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

Returns

true if the simulation needs to be integrate, no otherwise

void display() const

display EventsManager data

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 processEvents(Simulation &sim)

Process the next event, update the indexSets if necessary.

Parameters

sim – the simulation that owns this EventsManager

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

sim – the simulation that owns this EventsManager

Event &insertEvent(int type, double time)

insert an event of a certain type.

The event is created on the fly.

Parameters
  • type – the type of the event

  • time – the time of the event

Returns

a reference to 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

Parameters
Returns

a reference to the Event

inline double getTk()
inline double getTkp1() const

get time instant k+1 of the time discretisation

Returns

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

inline double getTkp2() const

get time instant k+2 of the time discretisation

Returns

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

inline 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

Returns

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

inline double currentTimeStep()

Get current timestep.

Returns

the current timestep

inline const TimeDiscretisation &timeDiscretisation() const

get TimeDiscretisation

Returns

the TimeDiscretisation in use for the time integration

inline void updateT(double T)

update final time

Parameters

T – the new final time

Protected Functions

ACCEPT_SERIALIZATION(EventsManager)
unsigned int insertEv(SP::Event e)

Insert an event in the event stack.

Parameters

e – the event to insert

Returns

the position of the inserted event in the stack

void update(Simulation &sim)

Update the set of events.

Parameters

sim – the Simulation using this EventsManager

EventsManager() = default

default constructor

Protected Attributes

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 …

SP::Event _eNonSmooth

Placeholder for the non smooth event.

unsigned int _k

Current index (for time instants)

SP::TimeDiscretisation _td

TimeDiscretisation for the time integration.

double _T

End of the Simulation.

bool _NSeventInsteadOfTD

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

Protected Static Attributes

static unsigned long int _GapLimit2Events

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