Message Boards Message Boards


Modifying Modelica C library for WSM

Posted 1 year ago
4 Replies
2 Total Likes

The "Modelica Standard Tables" library is in C, and the extrapolation method is hardcoded (in C) in the init function. I need to use "NO_EXTRAPOLATION" instead of "LAST_TWO_POINTS" So I pulled the Modelica source code from Github.

I used Terminal (macOS) to run the Makefile. It created

  • libModelicaO.a
  • libModelicaMatIO.a
  • libModelicaStandardTables.a
  • libzlib.a

I put libModelicaStandardTables.a into /Applications/SystemModeler/Contents/lib/osx64/msl/3.2.2 and the model failed. I thought maybe it depended on one of the other libraries, and that's when I noticed that libModelicaExternalC.a is not in the standard (Github) code for Modelica but libzlib.a is.

Is there a way to build the C code from Github that's compatible with WSM?

Relevant C code

void* ModelicaStandardTables_CombiTable2D_init(_In_z_ const char* tableName,
_In_z_ const char* fileName,
_In_ double* table, size_t nRow,
size_t nColumn, int smoothness) {
return ModelicaStandardTables_CombiTable2D_init2(fileName, tableName,
table, nRow, nColumn, smoothness, LAST_TWO_POINTS, 1 /* verbose */);
void* ModelicaStandardTables_CombiTable2D_init2(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_In_ double* table, size_t nRow,
size_t nColumn, int smoothness,
int extrapolation,
int verbose) {

Modelica code in WSM

external "C" externalCombiTable2D = ModelicaStandardTables_CombiTable2D_init(tableName, fileName, table, size(table, 1), size(table, 2), smoothness)

Maybe the better way to do this is to duplicate the table library and use CombiTable2D_init2 directly and pass the extrapolation integer (4 = NO_EXTRAPOLATION)

4 Replies

Where is the extrapolation hardcoded? You have the extrapolation parameter in CombiTimeTable that you can use to control the extrapolation.


I've updated the post with the code in C and WSM. The interpolation method is an argument, but not the extrapolation (unless it's bundled somehow, and I missed it).

Edit: I opened CombiTimeTable and see that extrapolation is an input parameter here, but not in the CombiTable2D external function.

I have never used the build systems that comes with MSL so I don't know why their makefile doesn't build libModelicaExternalC. However, if you look at the autotools based one libModelicaExternalC consists of ModelicaFFT.c ModelicaInternal.c ModelicaRandom.c ModelicaStrings.c.

Note the code you are looking at on github is the master branch, it's most likely not compatible with the Modelica code of MSL 3.2.2 (There is no ModelicaStandardTablesCombiTable2Dinit2 in 3.2.2) so you probably want it all or nothing if you are using the code from the master branch on github.

Thanks Otto, I submitted a ticket to get it on the developer's radar to see what can be done. In the meantime I'll try the workaround I mentioned. Thanks again.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract