deathHamster10
deathHamster10

Reputation: 53

Modelica - How can I best move a large array from a .CSV file or .MAT file to an external C object?

I am using Open Modelica.

I have a large array of floating point numbers (~4,000,000 numbers) in .csv format or .mat format (they are equally convenient to me).

I load the data into OpenModelica using the ExternData package (.csv) or using Modelica.Utilities.Streams.readRealMatrix (.mat). It is stored as a constant array of Real type.

I have produced a C function that performs some operations on this data set (some weird interpolation). This is associated with an ExternalObject that hold the data, which is given to it through its constructor and Modelica interface.

My problem is that the OpenModelica translator appears to grind to a halt, with massive memory consumption, when faced with a constant array of large size. For example, the follow model translates slowly. If the size of the array is increased, the translation time and memory consumption seems to increase exponentially.

model test
constant Real[10000,5] test_array;

end test;

Is there another way that I can move my data from the .csv or .mat files to the external object? I thought that my external C code could import the .csv or .mat file themselves, but that is quite beyond my almost non-existent C programming ability. Is there another way?

Upvotes: 2

Views: 376

Answers (1)

tbeu
tbeu

Reputation: 1349

The recommended way is to have such large array data not within the model but as external data files. The CombiTimeTable supports both reading from text file and MATLAB MAT file at simulation run-time. You will also benefit from shorter translation times.

Upvotes: 4

Related Questions