From ba144bacd6f1d95aa9891dfb123da4e70ed8a957 Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Tue, 25 Jan 2022 17:38:00 +0100 Subject: [PATCH 1/5] added minimal example to cmake --- README.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80c0dd6..1261b3d 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ it produces both, either of them or none (see YAML Configuration File) | j | Ejection Velocity [m/s] | | | | p | Position [m] | | | -## Library +## How to use the project as a library The Breakup Simulation can be used directly from any C++ project without the need of file input, etc. To create a new Breakup Simulation just follow these four steps: @@ -201,17 +201,78 @@ To create a new Breakup Simulation just follow these four steps: 3. Create your Breakup Simulation 4. Run and get the Result! -Example: +### Example CMake integration: +```cmake +cmake_minimum_required(VERSION 3.16) +project(FOO) +# ------------------------- get the breakup model ------------------------- +# Enable ExternalProject CMake module +include(FetchContent) + +# OPTIONAL: disable stuff not needed when used as a lib +set(BUILD_BREAKUP_MODEL_TESTS OFF CACHE INTERNAL "") +set(BUILD_BREAKUP_MODEL_SIM OFF CACHE INTERNAL "") + +FetchContent_Declare( + BreakupModelfetch + GIT_REPOSITORY git@github.com:esa/NASA-breakup-model-cpp.git + # GIT_TAG master +) + +# Get Breakup Model source and binary directories from CMake project +FetchContent_MakeAvailable(BreakupModelfetch) + +# OPTIONAL: Disable potential warnings +# from the library target +target_compile_options(breakupModel_lib PRIVATE -w) +# from included headers +get_target_property(propval breakupModel_lib INTERFACE_INCLUDE_DIRECTORIES) +target_include_directories(breakupModel_lib SYSTEM PUBLIC "${propval}") + +# -------------------- define your target and link it --------------------- + +add_executable(fooExe foo.cpp) +target_compile_features(fooExe PUBLIC cxx_std_17) +target_link_libraries(fooExe PUBLIC breakupModel_lib) +``` + +### Example C++ Code integration: ```cpp - //RuntimeInput via the RuntimeInputSource Object (minmial Config: minL_c = 0.05 + inputSatellites) +#include +#include +#include +#include + +int main() { + // generate satellites to collide + SatelliteBuilder satelliteBuilder; + std::vector satellites{ + satelliteBuilder + .setID(0) + .setPosition({0.,0.,0.}) // [m] + .setVelocity({0.,1.,0.}) // [m/s^2] + .setMass(500.) // [kg] + .getResult(), + satelliteBuilder + .setID(1) + .setPosition({0.,0.,0.}) // [m] + .setVelocity({0.,0.,1.}) // [m/s^2] + .setMass(500.) // [kg] + .getResult(), + }; + + // Minimal RuntimeInputSource only with minLc = 0.05 [m] and all involved satellites. auto configSource = std::make_shared(0.05, satellites); - //Give the BreakupBuilder its configuration object (YMALConfigurationReader or RuntimeInputSource or your own derived source) + // Initialize a BreakupBuilder with a configuration object + // (YMALConfigurationReader or RuntimeInputSource or your own derived source) BreakupBuilder breakupBuilder{configSource}; - //Create the Breakup Simulation + // Create the actual breakup simulation auto breakup = breakupBuilder.getBreakup(); - //Run it and get the result via breakup.getResult(); + // Run it and collect the result breakup->run(); + std::vector debris = breakup->getResult(); +} ``` ## Testing The tests use the framework GoogleTest and From 839a493369834e671e2fc83ad33bb811afff2c50 Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Thu, 27 Jan 2022 08:27:32 +0100 Subject: [PATCH 2/5] explicitly link example in readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1261b3d..fad3a49 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,8 @@ To create a new Breakup Simulation just follow these four steps: 3. Create your Breakup Simulation 4. Run and get the Result! +For further examples see [main.cpp](src/main.cpp) and the provided [example configurarions](example-config). + ### Example CMake integration: ```cmake cmake_minimum_required(VERSION 3.16) From 734f84b644ec25d2ecbcb313011e2cf896529421 Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Thu, 27 Jan 2022 11:51:03 +0100 Subject: [PATCH 3/5] explain how number of satellites is used to infer simulation type --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fad3a49..dd53174 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,9 @@ The given yaml-file should look like this: simulation: minimalCharacteristicLength: 0.05 #minimal fragment L_c in [m] simulationType: COLLISION #Option (Alias): COLLISION (CO) or EXPLOSION (EX) - #If not given type is determined - # by number of input satellites + #If not given, type is determined by number of (filtered) + #input satellites (1: EX, 2: CO, >2: Exception) currentMaxID: 48514 #For determining fragment ID - #Should be the currently largest given NORAD-Catalog ID #If not given, zero is assumed inputSource: ["../data.yaml"] #Path to input file(s) - One of the following: From 23813836f483b29813dd50d4a0cb432c1561334a Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Thu, 27 Jan 2022 12:14:29 +0100 Subject: [PATCH 4/5] mention idFilter in example code --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index dd53174..8d8d95e 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,9 @@ target_link_libraries(fooExe PUBLIC breakupModel_lib) int main() { // generate satellites to collide SatelliteBuilder satelliteBuilder; + // The number of Satellites determines the type of the simulation + // Add an idFilter to your config to only consider one or two satellites. + // (See brief-overview-on-the-available-options) std::vector satellites{ satelliteBuilder .setID(0) From c3406362f59a7f2e4ee447623bd7b16861254ee7 Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Thu, 27 Jan 2022 12:15:15 +0100 Subject: [PATCH 5/5] more consistent punctuation --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8d8d95e..09a8947 100644 --- a/README.md +++ b/README.md @@ -246,11 +246,11 @@ target_link_libraries(fooExe PUBLIC breakupModel_lib) #include int main() { - // generate satellites to collide + // Generate satellites to collide. SatelliteBuilder satelliteBuilder; - // The number of Satellites determines the type of the simulation + // The number of Satellites determines the type of the simulation. // Add an idFilter to your config to only consider one or two satellites. - // (See brief-overview-on-the-available-options) + // (See brief-overview-on-the-available-options.) std::vector satellites{ satelliteBuilder .setID(0) @@ -268,12 +268,12 @@ int main() { // Minimal RuntimeInputSource only with minLc = 0.05 [m] and all involved satellites. auto configSource = std::make_shared(0.05, satellites); - // Initialize a BreakupBuilder with a configuration object - // (YMALConfigurationReader or RuntimeInputSource or your own derived source) + // Initialize a BreakupBuilder with a configuration object. + // (YMALConfigurationReader or RuntimeInputSource or your own derived source.) BreakupBuilder breakupBuilder{configSource}; - // Create the actual breakup simulation + // Create the actual breakup simulation. auto breakup = breakupBuilder.getBreakup(); - // Run it and collect the result + // Run it and collect the result. breakup->run(); std::vector debris = breakup->getResult(); }