Program listing for file kernel/src/simulationTools/Event.hpp

Program listing for file kernel/src/simulationTools/Event.hpp#

  1#ifndef Event_H
  2#define Event_H
  3
  4#include <cmath>
  5#include <gmp.h>
  6#include <cstddef>
  7#include "SiconosConst.hpp"
  8#include "SimulationTypeDef.hpp"
  9#include "SiconosPointers.hpp"
 10#include "SiconosSerialization.hpp"
 11
 12
 13#if defined(_MSC_VER) && _MSC_VER < 1800
 14extern "C" double rint(double x);
 15#endif
 16
 17
 18
 19const double DEFAULT_TICK = 1e-16;
 20
 21
 22
 23class Event
 24{
 25protected:
 26
 27  ACCEPT_SERIALIZATION(Event);
 28
 29
 30  mpz_t _timeOfEvent;
 31
 32
 33  mpz_t _tickIncrement;
 34
 35
 36  int _type;
 37
 38
 39  double _dTime;
 40
 41
 42  static double _tick;
 43
 44
 45  static bool _eventCreated;
 46
 47
 48  unsigned int _k;
 49
 50
 51  SP::TimeDiscretisation _td;
 52
 53
 54  bool _reschedule;
 55
 56
 57  Event(): _type(0), _dTime(0.0), _k(0), _reschedule(false)
 58  {
 59    mpz_init(_timeOfEvent);
 60    mpz_init(_tickIncrement);
 61  };
 62
 63
 64
 65
 66
 67
 68
 69public:
 70
 71
 72  Event(double time, int newType = 0, bool reschedule = false);
 73
 74
 75  virtual ~Event();
 76
 77
 78  inline double getTick() const
 79  {
 80    return _tick;
 81  };
 82
 83
 84  static void setTick(double newTick);
 85
 86
 87  inline const mpz_t * getTimeOfEvent() const
 88  {
 89    return &_timeOfEvent ;
 90  };
 91
 92
 93  inline double getDoubleTimeOfEvent() const
 94  {
 95    return _dTime;
 96  }
 97
 98  inline void incrementTime(unsigned int step = 1)
 99  {
100    for (unsigned int i = 0; i < step; i++)
101      mpz_add(_timeOfEvent, _timeOfEvent, _tickIncrement);
102    _dTime = mpz_get_d(_timeOfEvent)*_tick;
103  }
104
105
106  inline void setTime(double time)
107  {
108    _dTime = time;
109    mpz_set_d(_timeOfEvent, rint(_dTime / _tick));
110  };
111
112
113  inline int getType() const
114  {
115    return _type ;
116  };
117
118
119  inline void setType(int newType)
120  {
121    _type = newType;
122  };
123
124
125  inline void setK(unsigned int newK) { _k = newK; };
126
127
128  void setTimeDiscretisation(SP::TimeDiscretisation td);
129
130
131  inline SP::TimeDiscretisation getTimeDiscretisation() const { return _td; };
132
133
134  void display() const ;
135
136
137  virtual void process(Simulation& sim) = 0;
138
139
140  virtual void update(unsigned int k = 0);
141
142  inline bool reschedule() const { return _reschedule; };
143};
144#endif