fix: handle state events for ME2/ME3 on consecutive simulations#412
Open
jschueller wants to merge 1 commit into
Open
fix: handle state events for ME2/ME3 on consecutive simulations#412jschueller wants to merge 1 commit into
jschueller wants to merge 1 commit into
Conversation
…initialize=False When continuing a simulation with initialize=False (e.g. after set_fmu_state() + input changes), the FMU must process potential state events before resuming integration. The FMI spec requires calling fmi2NewDiscreteStates / fmi3UpdateDiscreteStates after fmi2SetFMUstate since restored state + new inputs may trigger events. Previously, time-event checks at start time only covered ME1 and used unreliable event_info flags. PR modelon-community#109's unconditional event_update() was too aggressive because it ran on the initialize=True path too, where event_update was already called during init, violating the FMI state machine. This fix: - For initialize=False with ME2/ME3: enter_event_mode + event_update + enter_continuous_time_mode to process pending events (e.g. after set_fmu_state + input changes) - For initialize=True with ME2/ME3: extend the existing time-event check (equivalent to the ME1 check that was already in place) with proper mode transition wrappers - ME1 behavior unchanged - Add enter_event_mode() no-op override to Dummy_FMUModelME2 to prevent segfault when algorithm driver calls enter_event_mode() on test stubs Fixes modelon-community#159 Tests added: - test_fmi2.py::test_consecutive_simulation_with_initialize_false - test_fmi3_sim.py::TestSimulation::test_consecutive_simulation_with_initialize_false
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When continuing a simulation with initialize=False (e.g. after set_fmu_state()
Previously, time-event checks at start time only covered ME1 and used unreliable event_info flags. PR #109's unconditional event_update() was too aggressive because it ran on the initialize=True path too, where event_update was already called during init, violating the FMI state machine.
This fix:
Fixes #159
Tests added: