OpenModelica / OpenModelica

OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage.
https://openmodelica.org
Other
820 stars 305 forks source link

Use structured variables in imported FMU input dialog boxes #9627

Open ceraolo opened 1 year ago

ceraolo commented 1 year ago

Description

This is not a bug report, just a suggestion of a possible improvement

Imported FMUs created from modelica file show as parameters not only those available from the outside in the original modelica model, but also all the internal parameters, and show them in a non-structured way. In very simple the example given, the list is large and difficult to read, and can easily become huge and unmanageable. I propose to show parameters in a more structured way. See details below under "expected behaviour" I know that variables of imported FMUs are not shown as structured, also in output mat file; I miss a structured display also there, but I'll open a separate ticket for that.

Steps to Reproduce

Use the following file (without txt): TestWTable.mo.txt

  1. load TestWTable.mo and open TestBlock
  2. double-click on block1: the only parameter shown is K
  3. Create an FMU from Block1
  4. Import the created FMU and drag into a new model
  5. double-click on the just dragged instance of the imported FMU
  6. => you will see not only K but also all the internal parameters of myTable and firstOrder. In case the table contains a lot of points, this listing could be huge.

Expected Behavior

In TestBlockFMU, upon double-clicking on "block1", I would expect as list of variables: K firstOrder myTable.

K would show its value, while firstOrder and my Table should be expandable to show their internal parameters.

Version and OS

OM 1.20-dev-398 Ubuntu 22.4 under a VirtualBox MSL 4.0

#

ceraolo commented 1 year ago

After creating the ticket I checked with Dymola and found that what I expected is already there in Dymola, even when the FMU is created by OpenModelica. In enclose two screenshots. image image

Dymola does more than what I proposed: it also parses the table matrix in a structured way.

casella commented 1 year ago

@ceraolo when you import an FMU in OpenModelica, a custom Modelica wrapper is generated. You can actually inspect it and modify it. I think the best way to proceed here is that you actually modify it once, adding all the required dialog annotations to fit your requirements, and then post the original and modified .mo files here. At that point, patching the diff of the two files onto the built-in wrapper code generator will be straightforward.

Would you like to give it a try?

ceraolo commented 1 year ago

I saw that in Dymola and in Matlab (and probably in other tools), submodels are shown as single entities in the main dialog box, and you can access the internal parameters through interaction with these single entities.

Matlab and Dymola create wrappers for the FMU, but, obviously, only Dymola does this in Modelica. So I thought to take inspiration from the Dymola wrapper.

To appreciate the differences, using Dymola, load the three mo files in MU wrapper.zip, open compare, and double click on either of the two submodels (indeed two wrappers of the same FMU, the left one created by OM the right by Dymola).

FMU wrapper.zip

Some screenshots here: image image image

I also tried to load the Dymola wrapper into OM but found that the result is different and not what we need: image

So, I realized that Dymola, when creating its FMU wrapper, uses own extensions of Modelica, which it also uses for nested editing of parameters (I mean, changing parameter values of submodels of a main model from the dialog box of the main model).

I know that work is in progress to allow nested editing of parameters also in OM, even though insofar I could not locate the relevant ticket. EDIT: it is #2891

Maybe to approach this ticket it is better to wait that the nested editing of parameters to be implemented in OM? The same technique used for regular Modelica will then be used also for FMU wrappers.