Program listing for file kernel/src/simulationTools/EventsManager.hpp#
Return to documentation for this file
1#ifndef EventsManager_H
2#define EventsManager_H
3
4#include <vector>
5#include <limits>
6#include "SiconosFwd.hpp"
7#include "TimeDiscretisation.hpp"
8
9const unsigned long int GAPLIMIT_DEFAULT = 100;
10
11
12typedef std::vector<SP::Event> EventsContainer;
13
14
15class EventsManager
16{
17protected:
18
19 ACCEPT_SERIALIZATION(EventsManager);
20
21
22 EventsContainer _events;
23
24
25 SP::Event _eNonSmooth;
26
27
28 unsigned int _k;
29
30
31 SP::TimeDiscretisation _td;
32
33
34 double _T;
35
36
37 static unsigned long int _GapLimit2Events;
38
39
40 bool _NSeventInsteadOfTD;
41
42
43 unsigned int insertEv(SP::Event e);
44
45
46 void update(Simulation& sim);
47
48
49 EventsManager() = default;
50
51public:
52
53
54 EventsManager(SP::TimeDiscretisation td);
55
56
57 virtual ~EventsManager() {};
58
59
60 void initialize(double T);
61
62
63 inline void setGapLimitEvents(unsigned long int var)
64 {
65 _GapLimit2Events = var;
66 };
67
68
69 inline unsigned long int getGapLimitEvents() const
70 {
71 return _GapLimit2Events;
72 };
73
74
75 void noSaveInMemory(const Simulation& sim);
76
77
78 inline SP::Event currentEvent() const
79 {
80 return _events[0];
81 };
82
83
84 inline SP::Event nextEvent() const
85 {
86 return _events[1];
87 };
88
89
90 inline EventsContainer& events()
91 {
92 return _events;
93 };
94
95
96 inline bool hasNextEvent() const
97 {
98 return _events.size() > 1;
99 };
100
101
102 double startingTime() const ;
103
104
105 double nextTime() const ;
106
107
108 bool needsIntegration() const;
109
110
111 void display() const ;
112
113
114 void scheduleNonSmoothEvent(Simulation& sim, double time, bool yes_update = true);
115
116
117 void processEvents(Simulation& sim);
118
119
120 void preUpdate(Simulation& sim);
121
122
123 Event& insertEvent(int type, double time);
124
125
126 Event& insertEvent(int type, SP::TimeDiscretisation td);
127
128 double getTk()
129 {
130 return _td->getTk(_k);
131 }
132
133
134 inline double getTkp1() const
135 {
136 double tkp1 = _td->getTk(_k+1);
137 if (tkp1 <= _T + 100.0*std::numeric_limits<double>::epsilon())
138 return tkp1;
139 else
140 return std::numeric_limits<double>::quiet_NaN();
141 };
142
143
144 inline double getTkp2() const
145 {
146 double tkp2 = _td->getTk(_k+2);
147 if (tkp2 <= _T + 100.0*std::numeric_limits<double>::epsilon())
148 return tkp2;
149 else
150 return std::numeric_limits<double>::quiet_NaN();
151 };
152
153
154 inline double getTkp3() const
155 {
156 double tkp3 = _td->getTk(_k+3);
157 if (tkp3 <= _T + 100.0*std::numeric_limits<double>::epsilon())
158 return tkp3;
159 else
160 return std::numeric_limits<double>::quiet_NaN();
161 };
162
163
164 inline double currentTimeStep()
165 {
166 return _td->currentTimeStep(_k);
167 }
168
169
170 inline const TimeDiscretisation& timeDiscretisation() const { return *_td;};
171
172
173 inline void updateT(double T) { _T = T; };
174};
175
176#endif