diff --git a/CMakeLists.txt b/CMakeLists.txt index b4932ee..2ec252c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,15 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) +# Google Test framework +FetchContent_Declare(googletest + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG v1.13.0) +if(WIN32) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +endif() +FetchContent_MakeAvailable(googletest) + # fmtlib dependency FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt @@ -91,52 +100,6 @@ set(PROJECT_SOURCES gui/ThrustCurveMotorSelector.ui gui/qcustomplot.cpp gui/qcustomplot.h - model/MotorModel.cpp - model/MotorModel.h - model/MotorModelDatabase.cpp - model/MotorModelDatabase.h - model/Rocket.cpp - model/Rocket.h - model/ThrustCurve.cpp - model/ThrustCurve.h - sim/AtmosphericModel.h - sim/ConstantAtmosphere.h - sim/ConstantGravityModel.h - sim/DESolver.h - sim/Environment.h - sim/GeoidModel.h - sim/GravityModel.h - sim/Propagator.cpp - sim/Propagator.h - sim/RK4Solver.h - sim/SphericalGeoidModel.cpp - sim/SphericalGeoidModel.h - sim/SphericalGravityModel.cpp - sim/SphericalGravityModel.h - sim/StateData.h - sim/TestRK4Solver.h - sim/USStandardAtmosphere.cpp - sim/USStandardAtmosphere.h - sim/WindModel.cpp - sim/WindModel.h - utils/BinMap.cpp - utils/BinMap.h - utils/CurlConnection.cpp - utils/CurlConnection.h - utils/Logger.cpp - utils/Logger.h - utils/MotorModelDatabase.cpp - utils/MotorModelDatabase.h - utils/RSEDatabaseLoader.cpp - utils/RSEDatabaseLoader.h - utils/ThreadPool.cpp - utils/ThreadPool.h - utils/ThrustCurveAPI.cpp - utils/ThrustCurveAPI.h - utils/TSQueue.h - utils/math/Constants.h - utils/math/MathTypes.h - utils/math/UtilityMathFunctions.h ${TS_FILES} ) @@ -167,7 +130,24 @@ else() endif() -target_link_libraries(qtrocket PRIVATE Qt6::Widgets Qt6::PrintSupport libcurl jsoncpp_static fmt::fmt-header-only eigen) +add_subdirectory(utils) +add_subdirectory(sim) +add_subdirectory(model) + +#target_link_libraries(qtrocket PRIVATE +# Qt6::Widgets +# Qt6::PrintSupport +# libcurl +# jsoncpp_static +# fmt::fmt-header-only +# eigen) + +target_link_libraries(qtrocket PRIVATE + Qt6::Widgets + Qt6::PrintSupport + utils + sim + model) set_target_properties(qtrocket PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com diff --git a/model/CMakeLists.txt b/model/CMakeLists.txt new file mode 100644 index 0000000..bdac965 --- /dev/null +++ b/model/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(model + MotorModel.cpp + MotorModel.h + MotorModelDatabase.cpp + MotorModelDatabase.h + Rocket.cpp + Rocket.h + ThrustCurve.cpp + ThrustCurve.h) + +target_link_libraries(model PRIVATE + utils) diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt new file mode 100644 index 0000000..41e05e5 --- /dev/null +++ b/sim/CMakeLists.txt @@ -0,0 +1,26 @@ +add_library(sim + AtmosphericModel.h + ConstantAtmosphere.h + ConstantGravityModel.h + DESolver.h + Environment.h + GeoidModel.h + GravityModel.h + Propagator.cpp + Propagator.h + RK4Solver.h + SphericalGeoidModel.cpp + SphericalGeoidModel.h + SphericalGravityModel.cpp + SphericalGravityModel.h + StateData.h + USStandardAtmosphere.cpp + USStandardAtmosphere.h + WindModel.cpp + WindModel.h) + +target_link_libraries(sim PRIVATE + utils) + +# Unit tests +add_subdirectory(tests) diff --git a/sim/USStandardAtmosphere.cpp b/sim/USStandardAtmosphere.cpp index c73d729..83e4753 100644 --- a/sim/USStandardAtmosphere.cpp +++ b/sim/USStandardAtmosphere.cpp @@ -10,6 +10,7 @@ // qtrocket headers #include "sim/USStandardAtmosphere.h" #include "utils/math/Constants.h" +#include "utils/math/UtilityMathFunctions.h" using namespace utils::math; @@ -35,13 +36,13 @@ utils::BinMap initTemps() utils::BinMap initLapseRates() { utils::BinMap map; - map.insert(std::make_pair(0.0, 0.0065)); + 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)); - map.insert(std::make_pair(32000.0, -0.0028)); + map.insert(std::make_pair(20000.0, 0.001)); + map.insert(std::make_pair(32000.0, 0.0028)); map.insert(std::make_pair(47000.0, 0.0)); - map.insert(std::make_pair(51000.0, 0.0028)); - map.insert(std::make_pair(71000.0, 0.002)); + map.insert(std::make_pair(51000.0, -0.0028)); + map.insert(std::make_pair(71000.0, -0.002)); return map; } @@ -78,7 +79,7 @@ USStandardAtmosphere::~USStandardAtmosphere() double USStandardAtmosphere::getDensity(double altitude) { - if(temperatureLapseRate[altitude] == 0.0) + if(utils::math::floatingPointEqual(temperatureLapseRate[altitude], 0.0)) { return standardDensity[altitude] * std::exp((-Constants::g0 * Constants::airMolarMass * (altitude - standardDensity.getBinBase(altitude))) / (Constants::Rstar * standardTemperature[altitude])); @@ -86,11 +87,10 @@ double USStandardAtmosphere::getDensity(double altitude) } else { - double base = standardTemperature[altitude] / - (standardTemperature[altitude] + temperatureLapseRate[altitude] * (altitude - standardDensity.getBinBase(altitude))); + double base = (standardTemperature[altitude] - temperatureLapseRate[altitude] * (altitude - standardDensity.getBinBase(altitude))) / standardTemperature[altitude]; - double exponent = 1 + (Constants::g0 * Constants::airMolarMass) / - (Constants::Rstar * temperatureLapseRate[altitude]); + double exponent = (Constants::g0 * Constants::airMolarMass) / + (Constants::Rstar * temperatureLapseRate[altitude]) - 1.0; return standardDensity[altitude] * std::pow(base, exponent); diff --git a/sim/tests/CMakeLists.txt b/sim/tests/CMakeLists.txt new file mode 100644 index 0000000..f928cd9 --- /dev/null +++ b/sim/tests/CMakeLists.txt @@ -0,0 +1,14 @@ +enable_testing() + +add_executable(sim_tests + USStandardAtmosphereTests.cpp +) + +target_link_libraries(sim_tests + sim + GTest::gtest_main +) + +include(GoogleTest) +gtest_discover_tests(sim_tests) + diff --git a/sim/tests/USStandardAtmosphereTests.cpp b/sim/tests/USStandardAtmosphereTests.cpp new file mode 100644 index 0000000..1424232 --- /dev/null +++ b/sim/tests/USStandardAtmosphereTests.cpp @@ -0,0 +1,29 @@ +#include + +#include "sim/USStandardAtmosphere.h" + +TEST(USStandardAtmosphereTests, DensityTests) +{ + sim::USStandardAtmosphere atmosphere; + + EXPECT_DOUBLE_EQ(atmosphere.getDensity(0.0), 1.225); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(1000.0), 1.112); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(2000.0), 1.007); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(3000.0), 0.9093); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(4000.0), 0.8194); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(5000.0), 0.7364); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(6000.0), 0.6601); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(7000.0), 0.5900); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(8000.0), 0.5258); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(9000.0), 0.4647); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(10000.0), 0.4135); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(15000.0), 0.1948); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(20000.0), 0.08891); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(25000.0), 0.04008); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(30000.0), 0.01841); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(40000.0), 0.003996); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(50000.0), 0.001027); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(60000.0), 0.0003097); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(70000.0), 0.00008283); + EXPECT_DOUBLE_EQ(atmosphere.getDensity(80000.0), 0.00001846); +} diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 0000000..eebe01d --- /dev/null +++ b/utils/CMakeLists.txt @@ -0,0 +1,25 @@ +add_library(utils + BinMap.cpp + BinMap.h + CurlConnection.cpp + CurlConnection.h + Logger.cpp + Logger.h + MotorModelDatabase.cpp + MotorModelDatabase.h + RSEDatabaseLoader.cpp + RSEDatabaseLoader.h + ThreadPool.cpp + ThreadPool.h + ThrustCurveAPI.cpp + ThrustCurveAPI.h + TSQueue.h + math/Constants.h + math/MathTypes.h + math/UtilityMathFunctions.h) + +target_link_libraries(utils PUBLIC + libcurl + jsoncpp_static + fmt::fmt-header-only + eigen)