1

I'm trying to simulate my Dymola FMU multiple times with PyFMI and the function do_step() after each run it is supposed to start from the beginning.

The first simulation runs as expected, but afterwards, the initialization fails / is stuck and stops:

"FMIL: module = b'Model', log level = 4: b'[][FMU status:OK] Non-linear solver will attempt to handle this problem.\n'
FMIL: module = b'Model', log level = 4: b'[][FMU status:OK] Residual was NaN or Inf.\n'"

"Pseudo Code":

model = load_fmu(r'path', kind="CS", log_level=4)
model.initialize()    
model.setup_experiment(start_time=start_time)


for run in range(2):
  for step in steps:
     status = model.do_step([:], new_step=True)
  model.setup_experiment(start_time=start_time)       
  model.initialize()  # <- Fails
  

FMU created with Dymola 2022.

Has anyone had a similar problem? I didn't have issues with other FMUs and this python library.

Edit:

I have tried using FMpy where it runs no problem, but is much slower.

Phil
  • 624
  • 7
  • 19

2 Answers2

1

You need to reset the FMU before you can initialize it again. Use:

model.reset()

To reset the FMU. I.e.:

for run in range(2):
  for step in steps:
     status = model.do_step([:], new_step=True)
  model.reset()
  model.setup_experiment(start_time=start_time)       
  model.initialize()  # <- Fails
Christian Winther
  • 1,113
  • 1
  • 9
  • 17
0

You should reset the FMU with fmi2Reset before initializing again, see 2.1.6 of the FMI 2.0 specification https://github.com/modelica/fmi-standard/releases/download/v2.0.3/FMI-Specification-2.0.3.pdf