Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lambtt opened this issue Dec 10, 2022 · 2 comments
Closed

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

lambtt opened this issue Dec 10, 2022 · 2 comments
Labels
duplicate Duplicate of another issue/pr.

Comments

@lambtt
Copy link

lambtt commented Dec 10, 2022

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!

@lambtt
Copy link
Author

lambtt commented Dec 12, 2022

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

@modelonrobinandersson modelonrobinandersson added the duplicate Duplicate of another issue/pr. label Jan 5, 2023
@modelonrobinandersson
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Duplicate of another issue/pr.
Projects
None yet
Development

No branches or pull requests

2 participants