ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
modelspace::SimulationExecutive Class Reference

Implementation of the executive class for simulation. More...

#include <SimulationExecutive.h>

Inheritance diagram for modelspace::SimulationExecutive:
Collaboration diagram for modelspace::SimulationExecutive:

Public Member Functions

 SimulationExecutive ()
 Constructor for the simulation executive.
 
int parseArgs (int argc, char *argv[])
 Wrapper around arg parse.
 
int parseArgs (std::vector< std::string > arguments)
 Wrapper around arg parse.
 
void integrator (int val)
 Functions to set and get our integrator.
 
int integrator ()
 
void setRateHz (unsigned int rate_hz)
 Function to set the simulation run rate, in Hz.
 
void setRateSec (clockwerk::Time rate_sec)
 Function to set the simulation run rate, in seconds as Time.
 
void setRateSec (struct timespec rate_sec)
 
void setRateSec (double rate_sec)
 
void end (clockwerk::Time end_time)
 Overloaded function to set the simulation end time.
 
void end (struct timespec end_time)
 
void end (double end_time)
 
clockwerk::Time end ()
 Function to return simulation end time.
 
int startup ()
 Function to initialize our simulation executive and everything it contains.
 
int step ()
 Function to step the scheduler by a single step.
 
int step (const clockwerk::Time &step_size)
 Function to step the scheduler by a single step.
 
int run ()
 /
 
clockwerk::Time rate ()
 Function to acces the run rate of the simulation.
 
clockwerk::Frame< double > * rootFrame ()
 Getter for the simulation root frame.
 
std::vector< std::string > search (const std::string &s_val)
 Function to search the simulation and frame trees for a match.
 
std::vector< std::string > searchFrameTree (const std::string &s_val)
 Function to search the frame tree for a match.
 
std::vector< std::string > searchSimTree (const std::string &s_val)
 Function to search the simulation architecture tree for a match.
 
modelspace::LogManagerlogManager ()
 Getter for the log manager.
 
void addLog (clockwerk::SimLogger &log, unsigned int rate)
 Overloaded function to register and set up a logger.
 
void addLog (clockwerk::SimLogger &log, clockwerk::Monitor &monitor)
 Overloaded function to register and set up a logger.
 
modelspace::SimSchedulerschedule ()
 Getter for the schedule.
 
modelspace::VisualsModelvisualsModel ()
 Getter for the visuals model.
 
void enableVisuals ()
 Function to enable visuals for the simulation.
 
void disableVisuals ()
 Function to disable visuals for the simulation.
 
void logLevel (clockwerk::log_level_e new_level)
 Function to set the local model log level.
 
bool isTerminated ()
 Returns termination flag.
 
unsigned int runNumber ()
 Getter for run number.
 
void runNumber (unsigned int run_num)
 Setter for run number.
 
modelspace::ArgParserargs ()
 Function to access args.
 
modelspace::DispersionEnginedispersions ()
 Function to access dispersions.
 
modelspace::SimTimeManagertime ()
 Override of time() from executive to return SimTimeManager.
 
double simTime ()
 Function to access sim time.
 
modelspace::SpiceManagerspiceManager ()
 Function to return pointer to the spice manager.
 
void setTime (const std::string &time_in)
 Function to set time by string input.
 
bool started ()
 Function to return whether the simulation executive is started.
 
virtual void terminate ()
 /
 
void schedule (Scheduler *sched)
 /
 
clockwerk::EventLoggereventLog ()
 /
 
void time (TimeManager *mgr)
 
GraphTreeObjectparent ()
 Functions to get object's parent/children.
 
int parent (GraphTreeObject *new_parent)
 Function to assign the node's parent via pointer.
 
int parent (GraphTreeObject &new_parent)
 Function to assign the node's parent via reference.
 
std::vector< GraphTreeObject * > & children ()
 
unsigned int nChildren ()
 Getters for number of children and descendants.
 
unsigned int nDescendants ()
 
std::string name () const
 Getter and setter for object name.
 
int name (const std::string &new_name)
 
int rank ()
 Getter for the object rank.
 
virtual int type ()
 Function to indicate type – -1 by default unless implemented downstream.
 
bool loggable ()
 Getter for object logability flag – note no setter because should only be set by this or a derived class in its definition.
 
std::string address ()
 Getter for object's string address.
 
