ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
SimScheduler.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/*
17Scheduler header file
18
19Author: Alex Reynolds
20*/
21#ifndef SIM_SCHEDULER_H
22#define SIM_SCHEDULER_H
23
24#include <vector>
25
26#include "architecture/Scheduler.h"
27#include "simulation/SimTimeManager.h"
28#include "core/clockwerkerrors.h"
29#include "models/support/SixDOFDynamicsModel.h"
30#include "six_dof_dynamics/Frame.hpp"
32
33namespace modelspace {
34
35 /// @brief Simple implementation of the scheduler class
36
37 /// This class is a base implementation of scheduler. It is an empty
38 /// base class and cannot be used without implementation in a derived
39 /// child class.
40
41 /// The scheduler is used to execute models, tasks, monitors, and events
42 /// in a sequence and format as defined in the derived scheduler class.
43
44 /// Note: This scheduler is intended for use explicitly in simulation
45 /// with the 6-DOF dynamics model. It manually adds the 6-DOF dynamics
46 /// and uses it internally for time and integrator calculations.
47 class SimScheduler : public clockwerk::Scheduler {
48 public:
49 /// Signal name Type Default
51 /// The integrator type for the scheduler. Sets how models are integrated
52 SIGNAL(integrator_type, int, 4)
53 /// This is a pointer to the simulation's root frame. Sets frame for dynamics model
54 SIGNAL(root_frame_ptr, clockwerk::Frame<double>*, nullptr)
55 /// The maximum multiple of real time at which the sim will run on a single step.
56 /// For example, 2 will make the simulation cap speed at double real time.
57 /// Any negative number does not set a cap on run speed. This is the default behavior.
58 /// This multiple is achieved by blocking on start step to ensure the timing multiple
59 /// is met.
62
64 /// This is the rate at which the scheduler should run, as a Time object
65 SIGNAL(rate, clockwerk::Time, clockwerk::Time(1,0))
67
69 /// The time at which the last scheduler step was entered
70 SIGNAL(entry_time, clockwerk::Time, clockwerk::Time())
71 /// The time at which the last scheduler step was exited. Does not change wrt max_real_time_multiple.
72 SIGNAL(exit_time, clockwerk::Time, clockwerk::Time())
74
75 /// @brief Constructor for the scheduler.
76 /// @note Does note resolve all dependencies - executive needs to be set
77 SimScheduler(clockwerk::Executive &executive);
78
79 /// @brief Function to start and configure the scheduler prior to run.
80 /// @return Error code corresponding to success/failure
81 int startup();
82
83 /// @brief Function to step the scheduler by a single step
84 /// @param step_size The step size (as a time object) to step the sim by. Any nsec value greater
85 /// than NSEC_MAX will cause step to take the input step size, which is the default behavior.
86 /// Setting time to a valid time will step by that time rather than the input value.
87 /// @return Error code corresponding to success/failure
88 /// @note Overrides input step size parameter
89 int step(const clockwerk::Time &step_size = clockwerk::Time(0, NSEC_MAX + 1));
90
91 /// @brief Function to run the scheduler until pre-determined end conditions
92 /// identified/calculated by the scheduler
93 /// @return Error code corresponding to success/failure
94 /// @note The scheduler MUST define stopping conditions. Otherwise, will run indefinitely
95 int run();
96
97 /// @brief Function to register tasks with the scheduler. Depending
98 /// on the scheduler implementation these may be unused
99 /// @param task The task to register
100 /// @return Error code corresponding to success/failure
101 virtual int registerTask(clockwerk::Task* task) override;
102
103 /// @brief Function to set the scheduler for termination
104 void terminate() {_is_terminated = true;}
105
106 /// @brief Function to indicate whether the scheduler is terminated
107 /// @return The termination flag status
108 virtual bool isTerminated() {return _is_terminated;}
109
110 /// @brief Function to set the local model log level
111 /// @param new_level The new level to set logging to
112 void logLevel(clockwerk::log_level_e new_level) {_local_log_level = new_level;}
113
114 /// Time manager to handle all time in the scheduler
116 protected:
117 /// @brief Function to execute a single task thread
118 /// @param task_thread The task thread to execute
119 /// @return Error code corresponding to success/failure
120 int _executeTaskThread(std::vector<clockwerk::Task*> &task_thread);
121
122 /// Vectors to store the sequences for each element of the simulation scheduler
123 std::vector<clockwerk::Task*> _all_tasks;
124 std::vector<clockwerk::Task*> _startup;
125 std::vector<std::vector<clockwerk::Task*>> _start_step;
126 std::vector<std::vector<clockwerk::Task*>> _derivative;
127 std::vector<std::vector<clockwerk::Task*>> _end_step;
128
129 /// Variable to terminate the simulation. The simulation run
130 /// function terminates when this flag is set
131 bool _is_terminated;
132
133 /// Variable to catch errors from stuff
134 int _error;
135
136 /// Our 6-DOF dynamics model
138
139 // Timing variables to ensure real time lock
140 bool _is_first_step = true;
141 clockwerk::Time _sim_time_step;
142 clockwerk::Time _real_time_step;
143 clockwerk::Time _next_time;
144 };
145}
146
147#endif
#define NSEC_MAX
Definition Time.h:35
DataIO(GraphTreeObject *data_parent, std::string data_name, T initial_value)
Constructor for the DataIO object.
Definition DataIO.hpp:134
Central control mechanism to run simulations and software.
Definition Executive.h:43
Frame class definition.
Definition Frame.hpp:92
Base class implementation of the scheduler.
Definition Scheduler.h:48
This is the base implementation of the task class.
Definition Tasks.h:68
Wrapper to manage and convert time as timespce.
Definition Time.h:45
Time()
Default, copy constructors and default destructor.
Definition Time.h:48
Simple implementation of the scheduler class.
Definition SimScheduler.h:47
void terminate()
Function to set the scheduler for termination.
Definition SimScheduler.h:104
virtual bool isTerminated()
Function to indicate whether the scheduler is terminated.
Definition SimScheduler.h:108
SimScheduler(clockwerk::Executive &executive)
Constructor for the scheduler.
Definition SimScheduler.cpp:27
int startup()
Function to start and configure the scheduler prior to run.
Definition SimScheduler.cpp:56
modelspace::SimTimeManager time
Time manager to handle all time in the scheduler.
Definition SimScheduler.h:115
bool _is_terminated
Variable to terminate the simulation. The simulation run function terminates when this flag is set.
Definition SimScheduler.h:131
int run()
Function to run the scheduler until pre-determined end conditions identified/calculated by the schedu...
Definition SimScheduler.cpp:214
void logLevel(clockwerk::log_level_e new_level)
Function to set the local model log level.
Definition SimScheduler.h:112
virtual int registerTask(clockwerk::Task *task) override
Function to register tasks with the scheduler. Depending on the scheduler implementation these may be...
Definition SimScheduler.cpp:50
int _executeTaskThread(std::vector< clockwerk::Task * > &task_thread)
Function to execute a single task thread.
Definition SimScheduler.cpp:237
std::vector< clockwerk::Task * > _all_tasks
Vectors to store the sequences for each element of the simulation scheduler.
Definition SimScheduler.h:123
SixDOFDynamicsModel _dynamics
Our 6-DOF dynamics model.
Definition SimScheduler.h:137
int _error
Variable to catch errors from stuff.
Definition SimScheduler.h:134
int step(const clockwerk::Time &step_size=clockwerk::Time(0, 999999999+1))
Function to step the scheduler by a single step.
Definition SimScheduler.cpp:131
Class to manage time for the simulation object.
Definition SimTimeManager.h:45
Model to implement 6-DOF dynamics.
Definition SixDOFDynamicsModel.h:72
#define SIGNAL(NAME, TYPE, INITIAL_VALUE)
Definition macros.h:87
#define START_PARAMS
Definition macros.h:96
#define END_OUTPUTS
Definition macros.h:90
#define END_PARAMS
Definition macros.h:98
#define START_OUTPUTS
Definition macros.h:88
#define END_INPUTS
Definition macros.h:94
#define START_INPUTS
Definition macros.h:92
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< clockwerk::Time > exit_time
The time at which the last scheduler step was exited. Does not change wrt max_real_time_multiple.
Definition SimScheduler.h:72
clockwerk::DataIO< clockwerk::Time > entry_time
The time at which the last scheduler step was entered.
Definition SimScheduler.h:70
clockwerk::DataIO< int > integrator_type
The integrator type for the scheduler. Sets how models are integrated.
Definition SimScheduler.h:52
clockwerk::DataIO< clockwerk::Frame< double > * > root_frame_ptr
This is a pointer to the simulation's root frame. Sets frame for dynamics model.
Definition SimScheduler.h:54
clockwerk::DataIO< int > max_real_time_multiple
The maximum multiple of real time at which the sim will run on a single step. For example,...
Definition SimScheduler.h:60