21
21
22
22
#include < chrono>
23
23
#include < memory>
24
+ #include < variant>
25
+ #include < type_traits>
24
26
25
27
26
28
void run_subcommand::setup_options (
@@ -72,6 +74,12 @@ void run_subcommand::setup_options(
72
74
namespace
73
75
{
74
76
77
+ template <class ... Ts>
78
+ struct overloaded : Ts... { using Ts::operator ()...; };
79
+
80
+ template <class ... Ts>
81
+ overloaded (Ts...) -> overloaded<Ts...>;
82
+
75
83
cosim::execution load_system_structure (
76
84
const cosim::filesystem::path& path,
77
85
cosim::model_uri_resolver& uriResolver,
@@ -82,9 +90,19 @@ cosim::execution load_system_structure(
82
90
(cosim::filesystem::is_directory (path) &&
83
91
cosim::filesystem::exists (path / " OspSystemStructure.xml" ))) {
84
92
const auto config = cosim::load_osp_config (path, uriResolver);
85
- auto execution = cosim::execution (
86
- startTime,
87
- std::make_shared<cosim::fixed_step_algorithm>(config.step_size , workerThreadCount));
93
+ std::shared_ptr<cosim::algorithm> algorithm;
94
+
95
+ std::visit (
96
+ overloaded{
97
+ [&algorithm, &workerThreadCount](const cosim::fixed_step_algorithm_params& params) {
98
+ algorithm = std::make_shared<cosim::fixed_step_algorithm>(params, workerThreadCount);
99
+ },
100
+ [&algorithm, &workerThreadCount](const cosim::ecco_algorithm_params& params) {
101
+ algorithm = std::make_shared<cosim::ecco_algorithm>(params, workerThreadCount);
102
+ }},
103
+ config.algorithm_configuration );
104
+
105
+ auto execution = cosim::execution (startTime, algorithm);
88
106
cosim::inject_system_structure (
89
107
execution,
90
108
config.system_structure ,
@@ -154,6 +172,7 @@ class progress_monitor : public cosim::observer
154
172
: logger_(startTime, duration, percentIncrement, mrProgressResolution)
155
173
{}
156
174
175
+
157
176
private:
158
177
void simulator_added (cosim::simulator_index, cosim::observable*, cosim::time_point) override {}
159
178
void simulator_removed (cosim::simulator_index, cosim::time_point) override {}
@@ -184,6 +203,8 @@ class progress_monitor : public cosim::observer
184
203
override
185
204
{}
186
205
206
+ void state_restored (cosim::step_number, cosim::time_point) override {}
207
+
187
208
progress_logger logger_;
188
209
};
189
210
} // namespace
0 commit comments