Skip to content

The FMU cannot have correct results with time-changing input #159

Closed

Description

@lambtt

Hello, I'm using dymola-generated FMU for MPC work. I used PyFMI package's function to load the FMU and operate it.

Now my model is based on Modelica Buildings Library 9.0.0 and I found the issues shown below.

Describe the bug

I exported my system model based on MBL 9.0.0 to a co-simulation FMU for model predictive control.
There is only one integer input for the system mode (1,2 or 3).

I divided the simulation period into two parts (t1-t2, t2-t3) with different signals.

When my input signal ('Mode') was changed from 1 to 2 or 2 to 3, the results showed the system didn't have the correct reflection I wanted.

Pseudocode:

model.reset()
model.initialize()
model.set('Mode', int(2))
model.simulate(start_time=t1, final_time=t2,
input=None, options=demo_options)
states = model.get_fmu_state()

model_options['initialize'] = False
model.set_fmu_state(states)
model.set('Mode', int(3))
model.simulate(start_time=t2, final_time=t3,
input=None, options=demo_options)

The input 'Mode' is directly connected with one variable called 'TES'.
During the first time range from t1 to t2, the 'TES' is equal to input 'Mode'.
However, during the second time range from t2 to t3, the 'TES' is still the old value even though the input 'Mode' has been changed from 1 to 2 or 2 to 3 (this issue is shown in Figure 1).

The system didn't work correctly during the second time range either, which is very weird.
I tried different IDEs, Spyder or Pycharm, and Dymola versions, 2021, 2021X, and 2023. This issue still exists.

I also tried one example model (Buildings.Fluid.Storage.Examples.Stratified) in MBL 9.0.0, but the issue also exists.

And another strange stuff is that sometimes the 'TES' could follow the 'Mode', but some variables will restart from their initial guess (this issue is shown in Figure 2).

Expected behavior

Issue 1:

Throughout the simulation period, the variables in the system model should be influenced by the inputs.
Now they are influenced just in the first time range.

Issue 2:

The variables in the second time range should start from their previous values in the last time range instead of the initial guess.

Screenshots

Figure 1. The input cannot influence the system model except for the first time range.

Snipaste_2022-12-09_20-48-15

Figure 2. The variables restart from their initial guess.

Snipaste_2022-12-09_20-48-27

Version

PyFMI: 2.9.7
Modelica Buildings Library: 9.0.0
Modelica 4.0.0. Dymola 2021, 2021X, 2023
Windows 10

Additional context

I'm wondering if there are any comments or suggestions for this issue.
This issue is really weird.
I would appreciate any hints.
Thanks for your kind help!

Activity

  1. lambtt commented on Dec 12, 2022

    @lambtt
    Author

    This issue has been answered at #109.
    But I'm wondering if there will be any comments. Thanks!

  2. modelonrobinandersson commented on Oct 25, 2023

    @modelonrobinandersson
    Contributor

    Thank you @lambtt for your well documented issue, it will help us debug this when we start looking into it.

  3. added 3 commits that reference this issue on May 27, 2026
    11e0dd7
    17e7214
    7f72523
  4. added a commit that references this issue on Jun 5, 2026
    05adda9
  5. added 3 commits that reference this issue on Jun 24, 2026
    434071f
    e2132f8
    86582fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateDuplicate of another issue/pr.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions