My objective is to create a 1D/2D lookup table that can read a variable sized array in JSON file without having to specify a statically sized Modelica array parameter.
I started out by trying to extend ExternData to implement a custom table based on a suggestion in a github issue: https://github.com/modelica-3rdparty/ExternData/issues/34#issuecomment-718552210
The steps outlined were:
- Create your own copy of a CombiTable, modify it to accept a data access object and a stable name, see code snippet below
- Create a duplicate of the ExternalCombiTable1D, which instead references your own CombiTable data object
- Create a c-function which reads the data directly from the json and stores it into a table object, which is then passed to the MSL function ModelicaStandardTables_CombiTable1D_init2
I've implemented all three steps to make a custom CombiTable1D block which populates a dynamic sized table from ExternData JSON functions. Package code below:
https://github.com/vsskanth/ExternData.CustomTable
In this package, there are 3 experiments of relevance to this issue. All experiments compile but only only one experiment works:
ExternData.Examples.JSONTestVariableArrayBroken.mo
- Single instance of custom CombiTable1D - does not initializeExternData.Examples.JSONTestArrayCombi2DBroken.mo
- Custom CombiTable1D and instance of Modelica CombiTable2D - does not initializeExternData.Examples.JSONTestVariableArrayWorking.mo
- Custom CombiTable1D and a couple instances of Modelica CombiTable1D - works as expectedI am trying to find out why my custom CombiTable1D implementation initializes and runs only when there is at least one instance of Modelica CombiTable1D present in the experiment. I made sure to link ModelicaStandardTables.h
and ModelicaStandardTables.lib
libraries in my own implementation, checked for warnings in dsbuild.txt
and compilation seems to be fine.
For some reason, the constructor function for the custom ExternalCombiTable1D external object (ExternData.Types.ExternalCombiTable1D
) does not return and hence the custom CombiTable1D block (ExternData.Tables.CombiTable1D
) is not able to initialize when there are no instances of Modelica CombiTable1D tables in the model.
I would appreciate any thoughts on why this is happening and how to overcome it.
@tbeu has been generous enough to add JSON support to https://github.com/tbeu/ModelicaTableAdditions which renders this issue moot since I can just use that package with ExternData.
Its still interesting as to why this happens though. Seems like a Dymola translation bug.