ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
SimulationExecutive.h
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Simulation Executive header file
18
19Author: Alex Reynolds
20*/
21#ifndef SIMULATION_EXECUTIVE_H
22#define SIMULATION_EXECUTIVE_H
23
24#include "architecture/Executive.h"
25#include "six_dof_dynamics/Frame.hpp"
26#include "six_dof_dynamics/Body.hpp"
27#include "six_dof_dynamics/Node.hpp"
28#include "core/clockwerkerrors.h"
29#include "simulation/SimScheduler.h"
30#include "monitors/TimeTriggerMonitor.h"
31#include "events/SimTerminationEvent.h"
32#include "simulation/ArgParser.h"
33#include "simulation/DispersionEngine.h"
34#include "simulation/SimTimeManager.h"
35#include "logging/LogManager.h"
36#include "simulation/VisualsModel.h"
37#include "utils/spiceutils.h"
38
39namespace modelspace {
40
41 class Monitor;
42
43 /// @brief Implementation of the executive class for simulation
44 ///
45 /// The SimulationExecutive is a specific implementation of the
46 /// Executive base class for simulation. It contains specified
47 /// implementations of the scheduler, a frame tree and associated
48 /// search functions, and functions for logging and integration
49 /// setup.
50 ///
51 /// The simulation executive also controls visuals, if the user
52 /// chooses to enable them. They are inactive by default.
53 ///
54 /// Command line arguments that can be set on simulation executive
55 /// "end" - The simulation end time, as a double
56 /// "run" - The run number for Monte Carlo simulation. Run 0 is the "default"
57 /// "out-dir" - The output directory to which results should be dumped
58 /// "use-spice" - A flag indicating whether SPICE should be used. Default is true
59 ///
60 /// With regards to SPICE, the simulation executive loads by default the
61 /// kernels provided in utils/spiceutils.h. Users may command the simulation
62 /// executive to load more kernels using the function loadSpiceKernels
63 class SimulationExecutive : public clockwerk::Executive {
64 public:
65 /// @brief Constructor for the simulation executive
67 ~SimulationExecutive();
68
69 /// @brief Wrapper around arg parse
70 /// @param argc C++ argc input
71 /// @param argv C++ argv input
72 /// @return Error code corresponding to success/failure
73 int parseArgs(int argc, char *argv[]);
74
75 /// @brief Wrapper around arg parse
76 /// @param args A std::vector of arguments
77 /// @return Error code corresponding to success/failure
78 int parseArgs(std::vector<std::string> arguments);
79
80 /// Functions to set and get our integrator
81 void integrator(int val) {_sim_scheduler.params.integrator_type(val);}
82 int integrator() {return _sim_scheduler.params.integrator_type();}
83
84 /// @brief Function to set the simulation run rate, in Hz
85 /// @param rate_hz The simulation run rate, in Hz
86 void setRateHz(unsigned int rate_hz);
87
88 /// @brief Function to set the simulation run rate, in seconds as Time
89 /// @param rate_sec The simulation run rate as a timespec with seconds, nanoseconds
90 void setRateSec(clockwerk::Time rate_sec);
91 void setRateSec(struct timespec rate_sec);
92 void setRateSec(double rate_sec);
93
94 /// @brief Overloaded function to set the simulation end time
95 /// @param end_time The end time in its respective format
96 void end(clockwerk::Time end_time);
97 void end(struct timespec end_time);
98 void end(double end_time);
99
100 /// @brief Function to return simulation end time
101 /// @return End time, as a Time class
102 clockwerk::Time end() {return _term_monitor.params.trigger_time();}
103
104 /// @brief Function to initialize our simulation executive and everything
105 /// it contains
106 /// @return Error code corresponding to success/failure
107 int startup();
108
109 /// @brief Function to step the scheduler by a single step
110 /// @return Error code corresponding to success/failure
111 int step();
112
113 /// @brief Function to step the scheduler by a single step
114 /// @param step_size The step size (as a time object) to step the sim by
115 /// @return Error code corresponding to success/failure
116 int step(const clockwerk::Time &step_size);
117
118 /// / @brief Function to execute run for the executive and its kids
119 /// / @return Error code corresponding to success/failure
120 int run();
121
122 /// @brief Function to acces the run rate of the simulation
123 /// @return The rate of the simulation
124 clockwerk::Time rate() {return _sim_scheduler.inputs.rate();}
125
126 /// @brief Getter for the simulation root frame
127 clockwerk::Frame<double>* rootFrame() {return &_root_frame;}
128
129 /// @brief Function to search the simulation and frame trees for
130 /// a match
131 /// @param s_val The value to search for
132 /// @return A vector of string addresses matching the query
133 /// @note Returns string addresses -- user must get address and
134 /// cast appropriately if they wish to use appropriate type
135 std::vector<std::string> search(const std::string &s_val);
136
137 /// @brief Function to search the frame tree for a match
138 /// @param s_val The value to search for
139 /// @return A vector of string addresses matching the query
140 /// @note Returns string addresses -- user must get address and
141 /// cast appropriately if they wish to use appropriate type
142 std::vector<std::string> searchFrameTree(const std::string &s_val);
143
144 /// @brief Function to search the simulation architecture tree for a match
145 /// @param s_val The value to search for
146 /// @return A vector of string addresses matching the query
147 /// @note Returns string addresses -- user must get address and
148 /// cast appropriately if they wish to use appropriate type
149 std::vector<std::string> searchSimTree(const std::string &s_val);
150
151 /// Getter for the log manager
153
154 /// @brief Overloaded function to register and set up a logger
155 /// @param log The logger to add to the sim
156 /// @param rate The rate, in Hz, at which the logger should log
157 void addLog(clockwerk::SimLogger &log, unsigned int rate) {_log_manager.addLog(log, rate);}
158
159 /// @brief Overloaded function to register and set up a logger
160 /// @param log The logger to add to the sim
161 /// @param monitor The monitor which triggers the logger
162 void addLog(clockwerk::SimLogger &log, clockwerk::Monitor &monitor) {_log_manager.addLog(log, monitor);}
163
164 /// Getter for the schedule
165 modelspace::SimScheduler* schedule() {return &_sim_scheduler;}
166
167 /// Getter for the visuals model
169
170 /// @brief Function to enable visuals for the simulation
171 void enableVisuals();
172
173 /// @brief Function to disable visuals for the simulation
174 /// @note Shouldn't need to call this unless visuals were already enabled
175 void disableVisuals();
176
177 /// @brief Function to set the local model log level
178 /// @param new_level The new level to set logging to
179 void logLevel(clockwerk::log_level_e new_level) {_local_log_level = new_level;}
180
181 /// @brief Returns termination flag
182 /// @return Termination flag
183 bool isTerminated() {return _sim_scheduler.isTerminated();}
184
185 /// @brief Getter for run number
186 /// @return The run number
187 unsigned int runNumber() {return _run_num;}
188
189 /// @brief Setter for run number
190 /// @return The run number
191 void runNumber(unsigned int run_num) {_run_num = run_num;}
192
193 /// @brief Function to access args
194 /// @return Pointer to arguments
195 modelspace::ArgParser* args() {return &_args;}
196
197 /// @brief Function to access dispersions
198 /// @return Pointer to dispersions
200
201 /// @brief Override of time() from executive to return SimTimeManager
202 /// @return A pointer to the sim time manager.
203 modelspace::SimTimeManager* time() {return &_sim_scheduler.time;}
204
205 /// @brief Function to access sim time
206 /// @return Current sim time
207 double simTime() {return time()->base_time().asDouble();}
208
209 /// @brief Function to return pointer to the spice manager
210 /// @return Pointer to the spice manager
212
213 /// @brief Function to set time by string input
214 /// @param time_input The string input by which time will be set.
215 /// valid inputs are any input which is accepted
216 /// by the SPICE function STR2ET. More info here:
217 /// https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/FORTRAN/spicelib/str2et.html
218 /// This value defaults to 2023 September 26, 12:00:00 MDT
219 void setTime(const std::string &time_in) {time()->setTime(time_in);}
220
221 /// @brief Function to return whether the simulation executive is started
222 /// @return True if started, false if not
223 bool started() {return _started;}
224
225 protected:
226 /// @brief Function to configure simulation executive from command line input
228
229 /// @brief Function to print information associated with the simulation
230 void _printSimInfo();
231
232 /// @brief Pointer to the executive object, which for sim executive is self
233 /// This feature included for easy logging and consistent access accross modules
234 clockwerk::Executive* exc;
235
236 /// @brief To parse our command line arguments
238
239 /// @brief To generate dispersions for the simulation
241 int _rng_seed = 0;
242
243 /// The run number
244 unsigned int _run_num = 0;
245
246 /// @brief This is our sim's root frame, from which all other frames derive their relationships
247 ///
248 /// The root frame within the simulation executive is an arbitrary frame
249 /// relative to which all frames are defined. When SPICE is active in the
250 /// simulation executive the root frame is treated as the root of the
251 /// J2000 frame, and all planets will be set relative to that point.
252 clockwerk::Frame<double> _root_frame;
253
254 /// Specific declarations of scheduler, etc. specific to the simulation
255 /// executive
257 SimScheduler _sim_scheduler;
258
259 /// The spice manager to control all spice interactions
261
262 /// Monitor and event to terminate sim run
264 SimTerminationEvent _term_event;
265
266 /// Pointer to our visuals manager
267 VisualsModel* _visuals_model = nullptr;
268
269 /// Our local log level -- allows a higher log level locally than the overall system
270 clockwerk::log_level_e _local_log_level = clockwerk::NONE;
271
272 /// Flag to indicate whether the executive has been properly started.
273 /// Executive will not run unless startup has been called.
274 bool _started = false;
275
276 /// Variable to track the number of steps the simulation has taken
277 unsigned long long _step_count = 0;
278 };
279
280}
281
282#endif
const T & operator()()
Overloaded operator to return value of DataIO object.
Definition DataIO.hpp:129
int operator()(const T &new_value)
Function to set the value of the DataIO object.
Definition DataIO.hpp:115
Central control mechanism to run simulations and software.
Definition Executive.h:43
Frame class definition.
Definition Frame.hpp:92
Base class implementation of the monitor.
Definition Tasks.h:212
Class for logging data to a file.
Definition SimLogger.h:67
DataIO< Time > base_time
This is the exact current time as the scheduler steps forward.
Definition TimeManager.h:66
Wrapper to manage and convert time as timespce.
Definition Time.h:45
Class to parse arguments from the command line in any language.
Definition ArgParser.h:32
Class to generate input dispersions for the simulation.
Definition DispersionEngine.h:78
Class to manage logs.
Definition LogManager.h:42
void addLog(clockwerk::SimLogger &log, unsigned int rate)
Overloaded function to register and set up a logger.
Definition LogManager.cpp:62
void addLog(clockwerk::SimLogger &log, clockwerk::Monitor &monitor)
Overloaded function to register and set up a logger.
Definition LogManager.cpp:92
Simple implementation of the scheduler class.
Definition SimScheduler.h:47
virtual bool isTerminated()
Function to indicate whether the scheduler is terminated.
Definition SimScheduler.h:108
modelspace::SimTimeManager time
Time manager to handle all time in the scheduler.
Definition SimScheduler.h:115
Class to trigger termination in scheduler.
Definition SimTerminationEvent.h:35
Class to manage time for the simulation object.
Definition SimTimeManager.h:45
void setTime(const std::string &time_input=DEFAULT_SIMULATION_TIME)
Function to set time by string input.
Definition SimTimeManager.cpp:80
Implementation of the executive class for simulation.
Definition SimulationExecutive.h:63
std::vector< std::string > searchFrameTree(const std::string &s_val)
Function to search the frame tree for a match.
Definition SimulationExecutive.cpp:296
void runNumber(unsigned int run_num)
Setter for run number.
Definition SimulationExecutive.h:191
void setTime(const std::string &time_in)
Function to set time by string input.
Definition SimulationExecutive.h:219
bool isTerminated()
Returns termination flag.
Definition SimulationExecutive.h:183
int parseArgs(std::vector< std::string > arguments)
Wrapper around arg parse.
Definition SimulationExecutive.cpp:74
void addLog(clockwerk::SimLogger &log, unsigned int rate)
Overloaded function to register and set up a logger.
Definition SimulationExecutive.h:157
SimulationExecutive()
Constructor for the simulation executive.
Definition SimulationExecutive.cpp:25
modelspace::LogManager * logManager()
Getter for the log manager.
Definition SimulationExecutive.h:152
void addLog(clockwerk::SimLogger &log, clockwerk::Monitor &monitor)
Overloaded function to register and set up a logger.
Definition SimulationExecutive.h:162
void end(clockwerk::Time end_time)
Overloaded function to set the simulation end time.
Definition SimulationExecutive.cpp:128
bool started()
Function to return whether the simulation executive is started.
Definition SimulationExecutive.h:223
modelspace::SpiceManager * spiceManager()
Function to return pointer to the spice manager.
Definition SimulationExecutive.h:211
modelspace::VisualsModel * visualsModel()
Getter for the visuals model.
Definition SimulationExecutive.h:168
void enableVisuals()
Function to enable visuals for the simulation.
Definition SimulationExecutive.cpp:226
void _configureFromCmdLine()
Function to configure simulation executive from command line input.
Definition SimulationExecutive.cpp:82
std::vector< std::string > search(const std::string &s_val)
Function to search the simulation and frame trees for a match.
Definition SimulationExecutive.cpp:285
TimeTriggerMonitor _term_monitor
Monitor and event to terminate sim run.
Definition SimulationExecutive.h:263
int step(const clockwerk::Time &step_size)
Function to step the scheduler by a single step.
Definition SimulationExecutive.cpp:176
clockwerk::Time end()
Function to return simulation end time.
Definition SimulationExecutive.h:102
double simTime()
Function to access sim time.
Definition SimulationExecutive.h:207
clockwerk::Frame< double > * rootFrame()
Getter for the simulation root frame.
Definition SimulationExecutive.h:127
modelspace::DispersionEngine * dispersions()
Function to access dispersions.
Definition SimulationExecutive.h:199
clockwerk::log_level_e _local_log_level
Our local log level – allows a higher log level locally than the overall system.
Definition SimulationExecutive.h:270
void disableVisuals()
Function to disable visuals for the simulation.
Definition SimulationExecutive.cpp:235
void setRateHz(unsigned int rate_hz)
Function to set the simulation run rate, in Hz.
Definition SimulationExecutive.cpp:105
LogManager _log_manager
Specific declarations of scheduler, etc. specific to the simulation executive.
Definition SimulationExecutive.h:256
void _printSimInfo()
Function to print information associated with the simulation.
Definition SimulationExecutive.cpp:304
void integrator(int val)
Functions to set and get our integrator.
Definition SimulationExecutive.h:81
int parseArgs(int argc, char *argv[])
Wrapper around arg parse.
Definition SimulationExecutive.cpp:66
clockwerk::Executive * exc
Pointer to the executive object, which for sim executive is self This feature included for easy loggi...
Definition SimulationExecutive.h:234
int run()
/
Definition SimulationExecutive.cpp:201
int startup()
Function to initialize our simulation executive and everything it contains.
Definition SimulationExecutive.cpp:239
DispersionEngine _dispersion_engine
To generate dispersions for the simulation.
Definition SimulationExecutive.h:240
modelspace::SimTimeManager * time()
Override of time() from executive to return SimTimeManager.
Definition SimulationExecutive.h:203
int step()
Function to step the scheduler by a single step.
Definition SimulationExecutive.cpp:150
unsigned int _run_num
The run number.
Definition SimulationExecutive.h:244
ArgParser _args
To parse our command line arguments.
Definition SimulationExecutive.h:237
bool _started
Flag to indicate whether the executive has been properly started. Executive will not run unless start...
Definition SimulationExecutive.h:274
VisualsModel * _visuals_model
Pointer to our visuals manager.
Definition SimulationExecutive.h:267
modelspace::ArgParser * args()
Function to access args.
Definition SimulationExecutive.h:195
clockwerk::Time rate()
Function to acces the run rate of the simulation.
Definition SimulationExecutive.h:124
void setRateSec(clockwerk::Time rate_sec)
Function to set the simulation run rate, in seconds as Time.
Definition SimulationExecutive.cpp:114
std::vector< std::string > searchSimTree(const std::string &s_val)
Function to search the simulation architecture tree for a match.
Definition SimulationExecutive.cpp:300
SpiceManager _spice_manager
The spice manager to control all spice interactions.
Definition SimulationExecutive.h:260
unsigned long long _step_count
Variable to track the number of steps the simulation has taken.
Definition SimulationExecutive.h:277
unsigned int runNumber()
Getter for run number.
Definition SimulationExecutive.h:187
clockwerk::Frame< double > _root_frame
This is our sim's root frame, from which all other frames derive their relationships.
Definition SimulationExecutive.h:252
void logLevel(clockwerk::log_level_e new_level)
Function to set the local model log level.
Definition SimulationExecutive.h:179
modelspace::SimScheduler * schedule()
Getter for the schedule.
Definition SimulationExecutive.h:165
The Spice Manager is a single class instance to manage spice frames and return SPICE states.
Definition spiceutils.h:49
The time trigger monitor is a simple implementation of the monitor that triggers continuously after a...
Definition TimeTriggerMonitor.h:37
Class to write out frame information via socket using a standard interface as follows:
Definition VisualsModel.h:61
Class to propagate CR3BP dynamics in characteristic units.
Definition ConfigurationWriter.cpp:18
clockwerk::DataIO< clockwerk::Time > rate
This is the rate at which the scheduler should run, as a Time object.
Definition SimScheduler.h:65
clockwerk::DataIO< int > integrator_type
The integrator type for the scheduler. Sets how models are integrated.
Definition SimScheduler.h:52
clockwerk::DataIO< clockwerk::Time > trigger_time
This is the variable indicating when the monitor should trigger.
Definition TimeTriggerMonitor.h:42