.Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
EventCalendar.h
1 #ifndef __EVENT_CALENDAR_EVENT_CALENDAR_H__
2 #define __EVENT_CALENDAR_EVENT_CALENDAR_H__
3 
4 #include <vector>
5 #include "EventType.h"
6 #include "../Constants/Constants.h"
7 
8 namespace MDSimulation
9 {
36  {
37  private:
38 
44  struct CalendarNode
45  {
47  CalendarNode* Parent;
48  CalendarNode* Left;
49  CalendarNode* Right;
50  CalendarNode* CircleAL;
51  CalendarNode* CircleAR;
52  CalendarNode* CircleBL;
53  CalendarNode* CircleBR;
56  double Time;
57  int ObjectA;
58  int ObjectB;
59  EventType Type;
63  CalendarNode();
64  CalendarNode(const CalendarNode& other);
65 
67  void Insert(CalendarNode* ins);
68 
82  CalendarNode* Delete();
83 
88  std::pair<unsigned long, unsigned long> MinMax() const;
89  };
90 
91  std::vector<CalendarNode> ListAnchor; // Entry point for circularly linked lists
92 
93  CalendarNode* FreeList;
94  CalendarNode* Root;
96  bool HasStepped;
98  double CurrentEventTime;
99  int CurrentEventObjectA;
100  int CurrentEventObjectB;
101  EventType CurrentEventType;
104  CalendarNode* AllocateNode();
105 
112  void FreeNode(CalendarNode* node);
113 
121  CalendarNode* SafeDelete(CalendarNode* node);
122 
128  bool NodeInTree(CalendarNode const * const node);
129 
130  public:
131 
138  EventCalendar(const unsigned particleCount);
139 
141  ~EventCalendar();
142 
144  void ScheduleEvent(const double time, const EventType type,
145  const int idA=Constants::NULL_PARTICLE,
146  const int idB=Constants::NULL_PARTICLE);
147 
152  void NextEvent();
153 
159  bool HasMoreEvents();
160 
166  void ClearCalendar();
167 
171  double GetCurrentTime() const;
172 
176  int GetCurrentObjectA() const;
177 
181  int GetCurrentObjectB() const;
182 
187  double BalanceRatio() const;
188 
193  };
194 }
195 
196 #endif /* __EVENT_CALENDAR_H__ */
197 
int GetCurrentObjectB() const
Definition: EventCalendar.cpp:548
void NextEvent()
Advance the calendar one step and put the next event into the current event place holders...
Definition: EventCalendar.cpp:418
Definition: EventCalendar.h:35
EventType
Enumeration of the various event types in the system.
Definition: EventType.h:28
EventType GetCurrentEventType() const
Definition: EventCalendar.cpp:555
double BalanceRatio() const
Computes the ratio of the longest path to a leaf over the shortest path to a leaf.
Definition: EventCalendar.cpp:562
double GetCurrentTime() const
Definition: EventCalendar.cpp:534
bool HasMoreEvents()
Test whether the calendar has more events in it.
Definition: EventCalendar.cpp:528
const int NULL_PARTICLE
A particle index representing an invalid particle.
Definition: Constants.h:41
void ClearCalendar()
Empties all events from the event calendar and returns the allocated tree nodes to the free list...
Definition: EventCalendar.cpp:271
EventCalendar(const unsigned particleCount)
Initialize the calendar for a given number of particles.
Definition: EventCalendar.cpp:211
int GetCurrentObjectA() const
Definition: EventCalendar.cpp:541
~EventCalendar()
Clean up the dynamically allocated memory.
Definition: EventCalendar.cpp:254
void ScheduleEvent(const double time, const EventType type, const int idA=Constants::NULL_PARTICLE, const int idB=Constants::NULL_PARTICLE)
Schedule an event with the calendar.
Definition: EventCalendar.cpp:354