![]() |
helics
3.0.1
|
#include <TimeCoordinator.hpp>
Public Member Functions | |
TimeCoordinator () | |
TimeCoordinator (std::function< void(const ActionMessage &)> userSendMessageFunction) | |
void | setProperty (int timeProperty, Time propertyVal) |
void | setProperty (int intProperty, int propertyVal) |
void | setOptionFlag (int optionFlag, bool value) |
void | setDynamicJoining () |
Time | getTimeProperty (int timeProperty) const |
bool | getOptionFlag (int optionFlag) const |
int | getIntegerProperty (int intProperty) const |
void | setMessageSender (std::function< void(const ActionMessage &)> userSendMessageFunction) |
Time | getGrantedTime () const |
Time | allowedSendTime () const |
std::vector< GlobalFederateId > | getDependencies () const |
std::vector< GlobalFederateId > | getDependents () const |
int32_t | getCurrentIteration () const |
bool | updateTimeFactors () |
void | updateValueTime (Time valueUpdateTime, bool allowRequestSend) |
void | updateMessageTime (Time messageUpdateTime, bool allowRequestSend) |
void | specifyNonGranting (bool value=true) |
GlobalFederateId | getMinDependency () const |
message_process_result | processTimeMessage (const ActionMessage &cmd) |
void | processConfigUpdateMessage (const ActionMessage &cmd) |
void | processDependencyUpdateMessage (const ActionMessage &cmd) |
bool | addDependency (GlobalFederateId fedID) |
bool | addDependent (GlobalFederateId fedID) |
void | removeDependency (GlobalFederateId fedID) |
void | removeDependent (GlobalFederateId fedID) |
void | setAsChild (GlobalFederateId fedID) |
void | setAsParent (GlobalFederateId fedID) |
MessageProcessingResult | checkExecEntry () |
void | timeRequest (Time nextTime, IterationRequest iterate, Time newValueTime, Time newMessageTime) |
void | enteringExecMode (IterationRequest mode) |
MessageProcessingResult | checkTimeGrant () |
void | disconnect () |
void | localError () |
std::string | printTimeStatus () const |
bool | hasActiveTimeDependencies () const |
void | generateConfig (Json::Value &base) const |
void | generateDebuggingTimeInfo (Json::Value &base) const |
int | dependencyCount () const |
std::pair< GlobalFederateId, Time > | getMinGrantedDependency () const |
void | enterInitialization () |
void | requestTimeCheck () |
Public Attributes | |
GlobalFederateId | source_id {0} |
the identifier for inserting into the source id field of any generated messages; | |
IterationRequest | iterating {IterationRequest::NO_ITERATIONS} |
indicator that the coordinator should be iteratingif need be | |
bool | checkingExec {false} |
flag indicating that the coordinator is trying to enter the exec mode | |
bool | executionMode {false} |
flag that the coordinator has entered the execution Mode | |
bool | hasInitUpdates {false} |
flag indicating that a value or message was received during initialization stage | |
Protected Attributes | |
TimeData | upstream |
the variables for time coordination | |
TimeData | total |
TimeData | lastSend |
Time | time_granted {Time::minVal()} |
the most recent time granted | |
Time | time_requested {Time::maxVal()} |
the most recent time requested | |
Time | time_next {timeZero} |
the next possible internal event time | |
Time | time_minminDe {timeZero} |
the minimum of the minimum dependency event Time | |
Time | time_minDe {timeZero} |
the minimum event time of the dependencies | |
Time | time_allow {Time::minVal()} |
the current allowable time | |
Time | time_exec {Time::maxVal()} |
the time of the next targeted execution | |
Time | time_message {Time::maxVal()} |
the time of the earliest message event | |
Time | time_value {Time::maxVal()} |
the time of the earliest value event | |
Time | time_grantBase {Time::minVal()} |
Time | time_block {Time::maxVal()} |
a blocking time to not grant time >= the specified time | |
Time | maxTime {Time::maxVal()} |
shared_guarded_m< std::vector< GlobalFederateId > > | dependent_federates |
these are to maintain an accessible record of dependent federates | |
shared_guarded_m< std::vector< GlobalFederateId > > | dependency_federates |
these are to maintain an accessible record of dependency federates | |
TimeDependencies | dependencies |
federates which this Federate is temporally dependent on | |
std::vector< std::pair< Time, int32_t > > | timeBlocks |
blocks for a particular timeblocking link | |
tcoptions | info |
basic time control information | |
std::function< void(const ActionMessage &)> | sendMessageFunction |
callback used to send the messages | |
std::atomic< int32_t > | iteration {0} |
iteration counter | |
bool | disconnected {false} |
bool | nonGranting {false} |
bool | dynamicJoining {false} |
if set to true the time coordinator is joining an ongoing co-simulation | |
class managing the coordination of time in HELICS the time coordinator manages dependencies and computes whether time can advance or enter execution mode
helics::TimeCoordinator::TimeCoordinator | ( | ) |
default constructor
|
explicit |
construct from a federate info and message send function
References sendMessageFunction.
bool helics::TimeCoordinator::addDependency | ( | GlobalFederateId | fedID | ) |
add a federate dependency
References helics::TimeDependencies::addDependency(), dependencies, helics::TimeDependencies::getDependencyInfo(), and source_id.
Referenced by processDependencyUpdateMessage().
bool helics::TimeCoordinator::addDependent | ( | GlobalFederateId | fedID | ) |
add a dependent federate
References helics::TimeDependencies::addDependent(), dependencies, and dependent_federates.
Referenced by processDependencyUpdateMessage().
|
inline |
get the current granted time
References info, and time_granted.
MessageProcessingResult helics::TimeCoordinator::checkExecEntry | ( | ) |
check if entry to the executing state can be granted
References helics::ActionMessage::actionTime, helics::TimeDependencies::checkIfReadyForExecEntry(), helics::CONTINUE_PROCESSING, helics::ActionMessage::counter, dependencies, dependencyCount(), helics::ActionMessage::dest_id, dynamicJoining, helics::ERROR_RESULT, executionMode, helics::FORCE_ITERATION, hasInitUpdates, info, helics::ITERATE_IF_NEEDED, helics::ITERATING, iterating, iteration, iteration_requested_flag, helics::ActionMessage::messageID, helics::TimeData::next, helics::NEXT_STEP, helics::NO_ITERATIONS, helics::parent_broker_id, helics::ActionMessage::payload, helics::TimeDependencies::resetIteratingExecRequests(), sendMessageFunction, setActionFlag(), helics::ActionMessage::source_id, source_id, time_block, time_grantBase, time_granted, helics::timeZero, and updateTimeFactors().
MessageProcessingResult helics::TimeCoordinator::checkTimeGrant | ( | ) |
check if it is valid to grant a time
References helics::TimeDependencies::checkIfReadyForTimeGrant(), helics::CONTINUE_PROCESSING, dependencies, disconnect(), helics::TimeDependencies::empty(), helics::HALTED, info, helics::ITERATE_IF_NEEDED, helics::ITERATING, iterating, iteration, helics::NEXT_STEP, helics::NO_ITERATIONS, nonGranting, time_allow, time_block, time_exec, time_grantBase, time_granted, time_requested, and updateTimeFactors().
int helics::TimeCoordinator::dependencyCount | ( | ) | const |
get a count of the active dependencies
References helics::TimeDependencies::activeDependencyCount(), and dependencies.
Referenced by checkExecEntry().
void helics::TimeCoordinator::disconnect | ( | ) |
disconnect
References helics::appendMessage(), helics::TimeDependencies::begin(), dependencies, helics::ActionMessage::dest_id, helics::TimeDependencies::empty(), processTimeMessage(), sendMessageFunction, helics::TimeDependencies::size(), helics::ActionMessage::source_id, and source_id.
Referenced by checkTimeGrant().
void helics::TimeCoordinator::enteringExecMode | ( | IterationRequest | mode | ) |
function to enter the exec Mode
mode | the mode of iteration_request (no_iteration, FORCE_ITERATION, ITERATE_IF_NEEDED) |
References checkingExec, delayed_timing_flag, executionMode, info, iterating, helics::NO_ITERATIONS, setActionFlag(), helics::setIterationFlags(), helics::ActionMessage::source_id, and source_id.
void helics::TimeCoordinator::enterInitialization | ( | ) |
enter initialization
References dependencies, helics::ActionMessage::dest_id, dynamicJoining, sendMessageFunction, helics::ActionMessage::source_id, and source_id.
void helics::TimeCoordinator::generateConfig | ( | Json::Value & | base | ) | const |
generate a configuration string(JSON)
References helics::tcoptions::event_triggered, info, and helics::timeZero.
Referenced by generateDebuggingTimeInfo().
void helics::TimeCoordinator::generateDebuggingTimeInfo | ( | Json::Value & | base | ) | const |
generate debugging time information
References dependencies, generateConfig(), time_allow, time_exec, time_granted, time_message, time_minDe, time_minminDe, time_requested, time_value, timeBlocks, and upstream.
|
inline |
get the current iteration counter for an iterative call
this will work properly even when a federate is processing
References iteration.
std::vector< GlobalFederateId > helics::TimeCoordinator::getDependencies | ( | ) | const |
get a list of actual dependencies
References dependency_federates.
|
inline |
get a reference to the dependents vector
References dependent_federates.
|
inline |
get the current granted time
References time_granted.
int helics::TimeCoordinator::getIntegerProperty | ( | int | intProperty | ) | const |
get an option flag value
get a time Property
GlobalFederateId helics::TimeCoordinator::getMinDependency | ( | ) | const |
get the id of the federate that has the earliest time dependency
get a count of the active dependencies
References dependencies, and helics::TimeDependencies::getMinDependency().
std::pair< GlobalFederateId, Time > helics::TimeCoordinator::getMinGrantedDependency | ( | ) | const |
get a count of the active dependencies
References dependencies.
bool helics::TimeCoordinator::getOptionFlag | ( | int | optionFlag | ) | const |
get an option flag value
References helics::tcoptions::event_triggered, and info.
Time helics::TimeCoordinator::getTimeProperty | ( | int | timeProperty | ) | const |
get a time Property
bool helics::TimeCoordinator::hasActiveTimeDependencies | ( | ) | const |
return true if there are active dependencies
References dependencies, and helics::TimeDependencies::hasActiveTimeDependencies().
Referenced by helics::FilterFederate::hasActiveTimeDependencies().
void helics::TimeCoordinator::localError | ( | ) |
generate a local Error
References helics::appendMessage(), helics::TimeDependencies::begin(), dependencies, helics::ActionMessage::dest_id, helics::TimeDependencies::empty(), processTimeMessage(), sendMessageFunction, helics::TimeDependencies::size(), helics::ActionMessage::source_id, source_id, time_grantBase, and time_granted.
std::string helics::TimeCoordinator::printTimeStatus | ( | ) | const |
generate a string with the current time status
References time_allow, time_exec, time_granted, time_message, time_minDe, time_minminDe, time_requested, and time_value.
void helics::TimeCoordinator::processConfigUpdateMessage | ( | const ActionMessage & | cmd | ) |
process a message related to configuration
cmd | the update command |
References checkActionFlag(), indicator_flag, setOptionFlag(), and setProperty().
void helics::TimeCoordinator::processDependencyUpdateMessage | ( | const ActionMessage & | cmd | ) |
process a dependency update message
References addDependency(), addDependent(), checkActionFlag(), child_flag, parent_flag, removeDependency(), and removeDependent().
message_process_result helics::TimeCoordinator::processTimeMessage | ( | const ActionMessage & | cmd | ) |
process a message related to time
References helics::ActionMessage::actionTime, helics::GlobalFederateId::baseValue(), helics::delay_processing, dependencies, helics::TimeDependencies::getDependencyInfo(), helics::TimeData::minDe, helics::TimeData::minFed, helics::TimeData::next, helics::no_effect, helics::processed, removeDependent(), sendMessageFunction, helics::ActionMessage::setExtraData(), helics::ActionMessage::source_id, source_id, helics::ActionMessage::Tdemin, helics::TimeData::Te, helics::ActionMessage::Te, time_exec, time_grantBase, and time_granted.
Referenced by disconnect(), and localError().
void helics::TimeCoordinator::removeDependency | ( | GlobalFederateId | fedID | ) |
remove a dependency
fedID | the identifier of the federate to remove |
References dependencies, dependency_federates, and helics::TimeDependencies::removeDependency().
Referenced by processDependencyUpdateMessage().
void helics::TimeCoordinator::removeDependent | ( | GlobalFederateId | fedID | ) |
remove a dependent
fedID | the identifier of the federate to remove |
References dependencies, dependent_federates, and helics::TimeDependencies::removeDependent().
Referenced by processDependencyUpdateMessage(), and processTimeMessage().
void helics::TimeCoordinator::requestTimeCheck | ( | ) |
request a resend of the time message for certain federates currently blocking
References dependencies, helics::ActionMessage::dest_id, dynamicJoining, sendMessageFunction, helics::ActionMessage::source_id, source_id, and time_exec.
|
inline |
set dynamic joining flag to true
References dynamicJoining.
void helics::TimeCoordinator::setMessageSender | ( | std::function< void(const ActionMessage &)> | userSendMessageFunction | ) |
set the callback function used for the sending messages
References sendMessageFunction.
void helics::TimeCoordinator::setOptionFlag | ( | int | optionFlag, |
bool | value | ||
) |
set an option Flag for a the coordinator
References helics::tcoptions::event_triggered, and info.
Referenced by processConfigUpdateMessage().
void helics::TimeCoordinator::setProperty | ( | int | intProperty, |
int | propertyVal | ||
) |
set a timeProperty for a the coordinator
void helics::TimeCoordinator::setProperty | ( | int | timeProperty, |
Time | propertyVal | ||
) |
set a timeProperty for a the coordinator
Referenced by processConfigUpdateMessage().
void helics::TimeCoordinator::timeRequest | ( | Time | nextTime, |
IterationRequest | iterate, | ||
Time | newValueTime, | ||
Time | newMessageTime | ||
) |
request a time
nextTime | the new requested time |
iterate | the mode of iteration to use (no_iteration, FORCE_ITERATION, ITERATE_IF_NEEDED) |
newValueTime | the time of the next value |
newMessageTime | the time of the next message |
References dependencies, helics::TimeDependencies::empty(), helics::FORCE_ITERATION, info, iterating, helics::NO_ITERATIONS, helics::TimeDependencies::resetDependentEvents(), time_exec, time_granted, time_message, time_next, time_requested, time_value, and updateTimeFactors().
void helics::TimeCoordinator::updateMessageTime | ( | Time | messageUpdateTime, |
bool | allowRequestSend | ||
) |
update the time_message variable with a new value if needed if allowed it will send an updated time request message
References executionMode, hasInitUpdates, iterating, helics::NO_ITERATIONS, time_granted, time_message, and helics::timeZero.
bool helics::TimeCoordinator::updateTimeFactors | ( | ) |
compute updates to time values
References dependencies, helics::tcoptions::event_triggered, info, helics::TimeData::minDe, helics::TimeData::next, helics::TimeData::Te, time_allow, time_minDe, time_minminDe, time_next, time_requested, and upstream.
Referenced by checkExecEntry(), checkTimeGrant(), and timeRequest().
void helics::TimeCoordinator::updateValueTime | ( | Time | valueUpdateTime, |
bool | allowRequestSend | ||
) |
update the time_value variable with a new value if needed if allowed it will send an updated time request message
References executionMode, hasInitUpdates, iterating, helics::NO_ITERATIONS, time_granted, time_value, and helics::timeZero.
|
protected |
specify that the timeCoordinator should not grant times and instead operate in a continuous manner until completion
Referenced by checkTimeGrant().
|
protected |
time to use as a basis for calculating the next grantable time(usually time granted unless values are changing)
Referenced by checkExecEntry(), checkTimeGrant(), localError(), and processTimeMessage().