From 299fc3de71b46413d3a640980aeeb2e28f44fc5d Mon Sep 17 00:00:00 2001 From: David Heejong Park Date: Thu, 15 May 2025 14:31:16 +0200 Subject: [PATCH 1/2] Update libcosim to 0.11.1 --- CMakeLists.txt | 1 + conanfile.py | 2 +- src/run.cpp | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73f603a..381b15f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ endif() # Dependencies # ============================================================================== +find_package(libcbor REQUIRED) find_package(libcosim REQUIRED) find_package(Boost REQUIRED COMPONENTS log program_options) diff --git a/conanfile.py b/conanfile.py index bbae563..b0bff77 100644 --- a/conanfile.py +++ b/conanfile.py @@ -13,7 +13,7 @@ def requirements(self): self.tool_requires("cmake/[>=3.19]") if self.settings.os == "Linux": self.tool_requires("patchelf/[<0.18]") - self.requires("libcosim/0.10.4@osp/stable") + self.requires("libcosim/0.11.1@osp/stable") self.requires("boost/[>=1.71]") def layout(self): diff --git a/src/run.cpp b/src/run.cpp index ef74339..a5d4d27 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -82,9 +82,18 @@ cosim::execution load_system_structure( (cosim::filesystem::is_directory(path) && cosim::filesystem::exists(path / "OspSystemStructure.xml"))) { const auto config = cosim::load_osp_config(path, uriResolver); - auto execution = cosim::execution( - startTime, - std::make_shared(config.step_size, workerThreadCount)); + std::shared_ptr algorithm; + + std::visit([&algorithm, &config, &workerThreadCount](auto&& value) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + algorithm = std::make_shared(std::get(config.algorithm_configuration), workerThreadCount); + } else if constexpr (std::is_same_v) { + algorithm = std::make_shared(std::get(config.algorithm_configuration), workerThreadCount); + } + }, config.algorithm_configuration); + + auto execution = cosim::execution(startTime, algorithm); cosim::inject_system_structure( execution, config.system_structure, @@ -154,6 +163,7 @@ class progress_monitor : public cosim::observer : logger_(startTime, duration, percentIncrement, mrProgressResolution) {} + private: void simulator_added(cosim::simulator_index, cosim::observable*, cosim::time_point) override {} void simulator_removed(cosim::simulator_index, cosim::time_point) override {} @@ -184,6 +194,8 @@ class progress_monitor : public cosim::observer override {} + void state_restored(cosim::step_number, cosim::time_point) override {} + progress_logger logger_; }; } // namespace From 03d9070d9a64230015b0bae70c8c2cd3e966dc43 Mon Sep 17 00:00:00 2001 From: David Heejong Park Date: Thu, 15 May 2025 15:24:48 +0200 Subject: [PATCH 2/2] Update to visitor --- src/run.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/run.cpp b/src/run.cpp index a5d4d27..dc9f7ba 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -21,6 +21,8 @@ #include #include +#include +#include void run_subcommand::setup_options( @@ -72,6 +74,12 @@ void run_subcommand::setup_options( namespace { +template +struct overloaded : Ts... { using Ts::operator()...; }; + +template +overloaded(Ts...) -> overloaded; + cosim::execution load_system_structure( const cosim::filesystem::path& path, cosim::model_uri_resolver& uriResolver, @@ -84,14 +92,15 @@ cosim::execution load_system_structure( const auto config = cosim::load_osp_config(path, uriResolver); std::shared_ptr algorithm; - std::visit([&algorithm, &config, &workerThreadCount](auto&& value) { - using T = std::decay_t; - if constexpr (std::is_same_v) { - algorithm = std::make_shared(std::get(config.algorithm_configuration), workerThreadCount); - } else if constexpr (std::is_same_v) { - algorithm = std::make_shared(std::get(config.algorithm_configuration), workerThreadCount); - } - }, config.algorithm_configuration); + std::visit( + overloaded{ + [&algorithm, &workerThreadCount](const cosim::fixed_step_algorithm_params& params) { + algorithm = std::make_shared(params, workerThreadCount); + }, + [&algorithm, &workerThreadCount](const cosim::ecco_algorithm_params& params) { + algorithm = std::make_shared(params, workerThreadCount); + }}, + config.algorithm_configuration); auto execution = cosim::execution(startTime, algorithm); cosim::inject_system_structure(