diff --git a/.gitignore b/.gitignore index 045eed0..5b8a0ff 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ docs/doxygen/* # IDE qtrocket.pro.user .qmake.stash +CMakeLists.txt.user diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ec252c..bc3dc87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,12 @@ FetchContent_Declare(eigen GIT_TAG 3.4.0) FetchContent_MakeAvailable(eigen) +# boost dependency +FetchContent_Declare(Boost + GIT_REPOSITORY https://github.com/boostorg/boost + GIT_TAG boost-1.82.0) +FetchContent_MakeAvailable(Boost) + # Add qtrocket subdirectories. These are components that will be linked in @@ -63,7 +69,7 @@ set(CMAKE_AUTORCC ON) if(WIN32) set(CMAKE_PREFIX_PATH $ENV{QTDIR}) - include_directories("C:\\boost\\boost_1_82_0\\") +# include_directories("C:\\boost\\boost_1_82_0\\") # find_package(Qt6Core REQUIRED) # find_package(Qt6Widgets REQUIRED) endif() diff --git a/QtRocket.cpp b/QtRocket.cpp index 1fd1e9d..a42dadc 100644 --- a/QtRocket.cpp +++ b/QtRocket.cpp @@ -1,4 +1,3 @@ - /// \cond // C headers // C++ headers @@ -45,7 +44,7 @@ void guiWorker(int argc, char* argv[], int& ret) // Go! MainWindow w(QtRocket::getInstance()); - logger->info("Showing MainWindow"); + logger->debug("Showing MainWindow"); w.show(); ret = a.exec(); @@ -65,7 +64,7 @@ void QtRocket::init() std::lock_guard lck(mtx); if(!initialized) { - utils::Logger::getInstance()->info("Instantiating new QtRocket"); + utils::Logger::getInstance()->debug("Instantiating new QtRocket"); instance = new QtRocket(); initialized = true; } @@ -88,6 +87,13 @@ QtRocket::QtRocket() motorDatabase = std::make_shared(); + logger->debug("Initial states vector size: " + states.capacity() ); + // Reserve at least 1024 spaces for StateData + if(states.capacity() < 1024) + { + states.reserve(1024); + } + logger->debug("New states vector size: " + states.capacity() ); } int QtRocket::run(int argc, char* argv[]) @@ -122,3 +128,8 @@ void QtRocket::addMotorModels(std::vector& m) motorDatabase->addMotorModels(m); // TODO: Now clear any duplicates? } + +void QtRocket::appendState(const StateData& state) +{ + states.emplace_back(state); +} diff --git a/QtRocket.h b/QtRocket.h index d1c124b..613bfd3 100644 --- a/QtRocket.h +++ b/QtRocket.h @@ -15,12 +15,11 @@ // qtrocket headers #include "model/MotorModel.h" #include "model/Rocket.h" -#include "sim/AtmosphericModel.h" -#include "sim/GravityModel.h" #include "sim/Environment.h" #include "sim/Propagator.h" #include "utils/Logger.h" #include "utils/MotorModelDatabase.h" +#include "utils/math/MathTypes.h" /** * @brief The QtRocket class is the master controller for the QtRocket application. @@ -67,6 +66,8 @@ public: */ void setInitialState(const StateData& initState) { rocket.second->setInitialState(initState); } + void appendState(const StateData& state); + private: QtRocket(); @@ -84,6 +85,15 @@ private: std::shared_ptr environment; std::shared_ptr motorDatabase; + // Launch site + // ECEF coordinates + Vector3 launchSitePosition{0.0, 0.0, 0.0}; + + // Table of state data + std::vector states; + + + }; #endif // QTROCKET_H diff --git a/main.cpp b/main.cpp index 02d1e70..379e1b5 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,9 @@ - /// \cond // C headers // C++ headers // 3rd party headers /// \endcond - #include "QtRocket.h" #include "utils/Logger.h" @@ -14,13 +12,16 @@ int main(int argc, char *argv[]) // Instantiate logger utils::Logger* logger = utils::Logger::getInstance(); - logger->setLogLevel(utils::Logger::DEBUG_); + logger->setLogLevel(utils::Logger::PERF_); + logger->info("Logger instantiated at PERF level"); // instantiate QtRocket + logger->debug("Starting QtRocket"); QtRocket* qtrocket = QtRocket::getInstance(); // Run QtRocket. This'll start the GUI thread and block until the user // exits the program + logger->debug("QtRocket->run()"); int retVal = qtrocket->run(argc, argv); logger->debug("Returning"); return retVal; -} \ No newline at end of file +} diff --git a/model/Part.h b/model/Part.h index 03da6bf..434a65c 100644 --- a/model/Part.h +++ b/model/Part.h @@ -5,7 +5,6 @@ // C headers // C++ headers #include -#include #include // 3rd party headers @@ -13,7 +12,6 @@ // qtrocket headers #include "utils/math/MathTypes.h" -#include "model/Part.h" namespace model { @@ -120,4 +118,4 @@ private: } -#endif // MODEL_PART_H \ No newline at end of file +#endif // MODEL_PART_H diff --git a/model/Rocket.cpp b/model/Rocket.cpp index 3dafa4c..64d39be 100644 --- a/model/Rocket.cpp +++ b/model/Rocket.cpp @@ -1,7 +1,6 @@ // qtrocket headers #include "Rocket.h" -#include "QtRocket.h" namespace model { @@ -45,4 +44,4 @@ double Rocket::getMass(double t) return totalMass; } -} // namespace model \ No newline at end of file +} // namespace model diff --git a/model/Rocket.h b/model/Rocket.h index a7f2120..9949583 100644 --- a/model/Rocket.h +++ b/model/Rocket.h @@ -13,9 +13,7 @@ /// \endcond // qtrocket headers -#include "model/ThrustCurve.h" #include "sim/Propagator.h" -#include "utils/math/MathTypes.h" #include "model/Stage.h" #include "model/Propagatable.h" @@ -52,7 +50,7 @@ public: * @param t current simulation time * @return thrust in Newtons */ - double getThrust(double t); + double getThrust(double t) override; /** * @brief getMass returns current rocket diff --git a/model/Stage.cpp b/model/Stage.cpp index ab6a0c1..6d17794 100644 --- a/model/Stage.cpp +++ b/model/Stage.cpp @@ -1,8 +1,6 @@ /// \cond // C headers // C++ headers -#include -#include // 3rd party headers /// \endcond @@ -24,4 +22,4 @@ void Stage::setMotorModel(const model::MotorModel& motor) mm = motor; } -} // namespace model \ No newline at end of file +} // namespace model diff --git a/model/ThrustCurve.cpp b/model/ThrustCurve.cpp index fd7a803..8351d39 100644 --- a/model/ThrustCurve.cpp +++ b/model/ThrustCurve.cpp @@ -8,8 +8,6 @@ /// \endcond #include "model/ThrustCurve.h" -#include "utils/Logger.h" - ThrustCurve::ThrustCurve(std::vector>& tc) : thrustCurve(tc), diff --git a/sim/Aero.h b/sim/Aero.h index 08636f7..c57a778 100644 --- a/sim/Aero.h +++ b/sim/Aero.h @@ -4,7 +4,6 @@ /// \cond // C headers // C++ headers -#include // 3rd party headers /// \endcond @@ -38,4 +37,4 @@ private: }; } -#endif // SIM_AERO_H \ No newline at end of file +#endif // SIM_AERO_H diff --git a/sim/ConstantAtmosphere.h b/sim/ConstantAtmosphere.h index 226eead..2b33762 100644 --- a/sim/ConstantAtmosphere.h +++ b/sim/ConstantAtmosphere.h @@ -3,7 +3,6 @@ // qtrocket headers #include "AtmosphericModel.h" -#include "utils/math/Constants.h" namespace sim { diff --git a/sim/DESolver.h b/sim/DESolver.h index 54a4dee..f264e7c 100644 --- a/sim/DESolver.h +++ b/sim/DESolver.h @@ -4,13 +4,12 @@ /// \cond // C headers // C++ headers -#include +#include // 3rd party headers /// \endcond // qtrocket headers -#include "utils/math/MathTypes.h" namespace sim { diff --git a/sim/Environment.h b/sim/Environment.h index b866420..d6d759e 100644 --- a/sim/Environment.h +++ b/sim/Environment.h @@ -17,7 +17,6 @@ #include "sim/ConstantAtmosphere.h" #include "sim/USStandardAtmosphere.h" -#include "sim/GeoidModel.h" namespace sim { diff --git a/sim/Propagator.cpp b/sim/Propagator.cpp index 3b322d2..1ad0634 100644 --- a/sim/Propagator.cpp +++ b/sim/Propagator.cpp @@ -2,7 +2,6 @@ /// \cond // C headers // C++ headers -#include #include #include #include diff --git a/sim/RK4Solver.h b/sim/RK4Solver.h index 46a13ec..8365cad 100644 --- a/sim/RK4Solver.h +++ b/sim/RK4Solver.h @@ -4,10 +4,8 @@ /// \cond // C headers // C++ headers -#include #include #include -#include // 3rd party headers diff --git a/sim/USStandardAtmosphere.cpp b/sim/USStandardAtmosphere.cpp index 1081b00..c6a0cf3 100644 --- a/sim/USStandardAtmosphere.cpp +++ b/sim/USStandardAtmosphere.cpp @@ -18,9 +18,9 @@ namespace sim { // Populate static data -utils::BinMap initTemps() +utils::Bin initTemps() { - utils::BinMap map; + utils::Bin map; map.insert(std::make_pair(0.0, 288.15)); map.insert(std::make_pair(11000.0, 216.65)); map.insert(std::make_pair(20000.0, 216.65)); @@ -33,9 +33,9 @@ utils::BinMap initTemps() } -utils::BinMap initLapseRates() +utils::Bin initLapseRates() { - utils::BinMap map; + utils::Bin map; map.insert(std::make_pair(0.0, 0.0065)); map.insert(std::make_pair(11000.0, 0.0)); map.insert(std::make_pair(20000.0, -0.001)); @@ -47,9 +47,9 @@ utils::BinMap initLapseRates() return map; } -utils::BinMap initDensities() +utils::Bin initDensities() { - utils::BinMap map; + utils::Bin map; map.insert(std::make_pair(0.0, 1.225)); map.insert(std::make_pair(11000.0, 0.36391)); map.insert(std::make_pair(20000.0, 0.08803)); @@ -61,9 +61,9 @@ utils::BinMap initDensities() return map; } -utils::BinMap initPressures() +utils::Bin initPressures() { - utils::BinMap map; + utils::Bin map; map.insert(std::make_pair(0.0, 101325)); map.insert(std::make_pair(11000.0, 22632.1)); map.insert(std::make_pair(20000.0, 5474.89)); @@ -75,10 +75,10 @@ utils::BinMap initPressures() return map; } -utils::BinMap USStandardAtmosphere::temperatureLapseRate(initLapseRates()); -utils::BinMap USStandardAtmosphere::standardTemperature(initTemps()); -utils::BinMap USStandardAtmosphere::standardDensity(initDensities()); -utils::BinMap USStandardAtmosphere::standardPressure(initPressures()); +utils::Bin USStandardAtmosphere::temperatureLapseRate(initLapseRates()); +utils::Bin USStandardAtmosphere::standardTemperature(initTemps()); +utils::Bin USStandardAtmosphere::standardDensity(initDensities()); +utils::Bin USStandardAtmosphere::standardPressure(initPressures()); USStandardAtmosphere::USStandardAtmosphere() { diff --git a/sim/USStandardAtmosphere.h b/sim/USStandardAtmosphere.h index 740df66..3821295 100644 --- a/sim/USStandardAtmosphere.h +++ b/sim/USStandardAtmosphere.h @@ -3,7 +3,7 @@ // qtrocket headers #include "sim/AtmosphericModel.h" -#include "utils/BinMap.h" +#include "utils/Bin.h" namespace sim { @@ -33,10 +33,10 @@ public: double getDynamicViscosity(double altitude) override; private: - static utils::BinMap temperatureLapseRate; - static utils::BinMap standardTemperature; - static utils::BinMap standardDensity; - static utils::BinMap standardPressure; + static utils::Bin temperatureLapseRate; + static utils::Bin standardTemperature; + static utils::Bin standardDensity; + static utils::Bin standardPressure; }; diff --git a/utils/BinMap.cpp b/utils/Bin.cpp similarity index 91% rename from utils/BinMap.cpp rename to utils/Bin.cpp index 5ebe68b..5130bd1 100644 --- a/utils/BinMap.cpp +++ b/utils/Bin.cpp @@ -11,7 +11,7 @@ /// \endcond // qtrocket headers -#include "BinMap.h" +#include "Bin.h" // TODO: Check on the availability of this in Clang. // Replace libfmt with format when LLVM libc++ supports it @@ -20,33 +20,33 @@ namespace utils { -BinMap::BinMap() +Bin::Bin() : bins() { } -BinMap::BinMap(BinMap&& o) +Bin::Bin(Bin&& o) : bins(std::move(o.bins)) { } -BinMap::~BinMap() +Bin::~Bin() { } // TODO: Very low priority, but if anyone wants to make this more efficient it could be // interesting -void BinMap::insert(const std::pair& toInsert) +void Bin::insert(const std::pair& toInsert) { bins.push_back(toInsert); std::sort(bins.begin(), bins.end(), [](const auto& a, const auto& b){ return a.first < b.first; }); } -double BinMap::operator[](double key) +double Bin::operator[](double key) { auto iter = bins.begin(); // If the key is less than the lowest bin value, then it is out of range @@ -74,7 +74,7 @@ double BinMap::operator[](double key) return retVal; } -double BinMap::getBinBase(double key) +double Bin::getBinBase(double key) { auto iter = bins.begin(); // If the key is less than the lowest bin value, then it is out of range diff --git a/utils/BinMap.h b/utils/Bin.h similarity index 86% rename from utils/BinMap.h rename to utils/Bin.h index 216cd7d..86843b0 100644 --- a/utils/BinMap.h +++ b/utils/Bin.h @@ -1,5 +1,5 @@ -#ifndef UTILS_BINMAP_H -#define UTILS_BINMAP_H +#ifndef UTILS_BIN_H +#define UTILS_BIN_H /// \cond // C headers @@ -22,12 +22,12 @@ namespace utils { * @todo Make this class behave more like a proper STL container. Templetize it for one * */ -class BinMap +class Bin { public: - BinMap(); - BinMap(BinMap&& o); - ~BinMap(); + Bin(); + Bin(Bin&& o); + ~Bin(); void insert(const std::pair& toInsert); double operator[](double key); @@ -40,4 +40,4 @@ private: } // namespace utils -#endif // UTILS_BINMAP_H +#endif // UTILS_BIN_H diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index eebe01d..c748e02 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(utils - BinMap.cpp - BinMap.h + Bin.cpp + Bin.h CurlConnection.cpp CurlConnection.h Logger.cpp @@ -18,6 +18,10 @@ add_library(utils math/MathTypes.h math/UtilityMathFunctions.h) + +target_include_directories(utils PRIVATE + ${Boost_INCLUDE_DIR}) + target_link_libraries(utils PUBLIC libcurl jsoncpp_static diff --git a/utils/Logger.cpp b/utils/Logger.cpp index bce72dc..2860874 100644 --- a/utils/Logger.cpp +++ b/utils/Logger.cpp @@ -40,6 +40,13 @@ void Logger::log(std::string_view msg, const LogLevel& lvl) // all levels at or lower than the current level. switch(currentLevel) { + case PERF_: + if(lvl == PERF_) + { + outFile << "[PERF] " << msg << std::endl; + std::cout << "[PERF] " << msg << "\n"; + } + [[fallthrough]]; case DEBUG_: if(lvl == DEBUG_) { diff --git a/utils/Logger.h b/utils/Logger.h index 18c7467..752baf8 100644 --- a/utils/Logger.h +++ b/utils/Logger.h @@ -25,7 +25,8 @@ public: ERROR_, WARN_, INFO_, - DEBUG_ + DEBUG_, + PERF_ }; static Logger* getInstance(); @@ -38,16 +39,11 @@ public: void setLogLevel(const LogLevel& lvl); - /* - std::function error; - std::function warn; - std::function info; - std::function debug; - */ inline void error(std::string_view msg) { log(msg, ERROR_); } inline void warn(std::string_view msg) { log(msg, WARN_); } inline void info(std::string_view msg) { log(msg, INFO_); } inline void debug(std::string_view msg) { log(msg, DEBUG_); } + inline void perf(std::string_view msg) { log(msg, PERF_); } void log(std::ostream& o, const std::string& msg);