![]() |
.Simulation
|
#include <EventCalendar.h>
Public Member Functions | |
EventCalendar (const unsigned particleCount) | |
Initialize the calendar for a given number of particles. More... | |
~EventCalendar () | |
Clean up the dynamically allocated memory. More... | |
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. More... | |
void | NextEvent () |
Advance the calendar one step and put the next event into the current event place holders. | |
bool | HasMoreEvents () |
Test whether the calendar has more events in it. More... | |
void | ClearCalendar () |
Empties all events from the event calendar and returns the allocated tree nodes to the free list. More... | |
double | GetCurrentTime () const |
int | GetCurrentObjectA () const |
int | GetCurrentObjectB () const |
double | BalanceRatio () const |
Computes the ratio of the longest path to a leaf over the shortest path to a leaf. More... | |
EventType | GetCurrentEventType () const |
Interface for the Event Calendar class.
A node in the event calendar. Each node represents one event in the tree. It is structured using a binary search tree ordered by time. Each event involves two objects in the system. For collisions between two particles, it is the integer IDs of the two particles. For cell crossing events, the first is the ID of the particle and the second is the ID of the cell wall being crossed.
Each node uses six pointers to allow for quick updating of the calendar. Left and Right track the children as a typical BST would. Parent is the node's parent in the tree (where NULL indicates we are at the root).
CircleAL/CircleAR are the left and right pointers in the circular list of events involving object A. CircleBL/CircleBR do the same for object B.
An important invariant of this code is the invariance of the Type field for each CalendarNode
. Once the Type field is set, just after allocation, it is not changed until FreeNode
is called. In effect, the Type
field is const for the entire time each node is validly allocated.
MDSimulation::EventCalendar::EventCalendar | ( | const unsigned | particleCount | ) |
Initialize the calendar for a given number of particles.
particleCount | The number of particles in the system that the event calendar is tracking. |
MDSimulation::EventCalendar::~EventCalendar | ( | ) |
Clean up the dynamically allocated memory.
double MDSimulation::EventCalendar::BalanceRatio | ( | ) | const |
Computes the ratio of the longest path to a leaf over the shortest path to a leaf.
This is for useful diagnostics about tree balancing.
void MDSimulation::EventCalendar::ClearCalendar | ( | ) |
Empties all events from the event calendar and returns the allocated tree nodes to the free list.
The memory is kept, as it is expected that it will be used again.
EventType MDSimulation::EventCalendar::GetCurrentEventType | ( | ) | const |
int MDSimulation::EventCalendar::GetCurrentObjectA | ( | ) | const |
int MDSimulation::EventCalendar::GetCurrentObjectB | ( | ) | const |
double MDSimulation::EventCalendar::GetCurrentTime | ( | ) | const |
bool MDSimulation::EventCalendar::HasMoreEvents | ( | ) |
Test whether the calendar has more events in it.
void MDSimulation::EventCalendar::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.
Schedule an event in the simulation.
time | The time the event will occur in simulation units. |
type | The type of the event. |
idA | The id of the first object in the event. This refers to the the first particle unless this is an UpdateSystemEvent. |
idB | The id of the second object in the event. This may correspond to other things (i.e. the cell wall being crossed) depending on the type of the event. |