ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
SixDOFDynamicsModel.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/*
176-DOF Dynamics header file
18
19Author: Alex Reynolds
20*/
21
22#ifndef MODELS_SUPPORT_SIX_DOF_DYNAMICS_MODEL
23#define MODELS_SUPPORT_SIX_DOF_DYNAMICS_MODEL
24
25#include <vector>
26#include <array>
27#include <list>
28
29#include "architecture/Time.h"
30#include "architecture/Tasks.h"
31#include "architecture/Executive.h"
32#include "six_dof_dynamics/Frame.hpp"
33#include "six_dof_dynamics/Node.hpp"
34#include "six_dof_dynamics/Body.hpp"
35#include "six_dof_dynamics/FrameDynamics.hpp"
36#include "utils/ForwardEulerIntegrator.hpp"
37#include "utils/RK4Integrator.hpp"
38#include "simulation/SimulationSteps.h"
39
40namespace modelspace {
41
42 enum integrator_type_e {
43 FORWARD_EULER = 1,
44 RK4 = 4
45 };
46
47 /// @brief Model to implement 6-DOF dynamics
48 ///
49 /// This file defines the dynamics used for 6-DOF simulation.
50 ///
51 /// It inherits from the classical model architecture, but is designed
52 /// to execute in a manner that propagates dynamics forward in time.
53 ///
54 /// Tasks executed and order of operations:
55 /// Start step: Nothing
56 /// Derivative:
57 /// - Ensures frames are up to date by evaluating current state
58 /// - Articulates forces and moments applied at nodes through the
59 /// kinematics chain to the appropriate bodies
60 /// - Determines frame motion on the basis of applied forces/moments
61 /// - Integrates/updates frame states on the basis of kinematics --
62 /// note the critical difference in model scheme here -- this model
63 /// updates frame states in derivative, and therefore must run at
64 /// the end of the model order after forces and moments have been
65 /// calculated. It cannot be used as a standard model
66 /// End step: Nothing
67 ///
68 /// Key restrictions
69 /// - Must run at the end of model chain
70 /// - Must be one, and only one, instance of this model for every
71 /// simulation instance that uses 6-DOF frame dynamics
72 class SixDOFDynamicsModel : public clockwerk::Task {
73 public:
74 /// Model params
75 /// NAME TYPE DEFAULT VALUE
77 /** Input parameter describing the integrator type dynamics should use
78 * Valid choices are: "Forward Euler", "RK4" */
79 SIGNAL(integrator_type, modelspace::integrator_type_e,RK4);
80 /** Pointer to the root frame for the simulation. This pointer is used
81 * as the starting point for recursive calls to dynamics calculations*/
82 SIGNAL(root_frame_ptr, clockwerk::Frame<double>*,nullptr);
84
85 /// Model inputs
86 /// NAME TYPE DEFAULT VALUE
88 /** Time at the start of the simulation step, in seconds/nsec as Time class */
89 clockwerk::DataIO<clockwerk::Time> step_start_time = clockwerk::DataIO<clockwerk::Time>(this, "step_start_time");
90 /** Time at the end of the simulation step, in seconds as a double */
91 clockwerk::DataIO<clockwerk::Time> step_end_time = clockwerk::DataIO<clockwerk::Time>(this, "step_end_time");
93
94 /// Model outputs
95 /// NAME TYPE DEFAULT VALUE
97 /** The current simulation time as a time object */
98 clockwerk::DataIO<clockwerk::Time> current_time = clockwerk::DataIO<clockwerk::Time>(this, "current_time");
100
101 /// Model-specific implementations of startup and derivative
102 /// Must be scheduled manually to derivative
103 SixDOFDynamicsModel(clockwerk::Task &pnt, int schedule_slot=-2, const std::string &m_name="six_dof_dynamics")
104 : clockwerk::Task(pnt, schedule_slot, m_name) {}
105 SixDOFDynamicsModel(clockwerk::Executive &e, int schedule_slot=-2, const std::string &m_name="six_dof_dynamics")
106 : clockwerk::Task(e, schedule_slot, m_name) {}
107 ~SixDOFDynamicsModel() {}
108
109 /// @brief Function to reset our integrator for next step
110 void reset() {_integrator_step_num = 0;}
111 protected:
112 int start();
113 int execute();
114
115 /// @brief Function to recursively integrate the frame tree via
116 /// forward euler
117 /// @param frame_ptr Pointer to the root frame
118 /// @return Error code corresponding to success/failure
119 int _integrateRecursiveForwardEuler(clockwerk::Frame<double>* frame_ptr);
120 /// @brief Function to recursively integrate the frame tree via RK4
121 /// @param frame_ptr Pointer to the root frame
122 /// @return Error code corresponding to success/failure
123 int _integrateRecursiveRk4(clockwerk::Frame<double>* frame_ptr);
124
125 /// @brief Function to recursively loop through frames and set
126 /// their integrators
127 /// @return Error code corresponding to success/failure
128 int _recurseRefreshFrameIntegratorSet(clockwerk::Frame<double>* frame_ptr);
129
130 /// Variables to track integrator type and steps
131 unsigned int _integrator_step_num = 0;
132 unsigned int _integrator_steps_per_step = 0;
133
134 /// Vectors of integrators -- allows for dynamic integrator numbers
135 std::list<clockwerk::ForwardEulerIntegrator<double, NUM_INTEGRATED_STATES>> _fe_integrators;
136 std::list<clockwerk::RK4Integrator<double, NUM_INTEGRATED_STATES>> _rk4_integrators;
137 clockwerk::RK4Integrator<double, NUM_INTEGRATED_STATES>* _rk4_ptr;
138 clockwerk::ForwardEulerIntegrator<double, NUM_INTEGRATED_STATES>* _fe_ptr;
139
140 /// Our dynamics model for frames
141 clockwerk::FrameDynamics<double> _frame_dynamics;
142
143 /// Temporary variables to hold state output from integrator
144 /// and frame children for recursion
145 std::array<double, NUM_INTEGRATED_STATES> _tmp_state;
146 std::vector<GraphTreeObject*> _frame_children;
147
148 /// Temporary variable for time calculation in RK4
149 clockwerk::Time _half_step_size;
150 };
151
152}
153
154#endif
#define NUM_INTEGRATED_STATES
Definition Frame.hpp:35
Class for inter-object communication.
Definition DataIO.hpp:46
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
Definition ForwardEulerIntegrator.hpp:34
Definition FrameDynamics.hpp:34
Frame class definition.
Definition Frame.hpp:92
Base class for object organization.
Definition GraphTreeObject.h:87
Definition RK4Integrator.hpp:34
This is the base implementation of the task class.
Definition Tasks.h:68
Task(Task &pnt, int slot, const std::string &m_name="Unnamed")
Task-based constructor for the task. Auto-assigns executive.
Definition Tasks.cpp:47
Task(Executive &executive, int slot, const std::string &m_name="Unnamed")
Executive-based constructor for the task.
Definition Tasks.cpp:62
Wrapper to manage and convert time as timespce.
Definition Time.h:45
Model to implement 6-DOF dynamics.
Definition SixDOFDynamicsModel.h:72
clockwerk::FrameDynamics< double > _frame_dynamics
Our dynamics model for frames.
Definition SixDOFDynamicsModel.h:141
clockwerk::Time _half_step_size
Temporary variable for time calculation in RK4.
Definition SixDOFDynamicsModel.h:149
int start()
Function to perform task startup activities (step once after creation)
Definition SixDOFDynamicsModel.cpp:23
std::array< double, 13 > _tmp_state
Temporary variables to hold state output from integrator and frame children for recursion.
Definition SixDOFDynamicsModel.h:145
int _integrateRecursiveRk4(clockwerk::Frame< double > *frame_ptr)
Function to recursively integrate the frame tree via RK4.
Definition SixDOFDynamicsModel.cpp:148
void reset()
Function to reset our integrator for next step.
Definition SixDOFDynamicsModel.h:110
unsigned int _integrator_step_num
Variables to track integrator type and steps.
Definition SixDOFDynamicsModel.h:131
std::list< clockwerk::ForwardEulerIntegrator< double, 13 > > _fe_integrators
Vectors of integrators – allows for dynamic integrator numbers.
Definition SixDOFDynamicsModel.h:135
int execute()
Function to execute the task. All math and calculations should be here.
Definition SixDOFDynamicsModel.cpp:57
int _recurseRefreshFrameIntegratorSet(clockwerk::Frame< double > *frame_ptr)
Function to recursively loop through frames and set their integrators.
Definition SixDOFDynamicsModel.cpp:230
int _integrateRecursiveForwardEuler(clockwerk::Frame< double > *frame_ptr)
Function to recursively integrate the frame tree via forward euler.
Definition SixDOFDynamicsModel.cpp:109
SixDOFDynamicsModel(clockwerk::Task &pnt, int schedule_slot=-2, const std::string &m_name="six_dof_dynamics")
Model-specific implementations of startup and derivative Must be scheduled manually to derivative.
Definition SixDOFDynamicsModel.h:103
#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 > step_start_time
Definition SixDOFDynamicsModel.h:89
clockwerk::DataIO< clockwerk::Time > step_end_time
Definition SixDOFDynamicsModel.h:91
clockwerk::DataIO< clockwerk::Time > current_time
Definition SixDOFDynamicsModel.h:98
clockwerk::DataIO< modelspace::integrator_type_e > integrator_type
Definition SixDOFDynamicsModel.h:79
clockwerk::DataIO< clockwerk::Frame< double > * > root_frame_ptr
Definition SixDOFDynamicsModel.h:82