xrg-simulation / ClaRa-official

Open-source Modelica library for dynamic simulation of power plants and other kind of energy systems.
Other
1 stars 1 forks source link

Update ModelicaTables to ModelicaStandardTables #5

Closed AnHeuermann closed 9 months ago

AnHeuermann commented 9 months ago

Description

Some ClaRa components define impure functions that use external C functions from ModelicaTables.

In ClaRa.Components.Utilities.Blocks.ParameterizableTable1D

function tableInit "Initialize 1-dim. table defined by matrix (for details see: Modelica/Resources/C-Sources/ModelicaTables.h)"
  input String tableName;
  input String fileName;
  input Real table[ :, :];
  input Modelica.Blocks.Types.Smoothness smoothness;
  output Integer tableID;
external "C" tableID = ModelicaTables_CombiTable1D_init(
               tableName, fileName, table, size(table, 1), size(table, 2),
               smoothness) annotation(Library="ModelicaExternalC");
end tableInit;

I'm not sure what functions ModelicaExternalC should provide and where to look this up.

For MSL 4.0.0 Modelica.Blocks.Types.ExternalCombiTimeTable.constructor has

function constructor "Initialize 1-dim. table where first column is time"
  // [...]
external "C" externalCombiTimeTable = ModelicaStandardTables_CombiTimeTable_init2(
  // [...]
  )
  annotation (IncludeDirectory="modelica://Modelica/Resources/C-Sources", Library={"ModelicaStandardTables", "ModelicaIO", "ModelicaMatIO", "zlib"});
end constructor;

Expected Behavior

I guess the correct C library would be ModelicaStandardTables. But I'm not sure if it is good to depend on C functions from other libraries. Maybe use the Modelica blocks from the MSL instead which know what C functions they depend on (and ship).

If using Modelica.Blocks.Tables.CombiTable1Ds isn't an option ship all external C functions needed by ClaRa in ClaRa/Resources/Library and ClaRa/Resources/C-Sources.

Related Issues

This breaks FMU export in OpenModelica, see https://github.com/OpenModelica/OpenModelica/issues/11996.

AnHeuermann commented 9 months ago

The last time Modelica/Resources/C-Sources/ModelicaTables.h contained ModelicaTables_* functions was for MSL 3.2.1.

AlesVojacek commented 9 months ago

I have substituted ClaRa.Components.Utilities.Blocks.ParameterizableTable1D by Modelica.Blocks.Tables.CombiTable1Dv. That should solve the issue.

ClaRa.Components.Utilities.Blocks.ParameterizableTable1D used to be necessary because, for example, if the value of the "table" parameter depends on values calculated initially equation, OpenModelica and SimulationX (MSL3.2.1) did not support its use. It was however already solved.