Skip to content

ME FMU without continuous states crashes #403

@cbu-hw

Description

@cbu-hw

We have a ME FMU that (accidentally) had no continuous states, and simulating this crashes Python. The FMU simulates correctly using fmpy and OMSimulator.

The model:

model ElastoGapMWE
  Modelica.Mechanics.Translational.Components.ElastoGap elastoGap(s_rel(start = 0), c = 100, d = 0)  annotation(
    Placement(transformation(origin = {26, 14}, extent = {{-10, -10}, {10, 10}})));
  Modelica.Mechanics.Translational.Components.Fixed fixed annotation(
    Placement(transformation(origin = {68, -4}, extent = {{-10, -10}, {10, 10}})));
  Modelica.Mechanics.Translational.Sources.Position position(exact = true)  annotation(
    Placement(transformation(origin = {-20, 14}, extent = {{-10, -10}, {10, 10}})));
  Modelica.Blocks.Sources.Sine sine(f = 1, continuous = true)  annotation(
    Placement(transformation(origin = {-70, 14}, extent = {{-10, -10}, {10, 10}})));
equation
  connect(position.flange, elastoGap.flange_a) annotation(
    Line(points = {{-10, 14}, {16, 14}}, color = {0, 127, 0}));
  connect(elastoGap.flange_b, fixed.flange) annotation(
    Line(points = {{36, 14}, {68, 14}, {68, -4}}, color = {0, 127, 0}));
  connect(sine.y, position.s_ref) annotation(
    Line(points = {{-59, 14}, {-32, 14}}, color = {0, 0, 127}));
  annotation(
    uses(Modelica(version = "4.1.0")),
  experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
end ElastoGapMWE;

Export this as an ME FMU.

Python reproducer script:

import faulthandler
import pyfmi
import assimulo

print(f'{pyfmi.__version__=}') # 2.21.0
print(f'{assimulo.__version__=}') # 3.7.3
faulthandler.enable()  # Enable Python to print a traceback on crashing

model = pyfmi.load_fmu('ElastoGapMWE.fmu', kind='ME', log_level=6)
print(model.simulate_options())
print(f'{model.continuous_states=}\n')

model.simulate(final_time=1.0) # crashes, following print never occurs
print("Finished simulation")

Run the Python script. Note that the continuous_states array is empty.
Observe a crash:

Windows fatal exception: access violation

Current thread 0x0000778c (most recent call first):
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\pyfmi\fmi_algorithm_drivers.py", line 672 in solve
  File "C:\<path-to>\mwe_pyfmi.py", line 16 in <module>

Expected behaviour: Complete the simulation successfully

Versions
pyfmi 2.21.0
assimulo 3.7.3
Windows 11, Python 3.12
FMU generated with OpenModelica v1.27.0-dev-330-g5f16e75445

Related issues: #76, #92, OpenModelica/OpenModelica#15444

Metadata

Metadata

Labels

bugIssue or PR covers a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions