ModelSpace
Documentation for ModelSpace models and classes.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SimulationExecutive.h
Go to the documentation of this file.
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 /*
17 Simulation Executive header file
18 
19 Author: Alex Reynolds
20 */
21 #ifndef SIMULATION_SIMULATION_EXECUTIVE_H
22 #define SIMULATION_SIMULATION_EXECUTIVE_H
23 
24 #include "flight/FlightExecutive.h"
25 #include "frames/Frame.h"
26 #include "core/clockwerkerrors.h"
28 #include "simulation/ArgParser.h"
31 #include "logging/LogManager.h"
32 #include "logging/CsvLogger.h"
33 #include "simulation/VisualsModel.h"
34 #include "utils/spiceutils.h"
35 #include "Linux.h"
36 #include "SimPlatform.h"
37 
38 namespace modelspace {
39  class TimeTriggerMonitor;
40  class SimTerminationEvent;
41 
63  public:
67 
72  int parseArgs(int argc, char *argv[]);
73 
77  int parseArgs(std::vector<std::string> arguments);
78 
82 
85  void setRateHz(unsigned int rate_hz);
86 
89  void setRateSec(clockwerk::Time rate_sec);
90  void setRateSec(struct timespec rate_sec);
91  void setRateSec(double rate_sec);
92 
95  void end(clockwerk::Time end_time);
96  void end(struct timespec end_time);
97  void end(double end_time);
98 
102 
106  int16 startup();
107 
110  int16 step();
111 
115  int16 step(const clockwerk::Time &step_size);
116 
119  int16 run();
120 
124 
127 
134  std::vector<std::string> search(const std::string &s_val);
135 
141  std::vector<std::string> searchFrameTree(const std::string &s_val);
142 
148  std::vector<std::string> searchSimTree(const std::string &s_val);
149 
152 
155 
158 
160  void enableVisuals();
161 
164  void disableVisuals();
165 
168  bool visualsEnabled() {return _visuals_model != nullptr;}
169 
172  unsigned int runNumber() {return _run_num;}
173 
176  void runNumber(unsigned int run_num) {_run_num = run_num;}
177 
181 
185 
189 
192  double simTime() {return time().base_time().asFloatingPoint();}
193 
197 
204  void setTime(const std::string &time_in) {time().setTime(time_in);}
205 
208  bool started() {return _started;}
209 
212 
215  void writeSimDataToJson(const std::string &filename);
216 
222  int registerApp(cfspp::App& app, int16 slot) {return _sim_scheduler.registerApp(app, slot);}
223 
224  protected:
227  void _configLogEverything(const std::string &filename);
228 
230  void _configureFromCmdLine();
231 
233  void _printSimInfo();
234 
237 
240  int _rng_seed = 0;
241 
243  unsigned int _run_num = 0;
244 
252 
257 
260 
262  // NOTE: We have to allocate on the heap here due to the fact that these are
263  // now models.
264  TimeTriggerMonitor* _term_monitor;
265  SimTerminationEvent* _term_event;
266 
269 
272 
275  bool _started = false;
276 
278  unsigned long long _step_count = 0;
279 
280  CsvLogger* _all_log = nullptr;
281 
282  // Placeholder variables for OS, Platform, Setup, which are required by flight executive
283  // but not currently used in sim executive
284  Linux _null_os;
285  SimPlatform _null_platform;
287 
288  // Internal reference to simulation executive itself for logging
290  };
291 
292 }
293 
294 #endif
Base app class for derived implementation.
Definition: App.h:55
Executive derivation specifically to run flight systems.
Definition: FlightExecutive.h:46
cfspp::Scheduler & _scheduler
System schedule, which determines what apps and functions run when.
Definition: FlightExecutive.h:142
bool isTerminated()
Get whether scheduler is terminated.
Definition: Scheduler.h:77
Holds the setup configuration for Flight Executive.
Definition: Setup.h:39
Wrapper to manage and convert time as timespce.
Definition: Time.h:53
Class to parse arguments from the command line in any language.
Definition: ArgParser.h:32
Class for logging to CSV.
Definition: CsvLogger.h:35
Class to generate input dispersions for the simulation.
Definition: DispersionEngine.h:76
Frame class definition.
Definition: Frame.h:96
Class to manage logs.
Definition: LogManager.h:41
Simple implementation of the scheduler class.
Definition: SimScheduler.h:48
modelspace::SimTimeManager time
Time manager to handle all time in the scheduler.
Definition: SimScheduler.h:116
int16 registerApp(cfspp::App &app, int16 slot) override
Function to register apps with the scheduler. Depending on the scheduler implementation these may be ...
Definition: SimScheduler.cpp:54
Inputs inputs
Definition: SimScheduler.h:67
Params params
Definition: SimScheduler.h:62
Class to manage time for the simulation object.
Definition: SimTimeManager.h:45
clockwerk::DataIO< clockwerk::Time > base_time
This is the exact current time as the scheduler steps forward.
Definition: SimTimeManager.h:116
void setTime(const std::string &time_input=DEFAULT_SIMULATION_TIME)
Function to set time by string input.
Definition: SimTimeManager.cpp:136
Implementation of the executive class for simulation.
Definition: SimulationExecutive.h:62
std::vector< std::string > searchFrameTree(const std::string &s_val)
Function to search the frame tree for a match.
Definition: SimulationExecutive.cpp:355
void runNumber(unsigned int run_num)
Setter for run number.
Definition: SimulationExecutive.h:176
~SimulationExecutive()
Definition: SimulationExecutive.cpp:75
void setTime(const std::string &time_in)
Function to set time by string input.
Definition: SimulationExecutive.h:204
bool isTerminated()
Get whether scheduler is terminated.
Definition: SimulationExecutive.h:211
int registerApp(cfspp::App &app, int16 slot)
Function to register apps with the scheduler. Depending on the scheduler implementation these may be ...
Definition: SimulationExecutive.h:222
SimScheduler _sim_scheduler
Definition: SimulationExecutive.h:256
SimulationExecutive()
Constructor for the simulation executive.
Definition: SimulationExecutive.cpp:35
int _rng_seed
Definition: SimulationExecutive.h:240
SimTerminationEvent * _term_event
Definition: SimulationExecutive.h:265
Linux _null_os
Definition: SimulationExecutive.h:284
bool visualsEnabled()
Indicator as to whether visuals are enabled.
Definition: SimulationExecutive.h:168
bool started()
Function to return whether the simulation executive is started.
Definition: SimulationExecutive.h:208
modelspace::SimScheduler & schedule()
Getter for the schedule.
Definition: SimulationExecutive.h:154
modelspace::SpiceManager & spiceManager()
Function to return pointer to the spice manager.
Definition: SimulationExecutive.h:196
void enableVisuals()
Function to enable visuals for the simulation.
Definition: SimulationExecutive.cpp:285
void _configureFromCmdLine()
Function to configure simulation executive from command line input.
Definition: SimulationExecutive.cpp:102
std::vector< std::string > search(const std::string &s_val)
Function to search the simulation and frame trees for a match.
Definition: SimulationExecutive.cpp:344
cfspp::Setup _null_setup
Definition: SimulationExecutive.h:286
TimeTriggerMonitor * _term_monitor
Monitor and event to terminate sim run.
Definition: SimulationExecutive.h:264
modelspace::VisualsModel & visualsModel()
Getter for the visuals model.
Definition: SimulationExecutive.h:157
int16 run()
Function to execute run for the executive and its kids /.
Definition: SimulationExecutive.cpp:249
int16 startup()
Function to initialize our simulation executive and everything it contains.
Definition: SimulationExecutive.cpp:298
clockwerk::Time end()
Function to return simulation end time.
Definition: SimulationExecutive.cpp:82
double simTime()
Function to access sim time.
Definition: SimulationExecutive.h:192
void disableVisuals()
Function to disable visuals for the simulation.
Definition: SimulationExecutive.cpp:294
void setRateHz(unsigned int rate_hz)
Function to set the simulation run rate, in Hz.
Definition: SimulationExecutive.cpp:132
LogManager _log_manager
Definition: SimulationExecutive.h:255
Frame & rootFrame()
Getter for the simulation root frame.
Definition: SimulationExecutive.h:126
void _printSimInfo()
Function to print information associated with the simulation.
Definition: SimulationExecutive.cpp:416
void integrator(int val)
Functions to set and get our integrator.
Definition: SimulationExecutive.h:80
void _configLogEverything(const std::string &filename)
Configure logger which will log all sim outputs.
Definition: SimulationExecutive.cpp:383
int parseArgs(int argc, char *argv[])
Wrapper around arg parse.
Definition: SimulationExecutive.cpp:86
modelspace::DispersionEngine & dispersions()
Function to access dispersions.
Definition: SimulationExecutive.h:184
int16 step()
Function to step the scheduler by a single step.
Definition: SimulationExecutive.cpp:177
Frame _root_frame
This is our sim's root frame, from which all other frames derive their relationships.
Definition: SimulationExecutive.h:251
modelspace::ArgParser & args()
Function to access args.
Definition: SimulationExecutive.h:180
DispersionEngine _dispersion_engine
To generate dispersions for the simulation.
Definition: SimulationExecutive.h:239
CsvLogger * _all_log
Definition: SimulationExecutive.h:280
SimulationExecutive & exc
Definition: SimulationExecutive.h:289
unsigned int _run_num
The run number.
Definition: SimulationExecutive.h:243
ArgParser _args
To parse our command line arguments.
Definition: SimulationExecutive.h:236
bool _started
Definition: SimulationExecutive.h:275
SimPlatform _null_platform
Definition: SimulationExecutive.h:285
VisualsModel * _visuals_model
Pointer to our visuals manager.
Definition: SimulationExecutive.h:268
int integrator()
Definition: SimulationExecutive.h:81
clockwerk::Time rate()
Function to acces the run rate of the simulation.
Definition: SimulationExecutive.h:123
modelspace::LogManager & logManager()
Getter for the log manager.
Definition: SimulationExecutive.h:151
void writeSimDataToJson(const std::string &filename)
Write all simulation data, including models, to json output.
Definition: SimulationExecutive.cpp:363
void setRateSec(clockwerk::Time rate_sec)
Function to set the simulation run rate, in seconds as Time.
Definition: SimulationExecutive.cpp:141
log_level_e _local_log_level
Our local log level – allows a higher log level locally than the overall system.
Definition: SimulationExecutive.h:271
std::vector< std::string > searchSimTree(const std::string &s_val)
Function to search the simulation architecture tree for a match.
Definition: SimulationExecutive.cpp:359
SpiceManager _spice_manager
The spice manager to control all spice interactions.
Definition: SimulationExecutive.h:259
modelspace::SimTimeManager & time()
Override of time() from executive to return SimTimeManager.
Definition: SimulationExecutive.h:188
unsigned long long _step_count
Variable to track the number of steps the simulation has taken.
Definition: SimulationExecutive.h:278
unsigned int runNumber()
Getter for run number.
Definition: SimulationExecutive.h:172
The Spice Manager is a single class instance to manage spice frames and return SPICE states.
Definition: spiceutils.h:49
Class for managing ModelSpace visuals.
Definition: VisualsModel.h:54
*Command to change the Log Level of any app
Definition: cmd_CommandManager.h:55
log_level_e
Log level enumerations.
Definition: flighterrors.h:89
@ LOG_INFO
Definition: flighterrors.h:93
Class to propagate CR3BP dynamics in characteristic units.
Definition: statistics.hpp:22
clockwerk::DataIO< clockwerk::Time > rate
This is the rate at which the scheduler should run, as a Time object.
Definition: SimScheduler.h:66
clockwerk::DataIO< int > integrator_type
The integrator type for the scheduler. Sets how models are integrated.
Definition: SimScheduler.h:53