Phil
Phil

Reputation: 666

Opening big result mat-File raises buffer is too small for requested array

I've successfully finished my week-long Dymola simulation only to find myself unable to load the result mat-File with DyMat.

Every time I try to open it with Python and DyMat (https://www.j-raedler.de/projects/dymat/) I get the error:

buffer is too small for requested array

The problems seems to come from the immense model size and data logging. If I only simulate 1/3 of the time the mat-File opens just fine.

Does anyone have an idea how to solve this?

Upvotes: 2

Views: 278

Answers (3)

Dag B
Dag B

Reputation: 759

To reduce result file size Dymola also supports something called "Variable Selections" that gives you more fine-grained control over what variables are stored (in addition to states) and how they should be grouped. See the Dymola manual.

Upvotes: 1

Phil
Phil

Reputation: 666

I managed to solve it easily by declaring all parameters and variables I don't need with the protected keyword.

For example:

protected // I dont need the parameters below here
    parameter SI.Pressure p_nom = 10e5;
    parameter SI.Density rho_w = 1000;

public // Parameters below are visible in the simulation result
   SI.Pressure p;
   Real t;     

protected // Another Private block removing v from the simulation result
   SI.Velocity v;

You can make protected variables visible again by checking it in the Simulation setup in Dymola.

Additionally, make sure you do not have "Store Variables at events" activated and a high enough interval length. If you only need to store a couple of parameters it is even better to use another procedure described here: Selection of variables to be saved in the result file

Using protected and public reduces the simulation file size from 9 GB to below 1 GB solving my issues.

This might be an obvious answer for most, but I just didn't think it would solve it.

Upvotes: 0

marcu1000s
marcu1000s

Reputation: 177

I have also encountered similar problems when reading large Dymola simulation results in MAT format to Python (even though I've used modelicares instead of DyMat, see http://kdavies4.github.io/ModelicaRes/ ). For me, the problem seems to occur for results with many time steps, even when very few variables are written to file.

One workaround that has worked so far is this: Even though the large MAT file cannot be loaded in Python, it has worked for me to load the result file back into Dymola and from there export the results as SDF or CSV. Downsides are of course that the resulting SDF or CSV files are even larger than the original MAT file, and that this involves another manual step, but from there, I was always able to load the SDF or CSV data into Python, e.g. using the sdf Python package. If this would occur more often, it would probably also be possible to write a MOS-Script to automate the process of loading the MAT file into Dymola and export it to SDF or CSV.

This solution is not ideal, but maybe helpful as a workaround. If there are better solutions, I'd also be happy to hear about them.

Upvotes: 3

Related Questions