Repository navigation
Commit 05adda9
committed
fix: handle state events for ME2/ME3 on consecutive simulations with 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
Fixes modelon-community#72
Closes modelon-community#109
Tests added:
- test_fmi2.py::test_consecutive_simulation_with_initialize_false
- test_fmi3_sim.py::TestSimulation::test_consecutive_simulation_with_initialize_false1 parent 67d63ff commit 05adda9
4 files changed
Lines changed: 50 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
| 377 | + | |
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
382 | 393 | | |
383 | 394 | | |
384 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
399 | 402 | | |
400 | 403 | | |
401 | 404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1126 | 1126 | | |
1127 | 1127 | | |
1128 | 1128 | | |
1129 | | - | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
0 commit comments