GraphTreeObjectgetByAddress (const std::string &address)
 Function to get an object from the graph tree by string address.
 
void dump (bool recursive=false)
 Function to dump the graph node, optionally including descendents.
 
void graphNodeInfo ()
 Function to return all info associated with a given graph node.
 
void recurseGraphNodeInfo (unsigned int counter)
 Function to recurse through graph tree and print all node info.
 
virtual int header (void *logger)
 Function to pass headers for this object to the logger.
 
virtual std::vector< std::string > header_info () const
 
void findLoggable (std::vector< GraphTreeObject * > &matches)
 Function to find all loggable parameters in this node and its children.
 
virtual int log (void *logger)
 Function to log data to a logger.
 
void lock (bool recursive=true)
 Function to lock the graph tree object and its children to changes.
 
void unlock (bool recursive=true)
 Function to unlock the graph tree and its children for changes.
 
bool locked ()
 Function to return whether graph tree object is locked.
 

Protected Member Functions

void _configureFromCmdLine ()
 Function to configure simulation executive from command line input.
 
void _printSimInfo ()
 Function to print information associated with the simulation.
 
void recalculateDescendants ()
 Function to recursively re-calculate the number of descendants of a given node on the tree.
 
void recalculateRank ()
 Function to recursively re-calculate the rank of a given node on the tree.
 
std::vector< std::string > decomposeAddress (std::string address)
 Function to decompose a string into a series of substrings via indexing.
 
void findMatches (const std::vector< std::string > &subaddresses, const unsigned int &num_subaddresses, unsigned int index, bool match_found, std::vector< GraphTreeObject * > &matches)
 Function to find all addresses mathcing the set of substrings @parem subaddresses A vector of subaddresses to match.
 
std::vector< GraphTreeObject * > searchNodes (const std::string &address)
 Function to search through the graph tree by string address.
 
int addChild (GraphTreeObject *child)
 Function to add a child to the graph tree object.
 
int removeChild (GraphTreeObject *child)
 Function to remove a child from the graph node's children.
 

Protected Attributes

clockwerk::Executiveexc
 Pointer to the executive object, which for sim executive is self This feature included for easy logging and consistent access accross modules.
 
ArgParser _args
 To parse our command line arguments.
 
DispersionEngine _dispersion_engine
 To generate dispersions for the simulation.
 
int _rng_seed = 0
 
unsigned int _run_num = 0
 The run number.
 
clockwerk::Frame< double > _root_frame
 This is our sim's root frame, from which all other frames derive their relationships.
 
LogManager _log_manager
 Specific declarations of scheduler, etc. specific to the simulation executive.
 
SimScheduler _sim_scheduler
 
SpiceManager _spice_manager
 The spice manager to control all spice interactions.
 
TimeTriggerMonitor _term_monitor
 Monitor and event to terminate sim run.
 
SimTerminationEvent _term_event
 
VisualsModel_visuals_model = nullptr
 Pointer to our visuals manager.
 
clockwerk::log_level_e _local_log_level = clockwerk::NONE
 Our local log level – allows a higher log level locally than the overall system.
 
bool _started = false
 Flag to indicate whether the executive has been properly started. Executive will not run unless startup has been called.
 
unsigned long long _step_count = 0
 Variable to track the number of steps the simulation has taken.
 
clockwerk::Scheduler_schedule
 Scheduler to execute everything.
 
EventLogger event_logger
 Event logger for debugging and key events.
 
TimeManager * _time
 Time manager – tracked as a pointer because executive does not depend on time, but we want access for the majority of applications.
 
GraphTreeObject_parent = nullptr
 Pointer to the object's parent – should be null if the object is the root. Is set to null by default.
 
std::vector< GraphTreeObject * > _children
 Pointers to the object's children – automatically set to an empty vector, and can be increased to any size.
 
std::string _name = DEFAULT_NAME
 String name for object.
 
uint16_t _num_descendants = 0
 Total number of descendants (includes children of children) of the tree, again not including the tree itself.
 
uint8_t _num_children = 0
 Number of direct children of the tree (not including the tree itself)
 
uint8_t _rank = 0
 Rank for how far down on the graph tree the object is – starts at zero and maxes out at 256 via variable size.
 
uint8_t _graph_tree_type = BASE_GRAPH_TREE
 Variable to store graph tree object type.
 
