Opened 4 years ago
Last modified 3 years ago
#5995 assigned defect
FMU Export with Modelica.Utilities.Streams functions
Reported by: | robert.hallqvist@… | Owned by: | lochel |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | FMI | Version: | |
Keywords: | FMI, Modelica.Utilities.Streams | Cc: | lochel |
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 Changed 4 years ago by casella
- Component changed from *unknown* to FMI
- Milestone changed from NeedsInput to 1.16.0
- Owner changed from somebody to lochel
- Status changed from new to assigned
comment:2 Changed 4 years ago by sjoelund.se
I would need some more input because this works for me. Or did someone already fix it?
comment:3 Changed 4 years ago by robert.hallqvist@…
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 follow-up: ↓ 7 Changed 4 years ago by sjoelund.se
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 Changed 4 years ago by adrpo
See also #5263.
comment:6 Changed 4 years ago by anonymous
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.
comment:7 in reply to: ↑ 4 ; follow-up: ↓ 8 Changed 4 years ago by 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?
comment:8 in reply to: ↑ 7 ; follow-ups: ↓ 9 ↓ 10 Changed 4 years ago by 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.
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
comment:9 in reply to: ↑ 8 Changed 4 years ago by casella
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
comment:10 in reply to: ↑ 8 ; follow-up: ↓ 11 Changed 4 years ago by 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?
comment:11 in reply to: ↑ 10 ; follow-up: ↓ 12 Changed 4 years ago by robert.hallqvist@…
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 in reply to: ↑ 11 Changed 4 years ago by casella
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 Changed 4 years ago by casella
- Milestone changed from 1.16.0 to 1.17.0
Retargeted to 1.17.0 after 1.16.0 release
comment:14 Changed 4 years ago by casella
- Milestone changed from 1.17.0 to 1.18.0
Retargeted to 1.18.0 because of 1.17.0 timed release.
comment:15 Changed 3 years ago by casella
- Milestone 1.18.0 deleted
Ticket retargeted after milestone closed
@lochel, do you think this can be fixed in time for 1.16.0?