Opened 5 years ago

Last modified 3 years ago

#5995 assigned defect

FMU Export with Modelica.Utilities.Streams functions

Reported by: robert.hallqvist@… Owned by: Lennart Ochel
Priority: high Milestone:
Component: FMI Version:
Keywords: FMI, Modelica.Utilities.Streams Cc: Lennart Ochel

Description

The following error is communicated when exporting a model incorporating the functions Modelica.Utilities.Streams.readMatrixSize and matrixName, Modelica.Utilities.Streams.readMatrixSize:

[CodegenUtil.tpl: 197:14-197:14]: Template error: initial value of unknown type: Modelica.Utilities.Streams.readRealMatrix(..., Modelica.Utilities.Streams.readMatrixSize(...

It is possible to export FMUs incorporating these functions with competing FMI supporting tools

Change History (15)

comment:1 by Francesco Casella, 5 years ago

Component: *unknown*FMI
Milestone: NeedsInput1.16.0
Owner: changed from somebody to Lennart Ochel
Status: newassigned

@lochel, do you think this can be fixed in time for 1.16.0?

comment:2 by Martin Sjölund, 4 years ago

I would need some more input because this works for me. Or did someone already fix it?

comment:3 by robert.hallqvist@…, 4 years ago

The code that I do not manage to export as an FMU is:

model ReadExtMatrix_ArbSize

parameter String fileName="*.mat";
parameter String matrixName = "data" "Name / identifier of the 2D Real array on the file";
parameter Real Mat[Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {1, 0}, Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {0, 1}] = Modelica.Utilities.Streams.readRealMatrix(fileName, matrixName, Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {1, 0}, Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {0, 1});

end ReadExtMatrix_ArbSize;

The *.mat file contains a 2*n matrix named data

comment:4 by Martin Sjölund, 4 years ago

This works fine for me:

model ReadExtMatrix_ArbSize
parameter String fileName="/home/martin/.openmodelica/libraries/Modelica 4.0.0+maint.om/Resources/Data/Utilities/Test_RealMatrix_v4.mat";
parameter String matrixName = "Matrix_A" "Name / identifier of the 2D Real array on the file";
parameter Real Mat[Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {1, 0}, Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {0, 1}] = Modelica.Utilities.Streams.readRealMatrix(fileName, matrixName, Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {1, 0}, Modelica.Utilities.Streams.readMatrixSize(fileName, matrixName) * {0, 1});
end ReadExtMatrix_ArbSize;

But if loadResource is used, this will not evaluate at compile-time, and will fail since loadResource is deferred to runtime for FMUs.

comment:5 by Adrian Pop, 4 years ago

See also #5263.

comment:6 by anonymous, 4 years ago

Did I understand you correctly sjoelund.se that you are able to export the code posted above as an FMU? The example that I posted simulates just fine but when I try to export the code as an FMU I get the described error.

in reply to:  4 ; comment:7 by Francesco Casella, 4 years ago

Replying to sjoelund.se:

But if loadResource is used, this will not evaluate at compile-time, and will fail since loadResource is deferred to runtime for FMUs.

What is the rationale behind deferring loadResource to runtime for FMUs? If the parameter is structural, why couldn't it be evaluated at compile-time, as it should?

Last edited 4 years ago by Francesco Casella (previous) (diff)

in reply to:  7 ; comment:8 by Martin Sjölund, 4 years ago

Did I understand you correctly sjoelund.se that you are able to export the code posted above as an FMU? The example that I posted simulates just fine but when I try to export the code as an FMU I get the described error.

Yes, it worked fine as FMU.

Replying to casella:

Replying to sjoelund.se:

But if loadResource is used, this will not evaluate at compile-time, and will fail since loadResource is deferred to runtime for FMUs.

What is the rationale behind deferring loadResource to runtime for FMUs? If the parameter is structural, why couldn't it be evaluated at compile-time, as it should?

Because it would be evaluated to a constant string that won't exist on the machine that runs the FMU

in reply to:  8 comment:9 by Francesco Casella, 4 years ago

Replying to sjoelund.se:

Did I understand you correctly sjoelund.se that you are able to export the code posted above as an FMU? The example that I posted simulates just fine but when I try to export the code as an FMU I get the described error.

Yes, it worked fine as FMU.

@robert, which version of OMC are you using? Please try with version 1.16.0-dev.beta1

in reply to:  8 ; comment:10 by Francesco Casella, 4 years ago

Replying to sjoelund.se:

Because it would be evaluated to a constant string that won't exist on the machine that runs the FMU

The idea in this case should be that this constant string is immediately used by the front-end to load the data and constant-evaluated it, so this string won't actualy show up in the FMU code at all. I get that the front-end understands which parameters have structural influence, and it constant-evaluates them for good. Do I miss something?

Also, in case loadResource points to a modelica:// URL, we could make sure that the Resource directory is shipped with the FMU and reachable by the dll that implements it. Would that be doable?

in reply to:  10 ; comment:11 by robert.hallqvist@…, 4 years ago

Replying to casella:

Replying to sjoelund.se:

Because it would be evaluated to a constant string that won't exist on the machine that runs the FMU

The idea in this case should be that this constant string is immediately used by the front-end to load the data and constant-evaluated it, so this string won't actualy show up in the FMU code at all. I get that the front-end understands which parameters have structural influence, and it constant-evaluates them for good. Do I miss something?

Also, in case loadResource points to a modelica:// URL, we could make sure that the Resource directory is shipped with the FMU and reachable by the dll that implements it. Would that be doable?

Does this mean that it will be possible to modify the csv in the resources and that the FMU will be able to read the modified values? This would be of great benefit for my application if that is the case

in reply to:  11 comment:12 by Francesco Casella, 4 years ago

Replying to robert.hallqvist@…:

Does this mean that it will be possible to modify the csv in the resources and that the FMU will be able to read the modified values? This would be of great benefit for my application if that is the case

In principle, why not. The FMI specification, regarding the contents of the FMU, mentions that

4) Further data can be included in the FMU ZIP file, especially a model icon (bitmap file), documentation files, maps and tables needed by the FMU

If the FMU was generated from a Modelica model, it should be able to access data in directories structured according to the Modelica standard

comment:13 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:14 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:15 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.