diff --git a/.gitignore b/.gitignore index 7b027ba..045eed0 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,6 @@ build/ docs/doxygen/* # IDE -.vscode/ qtrocket.pro.user .qmake.stash diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..25015e2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/g++", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "linux-gcc-x64", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..dbaf2db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ccc9f99..3dfd854 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,13 +56,13 @@ set(PROJECT_SOURCES sim/ConstantGravityModel.cpp sim/ConstantGravityModel.h sim/DESolver.h + sim/Environment.h sim/GeoidModel.h sim/GravityModel.cpp sim/GravityModel.h sim/Propagator.cpp sim/Propagator.h sim/RK4Solver.h - sim/SimulationOptions.h sim/SphericalGeoidModel.cpp sim/SphericalGeoidModel.h sim/SphericalGravityModel.cpp @@ -79,6 +79,8 @@ set(PROJECT_SOURCES utils/CurlConnection.h utils/Logger.cpp utils/Logger.h + utils/MotorModelDatabase.cpp + utils/MotorModelDatabase.h utils/RSEDatabaseLoader.cpp utils/RSEDatabaseLoader.h utils/ThreadPool.cpp diff --git a/QtRocket.cpp b/QtRocket.cpp index 279b74b..9c39fe7 100644 --- a/QtRocket.cpp +++ b/QtRocket.cpp @@ -71,11 +71,11 @@ QtRocket::QtRocket() logger = utils::Logger::getInstance(); running = false; - // Need to set some sane defaults for Simulation Options - // The default constructor for SimulationOptions will do that for us, so just use that - setSimulationOptions(std::make_shared()); + // Need to set some sane defaults for the Environment + // The default constructor for Environment will do that for us, so just use that + setEnvironment(std::make_shared()); - rocket = + rocket.first = std::make_shared(); } diff --git a/QtRocket.h b/QtRocket.h index 5d07f75..ef21c17 100644 --- a/QtRocket.h +++ b/QtRocket.h @@ -7,6 +7,7 @@ #include #include #include +#include // 3rd party headers /// \endcond @@ -16,8 +17,10 @@ #include "model/Rocket.h" #include "sim/AtmosphericModel.h" #include "sim/GravityModel.h" -#include "sim/SimulationOptions.h" +#include "sim/Environment.h" +#include "sim/Propagator.h" #include "utils/Logger.h" +#include "utils/MotorModelDatabase.h" /** * @brief The QtRocket class is the master controller for the QtRocket application. @@ -38,18 +41,20 @@ public: void runSim(); - std::shared_ptr getGravityModel() { return simOptions->getGravityModel(); } - std::shared_ptr getAtmosphereModel() { return simOptions->getAtmosphericModel(); } - double getTimeStep() { return simOptions->getTimeStep(); } - std::shared_ptr getRocket() { return rocket; } + + std::shared_ptr getEnvironment() { return environment; } + void setTimeStep(double t) { rocket.second->setTimeStep(t); } + std::shared_ptr getRocket() { return rocket.first; } + + std::shared_ptr getMotorDatabase() { return motorDatabase; } void addMotorModels(std::vector& m); const std::vector& getMotorModels() const { return motorModels; } - void addRocket(std::shared_ptr r) { rocket = r; } + void addRocket(std::shared_ptr r) { rocket.first = r; } - void setSimulationOptions(std::shared_ptr options) { simOptions = options; } + void setEnvironment(std::shared_ptr e) { environment = e; } private: QtRocket(); @@ -66,9 +71,10 @@ private: utils::Logger* logger; - std::shared_ptr rocket; + std::pair, std::shared_ptr> rocket; - std::shared_ptr simOptions; + std::shared_ptr environment; + std::shared_ptr motorDatabase; }; diff --git a/docs/qtrocketUML.xmi b/docs/qtrocketUML.xmi index 3bd6f98..9c6e74e 100644 --- a/docs/qtrocketUML.xmi +++ b/docs/qtrocketUML.xmi @@ -1,9 +1,14 @@ - + + + + + + @@ -24,17 +29,881 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + + + + + + + + + + + + + + + + + @@ -43,39 +912,556 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gui/SimOptionsWindow.cpp b/gui/SimOptionsWindow.cpp index ac0d73b..f2bcba8 100644 --- a/gui/SimOptionsWindow.cpp +++ b/gui/SimOptionsWindow.cpp @@ -11,7 +11,7 @@ #include "SimOptionsWindow.h" #include "ui_SimOptionsWindow.h" -#include "sim/SimulationOptions.h" +#include "sim/Environment.h" SimOptionsWindow::SimOptionsWindow(QWidget *parent) : QMainWindow(parent), @@ -31,7 +31,7 @@ SimOptionsWindow::SimOptionsWindow(QWidget *parent) : // populate the combo boxes - std::shared_ptr options(new sim::SimulationOptions); + std::shared_ptr options(new sim::Environment); std::vector atmosphereModels = options->getAvailableAtmosphereModels(); std::vector gravityModels = options->getAvailableGravityModels(); @@ -60,12 +60,12 @@ void SimOptionsWindow::on_buttonBox_accepted() { QtRocket* qtrocket = QtRocket::getInstance(); - std::shared_ptr options(new sim::SimulationOptions); + std::shared_ptr environment(new sim::Environment); - options->setTimeStep(ui->timeStep->text().toDouble()); - options->setGravityModel(ui->gravityModelCombo->currentText().toStdString()); - options->setAtmosphereModel(ui->atmosphereModelCombo->currentText().toStdString()); - qtrocket->setSimulationOptions(options); + qtrocket->setTimeStep(ui->timeStep->text().toDouble()); + environment->setGravityModel(ui->gravityModelCombo->currentText().toStdString()); + environment->setAtmosphereModel(ui->atmosphereModelCombo->currentText().toStdString()); + qtrocket->setEnvironment(environment); this->close(); diff --git a/model/Rocket.cpp b/model/Rocket.cpp index a1c860a..1ce0e14 100644 --- a/model/Rocket.cpp +++ b/model/Rocket.cpp @@ -8,10 +8,9 @@ Rocket::Rocket() : propagator(this) void Rocket::launch() { - propagator.setTimeStep(QtRocket::getInstance()->getTimeStep()); - propagator.clearStates(); + propagator.clearStates(); propagator.setCurrentTime(0.0); - mm.startMotor(0.0); + mm.startMotor(0.0); propagator.runUntilTerminate(); } diff --git a/sim/SimulationOptions.h b/sim/Environment.h similarity index 79% rename from sim/SimulationOptions.h rename to sim/Environment.h index b0aafa4..0e09caf 100644 --- a/sim/SimulationOptions.h +++ b/sim/Environment.h @@ -1,47 +1,44 @@ -#ifndef SIMULATIONOPTIONS_H -#define SIMULATIONOPTIONS_H - +#ifndef SIM_ENVIRONMENT_H +#define SIM_ENVIRONMENT_H /// \cond // C headers // C++ headers #include #include #include -#include #include - // 3rd party headers /// \endcond // qtrocket headers -#include "sim/GravityModel.h" -#include "sim/SphericalGravityModel.h" #include "sim/ConstantGravityModel.h" +#include "sim/SphericalGravityModel.h" -#include "sim/AtmosphericModel.h" #include "sim/ConstantAtmosphere.h" #include "sim/USStandardAtmosphere.h" +#include "sim/GeoidModel.h" namespace sim { /** - * @brief The SimulationOptions class holds the available simulation options and environmental models + * @brief Holds simulation environment information, such as the gravity model, atmosphere model, + * Geoid model + * */ -class SimulationOptions +class Environment { public: - SimulationOptions() + Environment() { - setTimeStep(0.01); setGravityModel("Constant Gravity"); setAtmosphereModel("Constant Atmosphere"); } - ~SimulationOptions() = default; - SimulationOptions(const SimulationOptions&) = delete; - SimulationOptions(SimulationOptions&&) = delete; - SimulationOptions& operator=(const SimulationOptions&) = delete; - SimulationOptions& operator=(SimulationOptions&&) = delete; + ~Environment() = default; + Environment(const Environment&) = delete; + Environment(Environment&&) = delete; + Environment& operator=(const Environment&) = delete; + Environment& operator=(Environment&&) = delete; std::vector getAvailableGravityModels() { @@ -59,7 +56,6 @@ public: return retVal; } - void setTimeStep(double t) { timeStep = t; } void setGravityModel(const std::string& model) { if(model == "Constant Gravity") @@ -94,7 +90,6 @@ public: return retVal; } std::shared_ptr getGravityModel() { return gravityModels[gravityModel]; } - double getTimeStep() { return timeStep; } private: @@ -106,12 +101,11 @@ private: {"Constant Gravity", std::shared_ptr()}, {"Spherical Gravity", std::shared_ptr()}}; - double timeStep{0.01}; - std::string gravityModel{"Constant Gravity"}; /// Constant Gravity Model is the default std::string atmosphereModel{"Constant Atmosphere"}; /// Constant Atmosphere Model is the default }; -} +} // namespace sim -#endif // SIMULATIONOPTIONS_H + +#endif // SIM_ENVIRONMENT_H diff --git a/sim/Propagator.cpp b/sim/Propagator.cpp index 7f7d525..93659eb 100644 --- a/sim/Propagator.cpp +++ b/sim/Propagator.cpp @@ -98,20 +98,20 @@ double Propagator::getMass() double Propagator::getForceX() { QtRocket* qtrocket = QtRocket::getInstance(); - return (currentState[3] >= 0 ? -1.0 : 1.0) * qtrocket->getAtmosphereModel()->getDensity(currentState[2])/ 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[3]* currentState[3]; + return (currentState[3] >= 0 ? -1.0 : 1.0) * qtrocket->getEnvironment()->getAtmosphericModel()->getDensity(currentState[2])/ 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[3]* currentState[3]; } double Propagator::getForceY() { QtRocket* qtrocket = QtRocket::getInstance(); - return (currentState[4] >= 0 ? -1.0 : 1.0) * qtrocket->getAtmosphereModel()->getDensity(currentState[2]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[4]* currentState[4]; + return (currentState[4] >= 0 ? -1.0 : 1.0) * qtrocket->getEnvironment()->getAtmosphericModel()->getDensity(currentState[2]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[4]* currentState[4]; } double Propagator::getForceZ() { QtRocket* qtrocket = QtRocket::getInstance(); - double gravity = (qtrocket->getGravityModel()->getAccel(currentState[0], currentState[1], currentState[2])).x3; - double airDrag = (currentState[5] >= 0 ? -1.0 : 1.0) * qtrocket->getAtmosphereModel()->getDensity(currentState[2]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[5]* currentState[5]; + double gravity = (qtrocket->getEnvironment()->getGravityModel()->getAccel(currentState[0], currentState[1], currentState[2])).x3; + double airDrag = (currentState[5] >= 0 ? -1.0 : 1.0) * qtrocket->getEnvironment()->getAtmosphericModel()->getDensity(currentState[2]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[5]* currentState[5]; double thrust = rocket->getThrust(currentTime); return gravity + airDrag + thrust; } diff --git a/utils/MotorModelDatabase.cpp b/utils/MotorModelDatabase.cpp new file mode 100644 index 0000000..d17427f --- /dev/null +++ b/utils/MotorModelDatabase.cpp @@ -0,0 +1,66 @@ +// class header +#include "utils/MotorModelDatabase.h" + +/// \cond +// C headers +// C++ headers +// 3rd party headers +/// \endcond + +// qtrocket project headers +#include "QtRocket.h" + +namespace utils +{ + +MotorModelDatabase::MotorModelDatabase() + : motorModelMap() +{ +} + +MotorModelDatabase::~MotorModelDatabase() +{ +} + +void MotorModelDatabase::addMotorModel(const model::MotorModel& m) +{ + utils::Logger* logger = QtRocket::getInstance()->getLogger(); + std::string name = m.data.commonName; + if(motorModelMap.find(name) != motorModelMap.end()) + { + logger->debug("Replacing MotorModel " + name + " in MotorModelDatabase"); + } + else + { + logger->info("Adding MotorModel " + name + " to MotorModelDatabase"); + } + motorModelMap[name] = m; +} + +void MotorModelDatabase::addMotorModels(const std::vector& models) +{ + utils::Logger* logger = QtRocket::getInstance()->getLogger(); + for(const auto& i : models) + { + addMotorModel(i); + } +} + +std::optional MotorModelDatabase::getMotorModel(const std::string& name) +{ + auto mm = motorModelMap.find(name); + if(mm == motorModelMap.end()) + { + Logger::getInstance()->debug("Unable to locate " + name + " in MotorModel database"); + + return std::nullopt; + + } + else + { + Logger::getInstance()->debug("Retrieved " + name + " from MotorModel database"); + return motorModelMap[name]; + } +} + +} // namespace utils diff --git a/utils/MotorModelDatabase.h b/utils/MotorModelDatabase.h new file mode 100644 index 0000000..44ca98d --- /dev/null +++ b/utils/MotorModelDatabase.h @@ -0,0 +1,74 @@ +#ifndef UTILS_MOTORMODELDATABASE_H +#define UTILS_MOTORMODELDATABASE_H + +/// \cond +// C headers +// C++ headers +#include +#include +#include +#include +// 3rd party headers +/// \endcond + +// qtrocket headers +#include "model/MotorModel.h" + + +namespace utils +{ +/** + * @brief MotorModelDatabase is a simple storage, search, and retrieval mechanism for Model Rocket + * motors. + * + */ +class MotorModelDatabase +{ +public: + MotorModelDatabase(); + ~MotorModelDatabase(); + + // No copies + MotorModelDatabase(const MotorModelDatabase&) = delete; + MotorModelDatabase(MotorModelDatabase&&) = delete; + MotorModelDatabase& operator=(const MotorModelDatabase&) = delete; + MotorModelDatabase& operator=(MotorModelDatabase&&) = delete; + + + /** + * @brief Adds a single MotorModel to the database. If that MotorModel already exists, it is + * replaced. + * + * @param model MotorModel to add + * + */ + void addMotorModel(const model::MotorModel& m); + + /** + * @brief Adds multiple motor models at once. Any duplicates already in the datbase are replaced. + * + * @param model MotorModels to add + * + */ + void addMotorModels(const std::vector& models); + + /** + * @brief Get the Motor Model by Common Name + * + * @param name Motor Common name + * @return std::optional + */ + std::optional getMotorModel(const std::string& name); +private: + + // The "database" is really just a map. :) + /// motorModelMap is keyed off of the motor commonName + std::map motorModelMap; + + + +}; + +} // namespace utils + +#endif // UTILS_MOTORMODELDATABASE_H \ No newline at end of file