Skip to content

Commit

Permalink
Fix bug and get rid of warnings in ECCO algorithm
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kyllingstad committed Sep 21, 2023
1 parent 69a407c commit 458119a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cosim/algorithm/ecco_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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;
}
}
Expand All @@ -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);
Expand Down

0 comments on commit 458119a

Please sign in to comment.