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

Simulate until allows single steps to be taken after end time is passed and "stopped" flag is not reversed if simulate_until ends by timeout #654

Closed msteinsto closed 3 years ago

msteinsto commented 3 years ago

Current do-loop implementation of simulate_until() allows single steps to be taken after end time is exceeded if the optional end time is provided. It would probably be more intuitive that the simulation will only step if the end time is not exceeded. The step function can be used if a single simulation step is the intended behavior.

Furthermore, the stopped_ flag is not reset if the simulate_until() function is ended by timeout. is_running() is determined by the inverse of the stopped_ flag. The simulation then ends up in a state where it is effectively paused as it is no longer stepping while the indicated state accessed by is_running() will return true. is_running() is documented as "Is the simulation loop currently running" which it will not be if the simulate_until() while loop is ended by time_out() returning true. stop_simulation() is documented as "Stops the co-simulation temporarily" which should probably be called after the simulate_until() function has successfully completed all steps. stop_simulation() sets the stopped_ flag to true.