#include <Clock.h>
Public Member Functions | |
Clock () | |
~Clock () | |
void | setDt (double v) |
double | getDt () const |
double | getRunTime () const |
double | getCurrentTime () const |
unsigned long | getNsteps () const |
unsigned long | getCurrentStep () const |
unsigned int | getStride () const |
void | setTickStep (unsigned int i, unsigned int v) |
unsigned int | getTickStep (unsigned int i) const |
void | setTickDt (unsigned int i, double v) |
double | getTickDt (unsigned int i) const |
unsigned int | getDefaultTick (string className) const |
vector< double > | getDts () const |
void | stop () |
void | handleStart (const Eref &e, double runtime) |
dest function for message to run simulation for specified time | |
void | handleStep (const Eref &e, unsigned long steps) |
dest function for message to run simulation for specified steps | |
void | handleReinit (const Eref &e) |
dest function for message to trigger reinit. | |
void | process () |
unsigned int | getNumTicks () const |
bool | isRunning () const |
bool | isDoingReinit () const |
void | innerReportClock () const |
bool | checkTickNum (const string &funcName, unsigned int i) const |
Utility func to range-check when Ticks are being changed. | |
Static Public Member Functions | |
static void | reportClock () |
Static function. | |
static const Cinfo * | initCinfo () |
static unsigned int | lookupDefaultTick (const string &className) |
static void | buildDefaultTick () |
Builds the default scheduling map of classes to ticks. | |
Static Public Attributes | |
static const unsigned int | numTicks = 32 |
Friends | |
void | testClock () |
Clock now uses integral scheduling. The Clock has an array of child Ticks, each of which controls the process and reinit calls of its targets. The Clock has a minimum dt. All ticks operate with (positive) integral multiples of this, from 1 to anything. If multiple Ticks are due to go off in a given cycle, the order is from lowest to highest. Within a Tick the order of execution of target objects is undefined.
The Reinit call goes through all Ticks in order.
Clock::Clock | ( | ) |
Clock::~Clock | ( | ) |
void Clock::buildDefaultTick | ( | ) | [static] |
Builds the default scheduling map of classes to ticks.
This is the authoritative database of default tick assignments for each class. This is here because one needs to see relative locations of all assignments in order to do this. This assumes that in cases where there are two ticks (such as init and process) for a single class, then they are sequential. Base classes are also represented here. They are checked as a fallback if the more specific class lookup fails. Certain classes, such as Zombies, explicitly do not get scheduled even though they may inherit process messages. These are given the tick ~0U.
Referenced by Clock().
bool Clock::checkTickNum | ( | const string & | funcName, | |
unsigned int | i | |||
) | const |
Utility func to range-check when Ticks are being changed.
Referenced by setTickDt(), and setTickStep().
unsigned long Clock::getCurrentStep | ( | ) | const |
Referenced by initCinfo().
double Clock::getCurrentTime | ( | ) | const |
Referenced by initCinfo(), and testClock().
unsigned int Clock::getDefaultTick | ( | string | className | ) | const |
Referenced by initCinfo().
double Clock::getDt | ( | ) | const |
Referenced by initCinfo().
vector< double > Clock::getDts | ( | ) | const |
Referenced by initCinfo().
unsigned long Clock::getNsteps | ( | ) | const |
Referenced by initCinfo().
unsigned int Clock::getNumTicks | ( | ) | const |
References numTicks.
Referenced by initCinfo().
double Clock::getRunTime | ( | ) | const |
Referenced by initCinfo().
unsigned int Clock::getStride | ( | ) | const |
Referenced by initCinfo().
double Clock::getTickDt | ( | unsigned int | i | ) | const |
Referenced by initCinfo().
unsigned int Clock::getTickStep | ( | unsigned int | i | ) | const |
Referenced by initCinfo().
void Clock::handleReinit | ( | const Eref & | e | ) |
dest function for message to trigger reinit.
This is the dest function that sets off the reinit.
References ProcInfo::currTime, and ProcInfo::dt.
Referenced by initCinfo(), and testClock().
void Clock::handleStart | ( | const Eref & | e, | |
double | runtime | |||
) |
dest function for message to run simulation for specified time
Start has to happen gracefully: If the simulation was stopped for any reason, it has to pick up where it left off. The "runtime" argument is the additional time to run the simulation.
References handleStep().
Referenced by initCinfo(), and testClock().
void Clock::handleStep | ( | const Eref & | e, | |
unsigned long | steps | |||
) |
dest function for message to run simulation for specified steps
References ProcInfo::currTime, ProcInfo::dt, and SrcFinfo0::send().
Referenced by handleStart(), and initCinfo().
const Cinfo * Clock::initCinfo | ( | ) | [static] |
References getCurrentStep(), getCurrentTime(), getDefaultTick(), getDt(), getDts(), getNsteps(), getNumTicks(), getRunTime(), getStride(), getTickDt(), getTickStep(), handleReinit(), handleStart(), handleStep(), Neutral::initCinfo(), isRunning(), numTicks, setDt(), setTickDt(), setTickStep(), and stop().
Referenced by init(), testFibonacci(), and testShellAddMsg().
void Clock::innerReportClock | ( | ) | const |
Referenced by reportClock().
bool Clock::isDoingReinit | ( | ) | const |
Flag: True when the simulation is busy with reinit
bool Clock::isRunning | ( | ) | const |
Flag: True when the simulation is still running.
Referenced by initCinfo().
static unsigned int Clock::lookupDefaultTick | ( | const string & | className | ) | [static] |
Look up the default Tick number for the specified class. Note that for objects having an 'init' action as well as process, the assigned tick is for 'init' and the next number will be used for 'process'.
Referenced by innerCopyElements(), Stoich::unZombifyModel(), and Element::zombieSwap().
void Clock::process | ( | ) |
void Clock::reportClock | ( | ) | [static] |
Static function.
Utility function to tell us about the scheduling
References c, and innerReportClock().
void Clock::setDt | ( | double | v | ) |
Referenced by initCinfo().
void Clock::setTickDt | ( | unsigned int | i, | |
double | v | |||
) |
A little nasty because we want to ensure that the main clock dt is set intelligently from the assignment here.
References checkTickNum(), and numTicks.
Referenced by initCinfo().
void Clock::setTickStep | ( | unsigned int | i, | |
unsigned int | v | |||
) |
void Clock::stop | ( | ) |
Halts running simulation gracefully, letting it restart wherever it left off from.
Does a graceful stop of the simulation, leaving so it can continue cleanly with another step or start command.
Referenced by initCinfo().
void testClock | ( | ) | [friend] |
Check that clock scheduling works.
const unsigned int Clock::numTicks = 32 [static] |
number of Ticks.
The Clock manages simulation scheduling, in a close collaboration with the Tick. This version does this using an array of child Ticks, which it manages directly.
Simulation scheduling requires that certain functions of groups of objects be called in a strict sequence according to a range of timesteps, dt. For example, the numerical integration function of a compartment may be called every 10 microseconds. Furthermore, there may be ion channels in the simulation which also have to be called every 10 microseconds, but always after all the compartments have been called. Finally, the graphical update function to plot the compartment voltage may be called every 1 millisecond of simulation time. The whole sequence has to be repeated till the runtime of the simulation is complete.
This scheduler uses integral multiples of the base timestep dt_.
The system works like this: 1. Assign times to each Tick. This is divided by dt_ and the rounded value is used for the integral multiple. Zero means the tick is not scheduled. 2. The process call goes through all active ticks in order every timestep. Each Tick increments its counter and decides if it is time to fire. 4. The Reinit call goes through all active ticks in order, just once. 5. We connect up the Ticks to their target objects. 6. We begin the simulation by calling 'start' or 'step' on the Clock. 'step' executes exactly one timestep (of the minimum dt_), visiting all ticks as above.. 'start' executes an integral number of such timesteps. 7. To interrupt the simulation at some intermediate time, call 'stop'. This lets the system complete its current step. 8. To restart the simulation from where it left off, use the same 'start' or 'step' function on the Clock. As all the ticks retain their state, the simulation can resume smoothly.
Referenced by getNumTicks(), initCinfo(), setTickDt(), and testClock().