bool _locked = false
 Variable to lock the graph tree object and prevent structural updates.
 
bool _loggable = false
 Variable to indicate whether the selected object is loggable. Set to false by default.
 

Detailed Description

Implementation of the executive class for simulation.

The SimulationExecutive is a specific implementation of the Executive base class for simulation. It contains specified implementations of the scheduler, a frame tree and associated search functions, and functions for logging and integration setup.

The simulation executive also controls visuals, if the user chooses to enable them. They are inactive by default.

Command line arguments that can be set on simulation executive "end" - The simulation end time, as a double "run" - The run number for Monte Carlo simulation. Run 0 is the "default" "out-dir" - The output directory to which results should be dumped "use-spice" - A flag indicating whether SPICE should be used. Default is true

With regards to SPICE, the simulation executive loads by default the kernels provided in utils/spiceutils.h. Users may command the simulation executive to load more kernels using the function loadSpiceKernels

Member Function Documentation

◆ addChild()

int clockwerk::GraphTreeObject::addChild ( GraphTreeObject child)
protectedinherited

Function to add a child to the graph tree object.

Parameters
childA pointer to the graph tree object to add to the tree
Returns
An error code corresponding to success/failure

◆ addLog() [1/2]

void modelspace::SimulationExecutive::addLog ( clockwerk::SimLogger log,
clockwerk::Monitor monitor 
)
inline

Overloaded function to register and set up a logger.

Parameters
logThe logger to add to the sim
monitorThe monitor which triggers the logger

◆ addLog() [2/2]

void modelspace::SimulationExecutive::addLog ( clockwerk::SimLogger log,
unsigned int  rate 
)
inline

Overloaded function to register and set up a logger.

Parameters
logThe logger to add to the sim
rateThe rate, in Hz, at which the logger should log

◆ address()

std::string clockwerk::GraphTreeObject::address ( )
inherited

Getter for object's string address.

Returns
Returns the string address for the object

◆ args()

modelspace::ArgParser * modelspace::SimulationExecutive::args ( )
inline

Function to access args.

Returns
Pointer to arguments

◆ decomposeAddress()

std::vector< std::string > clockwerk::GraphTreeObject::decomposeAddress ( std::string  address)
protectedinherited

Function to decompose a string into a series of substrings via indexing.

Parameters
addressThe address to be decomposed
Returns
A vector of strings containing each delimeter-separated substring

◆ disableVisuals()

void modelspace::SimulationExecutive::disableVisuals ( )

Function to disable visuals for the simulation.

Note
Shouldn't need to call this unless visuals were already enabled

◆ dispersions()

modelspace::DispersionEngine * modelspace::SimulationExecutive::dispersions ( )
inline

Function to access dispersions.

Returns
Pointer to dispersions

◆ dump()

void clockwerk::GraphTreeObject::dump ( bool  recursive = false)
inherited

Function to dump the graph node, optionally including descendents.

Parameters
recursiveParameter indicating whether to dump only one node (default/false) or the entire tree (true)
Note
Recursive dumps the whole tree... be careful what you wish for

◆ end() [1/2]

clockwerk::Time modelspace::SimulationExecutive::end ( )
inline

Function to return simulation end time.

Returns
End time, as a Time class

◆ end() [2/2]

void modelspace::SimulationExecutive::end ( clockwerk::Time  end_time)

Overloaded function to set the simulation end time.

Parameters
end_timeThe end time in its respective format

◆ eventLog()

clockwerk::EventLogger * clockwerk::Executive::eventLog ( )
inlineinherited

/

Getter for the event logger. Returns pointer to event logger

◆ findLoggable()

void clockwerk::GraphTreeObject::findLoggable ( std::vector< GraphTreeObject * > &  matches)
inherited

Function to find all loggable parameters in this node and its children.

Parameters
matchesExpandable vector to hold all matches in the tree

◆ findMatches()

void clockwerk::GraphTreeObject::findMatches ( const std::vector< std::string > &  subaddresses,
const unsigned int num_subaddresses,
unsigned int  index,
bool  match_found,
std::vector< GraphTreeObject * > &  matches 
)
protectedinherited

Function to find all addresses mathcing the set of substrings @parem subaddresses A vector of subaddresses to match.

