Opened 4 years ago
Last modified 3 years ago
#5995 assigned defect
FMU Export with Modelica.Utilities.Streams functions
Reported by: | 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 , 4 years ago
Component: | *unknown* → FMI |
---|---|
Milestone: | NeedsInput → 1.16.0 |
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 4 years ago
I would need some more input because this works for me. Or did someone already fix it?
comment:3 by , 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
follow-up: 7 comment:4 by , 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:6 by , 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.
follow-up: 8 comment:7 by , 4 years ago
Replying to sjoelund.se:
But if
loadResource
is used, this will not evaluate at compile-time, and will fail sinceloadResource
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?
follow-ups: 9 10 comment:8 by , 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 sinceloadResource
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
comment:9 by , 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
follow-up: 11 comment:10 by , 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?
follow-up: 12 comment:11 by , 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
comment:12 by , 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:14 by , 4 years ago
Milestone: | 1.17.0 → 1.18.0 |
---|
Retargeted to 1.18.0 because of 1.17.0 timed release.
@lochel, do you think this can be fixed in time for 1.16.0?