open-simulation-platform / libcosim

OSP C++ co-simulation library
https://open-simulation-platform.github.io/libcosim
Mozilla Public License 2.0
61 stars 10 forks source link

Transfer variables after initialisation #766

Closed kyllingstad closed 5 months ago

kyllingstad commented 5 months ago

fixed_step_algorithm::initialize() ends by calling simulator::start_simulation(), which, for an FMI 2.0 FMU ends up calling fmi2ExitInitializationMode(). This function is not prohibited from modifying variable values, which means that we must assume that it does. Previously we did not, and this has led to issue #609, which to me looks like a pretty severe correctness issue. Here, I've added get_variables() and set_variables() calls at additional points in the call sequence of a slave_simulator() where variable values may have changed, and I've added a variable transfer at the end of fixed_step_algorithm::initialize().

I've run the quarter-truck case to verify that these changes actually do fix #609:

issue-609-before-after

The PR also fixes #762 (in the same way that PR #765 does – they have a common change in slave_simulator.cpp).