- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How FMU handle a lookup table
How FMU handle a lookup table
How FMU handle a lookup table
Hallo everybody,
Say i have a model with two inputs u1 and u2 that feed to a 2D-LookupTable as an output in OMEdit. The table is saved inside a file with either .mat or .txt format.
My Question is, how does the FMU export process handle the external file? Can external file be included as a resource (i.e. packed together in FMU) or should the table hardcoded into the model? And if the table is hardcoded, is there any significant performance issue?
- Arinomo23
- 120 Posts
Re: How FMU handle a lookup table
If you use in Modelica URIs such as modelica://path/to/file.txt then the generated FMU will include the file.txt in the resource directory.
If you use the direct path to file then the FMU will not have that file included in the resource directory and it will read it from that local path. Note that in this case, if you send the FMU to somebody else, they will not have access to file.txt.
You can also include the table directly in the Modelica code but that might slow down the compilation (depending on how big the table is) and make the FMU bigger.
- adrpo
- 885 Posts
Re: How FMU handle a lookup table
Hallo Adrian,
thanks for the reply. Regarding the Modelica URI, below is a simple model I made:
Code:
model PathTest
import Files = Modelica.Utilities.Files;
Modelica.Blocks.Sources.CombiTimeTable combiTimeTable1(extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint, fileName = Files.loadResource("modelica://KS_Tables/LookUp/myTable.txt"), smoothness = Modelica.Blocks.Types.Smoothness.ConstantSegments, tableName = "Test", tableOnFile = true) annotation(
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
annotation(
Icon(coordinateSystem(preserveAspectRatio = false)));end PathTest;
Where KS_Tables is an empty package I made, and LookUp is a folder I manually add in Win Explorer. Simulation of the model work fine with expected output. The problem is when I try to export the model as FMU using OMEdit (right mouse click-->Export-->FMU). When I did this, all Libraries that currently loaded in OMEdit are included in resource folder, regardless if they are used in model or not. When all other libraries are unloaded, only MSL is included, but not the KS_Tables.
Am I not understand the Modelica URI correctly? or did i make some other mistakes?
Thnks
A
- Arinomo23
- 120 Posts
Re: How FMU handle a lookup table
Hm, i will need to check if we put the entire library in the resource folder if is loaded into OMEdit, it might be that we do, but that seems like an overkill and we should change it.
- adrpo
- 885 Posts
Re: How FMU handle a lookup table
We do that if we have a call to uriToFileName(xxx) where xxx is not a constant string that we can resolve at compile-time. And for the MSL, it seems that the loadResource function is not marked with Inline=true.
I think the best fix would be for us to change ModelicaServices.ExternalReferences.loadResource to be marked Inline=true.
- sjoelund.se
- 1700 Posts
Re: How FMU handle a lookup table
sjoelund.se wrote:
We do that if we have a call to uriToFileName(xxx) where xxx is not a constant string that we can resolve at compile-time. And for the MSL, it seems that the loadResource function is not marked with Inline=true.
I think the best fix would be for us to change ModelicaServices.ExternalReferences.loadResource to be marked Inline=true.
Hi Martin,
thank you for the feedback. Should I open a new ticket about this?
- Arinomo23
- 120 Posts
Re: How FMU handle a lookup table
Yes, might be good to open a ticket. I not only want to fix the problem, but give a diagnostic message when we fallback to copying all the files into the FMU...
- sjoelund.se
- 1700 Posts
Re: How FMU handle a lookup table
Hallo Martin, Hallo Adrian,
thank you for the fix in nightly build. The loadResource (both in Modelica.Utilities and ModelicaService.ExternalReference) is now only include the intended file(s) in the resource folder of FMU.
I have a question regarding how the file inside resource folder is utilized. After a successful FMU export, I test the FMU using FMUChecker. I changed the original file's name on my computer to check if the file inside the resource folder is used or it still trying to used the original file and it seems fmuChecker is still looking for path to original file.
Is what I'm looking for, is the intended use case of including file in resource folder(i.e. FMU is useable out of the box by end-user)? or the end user should un-pack the FMU, download the file, change the path (e.g. fileName of a combiTimeTable) and repack the FMU using makefile? or its just how fmuChecker works?
I've look at the FMI documentation, but seems didn't find any reference(or more likely missed it).
best regards
A
- Arinomo23
- 120 Posts
Re: How FMU handle a lookup table
I tested using Linux and OMSimulator and added some debug print to see that it's doing what it should:
Code:
path to load: /home/marsj/tmp/tmp2/KS_Tables/LookUp/myTable.txt
Resources dir: /home/marsj/tmp/tmp2/model-ca9vdzfd/temp/fmu/resources
Result: /home/marsj/tmp/tmp2/model-ca9vdzfd/temp/fmu/resources/home/marsj/tmp/tmp2/KS_Tables/LookUp/myTable.txt
With Linux and fmuCheck.linux64:
Code:
path to load: /home/marsj/tmp/tmp2/KS_Tables/LookUp/myTable.txt
Resources dir: /tmp/fmucktmp1H9wDU/resources
Result: /tmp/fmucktmp1H9wDU/resources/home/marsj/tmp/tmp2/KS_Tables/LookUp/myTable.txt
So it should work fine... I suppose if you use Windows, the long paths aren't particularly helpful though
- sjoelund.se
- 1700 Posts
Re: How FMU handle a lookup table
Hmm... that's interesting. I'll check if the proble really is a long path on Windows and will let you know. Thanks a lot.
- Arinomo23
- 120 Posts
Re: How FMU handle a lookup table
Hi Martin,
I've check on a win10 64bit at home and it still failed. Either from the long name or because mixed use of / and \ in windows (see code below). Anyhow, if its working, maybe it will work on the rt-machine as i intended.
Thank you again for your help.
Code:
[INFO][FMUCHK] Printing output file header
"time"
[INFO][FMUCHK] Model identifier for CoSimulation: PathTest
[INFO][FMILIB] Loading 'win64' binary with 'default' platform types
[INFO][FMUCHK] Version returned from CS FMU: 2.0
stdout | info | ... loading "TestTable" from "C:\Users\Arinomo\Desktop\Check\/E:/USERTEMP/fmucktmpa12888/resources/C:\Users\Arinomo\Desktop\Test\TestTable.txt"
assert | debug | Not possible to open file "C:\Users\Arinomo\Desktop\Check\/E:/USERTEMP/fmucktmpa12888/resources/C:\Users\Arinomo\Desktop\Test\TestTable.txt": No such file or directory
[FMU][logFmi2Call][FMU status:Error] fmi2EnterInitializationMode: terminated by an assertion.
[FATAL][FMUCHK] Failed to initialize FMU for simulation (FMU status: OK)
FMU check summary:
FMU reported:
1 warning(s) and error(s)
Checker reported:
0 Warning(s)
1 Error(s)
1 Fatal error(s) occurred during processing
- Arinomo23
- 120 Posts
Re: How FMU handle a lookup table
Yeah, that path looks a bit messed up and needs a ticket for one of our windows developers to have a look.
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How FMU handle a lookup table