From 458119a447c519f15757195078863f19b4518e11 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 21 Sep 2023 07:55:53 +0200 Subject: [PATCH] Fix bug and get rid of warnings in ECCO algorithm An implementation of `algorithm::do_step()` is supposed to return the length of the step that was taken by the algorithm. In our ECCO implementation, it instead returned the size of the *next* step. This commit fixes that, plus gets rid of a couple of signed-unsigned comparison warnings. --- src/cosim/algorithm/ecco_algorithm.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cosim/algorithm/ecco_algorithm.cpp b/src/cosim/algorithm/ecco_algorithm.cpp index 76b03133..4c14e00f 100644 --- a/src/cosim/algorithm/ecco_algorithm.cpp +++ b/src/cosim/algorithm/ecco_algorithm.cpp @@ -240,7 +240,10 @@ class ecco_algorithm::impl throw error(make_error_code(errc::simulation_error), errMessages.str()); } - stepSize_ = adjust_step_size(currentT, stepSize_, params_); + const auto stepSizeTaken = stepSize_; + if (stepCounter_ >= 2) { + stepSize_ = adjust_step_size(currentT, stepSize_, params_); + } // Transfer the outputs from simulators that have finished their // individual time steps within this co-simulation time step. @@ -260,7 +263,7 @@ class ecco_algorithm::impl } - return {stepSize_, std::move(finished)}; + return {stepSizeTaken, std::move(finished)}; } void set_stepsize_decimation_factor(cosim::simulator_index i, int factor) @@ -271,7 +274,7 @@ class ecco_algorithm::impl void print_average_energies() { - for (int i = 0; i < energies_.size(); ++i) { + for (std::size_t i = 0; i < energies_.size(); ++i) { std::cout << "Avg energy for sim idx " << i << ": " << get_mean(energies_.at(i)) << std::endl; } } @@ -283,7 +286,7 @@ class ecco_algorithm::impl const auto dt = to_double_duration(stepSize, currentTime); - for (int i = 0; i < uVariables_.size(); i+=2) { + for (std::size_t i = 0; i < uVariables_.size(); i+=2) { auto u_a = uVariables_.at(i); auto u_b = uVariables_.at(i+1); auto y_a = yVariables_.at(i);