Parameters
num_subaddressesThe number of subaddresses to match
indexThe index of subaddresses to search in
match_foundVariable indicating whether a match was found higher in the tree
matchesImplicit return of all matches to the specified address

◆ getByAddress()

GraphTreeObject * clockwerk::GraphTreeObject::getByAddress ( const std::string &  address)
inherited

Function to get an object from the graph tree by string address.

Parameters
addressThe exact string address to access the variable with
Returns
Pointer to the graph tree object at the address, or nullptr if address is not valid or returns

◆ header()

◆ header_info()

virtual std::vector< std::string > clockwerk::GraphTreeObject::header_info ( ) const
inlinevirtualinherited

Reimplemented in clockwerk::Time.

◆ isTerminated()

bool modelspace::SimulationExecutive::isTerminated ( )
inlinevirtual

Returns termination flag.

Returns
Termination flag

Reimplemented from clockwerk::Executive.

◆ lock()

void clockwerk::GraphTreeObject::lock ( bool  recursive = true)
inherited

Function to lock the graph tree object and its children to changes.

Parameters
recursiveFlag to indicate whether lock should be recursive

◆ log()

◆ logLevel()

void modelspace::SimulationExecutive::logLevel ( clockwerk::log_level_e  new_level)
inline

Function to set the local model log level.

Parameters
new_levelThe new level to set logging to

◆ parent() [1/2]

int clockwerk::GraphTreeObject::parent ( GraphTreeObject new_parent)
inherited

Function to assign the node's parent via reference.

Parameters
new_parentThe new parent to assign the node to
Returns
Error code corresponding to success/failure
Note
This function is the only method to ADD or REMOVE a node from a tree. To add, pass the address to a GraphTreeObject to this function. To remove, pass a nullptr. Note that parents for objects on an existing tree can be reassigned

◆ parent() [2/2]

int clockwerk::GraphTreeObject::parent ( GraphTreeObject new_parent)
inherited

Function to assign the node's parent via pointer.

Parameters
new_parentThe new parent to assign the node to
Returns
Error code corresponding to success/failure
Note
This function is the only method to ADD or REMOVE a node from a tree. To add, pass the address to a GraphTreeObject to this function. To remove, pass a nullptr. Note that parents for objects on an existing tree can be reassigned

◆ parseArgs() [1/2]

int modelspace::SimulationExecutive::parseArgs ( int  argc,
char argv[] 
)

Wrapper around arg parse.

Parameters
argcC++ argc input
argvC++ argv input
Returns
Error code corresponding to success/failure

◆ parseArgs() [2/2]

int modelspace::SimulationExecutive::parseArgs ( std::vector< std::string >  arguments)

Wrapper around arg parse.

Parameters
argsA std::vector of arguments
Returns
Error code corresponding to success/failure

◆ rate()

clockwerk::Time modelspace::SimulationExecutive::rate ( )
inline

Function to acces the run rate of the simulation.

Returns
The rate of the simulation

◆ recurseGraphNodeInfo()

void clockwerk::GraphTreeObject::recurseGraphNodeInfo ( unsigned int  counter)
inherited

Function to recurse through graph tree and print all node info.

Returns
String containing all recursive graph node information in tab cascade format

◆ removeChild()

int clockwerk::GraphTreeObject::removeChild ( GraphTreeObject child)
protectedinherited

Function to remove a child from the graph node's children.

Parameters
childThe child to remove
Returns
Success/fail error code based on whether the child is present

◆ run()

int modelspace::SimulationExecutive::run ( )
virtual

/

Function to execute run for the executive and its kids /

Returns
Error code corresponding to success/failure

Reimplemented from clockwerk::Executive.

◆ runNumber() [1/2]

unsigned int modelspace::SimulationExecutive::runNumber ( )
inline

Getter for run number.

Returns
The run number

◆ runNumber() [2/2]

void modelspace::SimulationExecutive::runNumber ( unsigned int  run_num)
inline

Setter for run number.

Returns
The run number

◆ schedule()

void clockwerk::Executive::schedule ( Scheduler sched)
inlineinherited

/

Function to set the scheduler for the executive

◆ search()

std::vector< std::string > modelspace::SimulationExecutive::search ( const std::string &  s_val)

Function to search the simulation and frame trees for a match.

Parameters
s_valThe value to search for
Returns
A vector of string addresses matching the query
Note
Returns string addresses – user must get address and cast appropriately if they wish to use appropriate type

◆ searchFrameTree()

std::vector< std::string > modelspace::SimulationExecutive::searchFrameTree ( const std::string &  s_val)

Function to search the frame tree for a match.

Parameters
s_valThe value to search for
Returns
A vector of string addresses matching the query
Note
Returns string addresses – user must get address and cast appropriately if they wish to use appropriate type

◆ searchNodes()

std::vector< GraphTreeObject * > clockwerk::GraphTreeObject::searchNodes ( const std::string &  address)
protectedinherited

Function to search through the graph tree by string address.

Parameters
address`The address or address chunk to search for
Returns
A vector of objects addresses meeting the criteria specified by address

◆ searchSimTree()

std::vector< std::string > modelspace::SimulationExecutive::searchSimTree ( const std::string &  s_val)

Function to search the simulation architecture tree for a match.

Parameters
s_valThe value to search for
Returns
A vector of string addresses matching the query
Note
Returns string addresses – user must get address and cast appropriately if they wish to use appropriate type

◆ setRateHz()

void modelspace::SimulationExecutive::setRateHz ( unsigned int  rate_hz)

Function to set the simulation run rate, in Hz.

Parameters
rate_hzThe simulation run rate, in Hz

◆ setRateSec()

void modelspace::SimulationExecutive::setRateSec ( clockwerk::Time  rate_sec)

Function to set the simulation run rate, in seconds as Time.

Parameters
rate_secThe simulation run rate as a timespec with seconds, nanoseconds

◆ setTime()

void modelspace::SimulationExecutive::setTime ( const std::string &  time_in)
inline

Function to set time by string input.

Parameters
time_inputThe string input by which time will be set. valid inputs are any input which is accepted by the SPICE function STR2ET. More info here: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/FORTRAN/spicelib/str2et.html This value defaults to 2023 September 26, 12:00:00 MDT

◆ simTime()

double modelspace::SimulationExecutive::simTime ( )
inline

Function to access sim time.

Returns
Current sim time

◆ spiceManager()

modelspace::SpiceManager * modelspace::SimulationExecutive::spiceManager ( )
inline

Function to return pointer to the spice manager.

Returns
Pointer to the spice manager

◆ started()

bool modelspace::SimulationExecutive::started ( )
inline

Function to return whether the simulation executive is started.

Returns
True if started, false if not

◆ startup()

int modelspace::SimulationExecutive::startup ( )
virtual

Function to initialize our simulation executive and everything it contains.

Returns
Error code corresponding to success/failure

Reimplemented from clockwerk::Executive.

◆ step() [1/2]

int modelspace::SimulationExecutive::step ( )
virtual

Function to step the scheduler by a single step.

Returns
Error code corresponding to success/failure

Reimplemented from clockwerk::Executive.

◆ step() [2/2]

int modelspace::SimulationExecutive::step ( const clockwerk::Time step_size)

Function to step the scheduler by a single step.

Parameters
step_sizeThe step size (as a time object) to step the sim by
Returns
Error code corresponding to success/failure

◆ terminate()

virtual void clockwerk::Executive::terminate ( )
inlinevirtualinherited

/

This function shadows the schedule's terminate call / for ease of use

◆ time()

modelspace::SimTimeManager * modelspace::SimulationExecutive::time ( )
inline

Override of time() from executive to return SimTimeManager.

Returns
A pointer to the sim time manager.

◆ type()

virtual int clockwerk::GraphTreeObject::type ( )
inlinevirtualinherited

Function to indicate type – -1 by default unless implemented downstream.

Returns
Int indicating frame type – unimplemented always -1

◆ unlock()

void clockwerk::GraphTreeObject::unlock ( bool  recursive = true)
inherited

Function to unlock the graph tree and its children for changes.

Parameters
recursiveFlag to indicate whether unlock should be recursive

Member Data Documentation

◆ _root_frame

clockwerk::Frame<double> modelspace::SimulationExecutive::_root_frame
protected

This is our sim's root frame, from which all other frames derive their relationships.

The root frame within the simulation executive is an arbitrary frame relative to which all frames are defined. When SPICE is active in the simulation executive the root frame is treated as the root of the J2000 frame, and all planets will be set relative to that point.


The documentation for this class was generated from the following files: