1

I am working on a complex Modelica model that contains a large set of data, and I need the simulation to keep going until I terminate the simulation process, maybe even for days, so the .mat file could get very large, I got trouble with how to do data processing. So I'd like to ask if there are any methods that allow me to

  1. output the data I need after a fixed time step during simulation, but not using the .mat file after simulation. I am considering using Modelica.Utilities.Stream.Print` function to print the data I need into a CSV file, but I have to write a huge amount of code that prints every variable I need, so I think there should be a better solution.
  2. delete the .mat file during a fixed time step, so the .mat file stored on my PC wouldn't get too large, and don't affect the normal simulation of Dymola.
Jack
  • 1,094
  • 6
  • 16
  • 2
    Would result filtering help? https://www.claytex.com/blog/selection-of-variables-to-be-saved-in-the-result-file/ – Priyanka Apr 02 '21 at 12:58
  • 2
    related: https://stackoverflow.com/questions/42123605/how-to-hide-simulation-variables-in-dymola – Priyanka Apr 02 '21 at 13:00
  • 2
    I'm not sure what kind of analysis you want to perform. If you only need to access variables as they are being written and can accept some being lost and not having history... Then OPC is probably your best bet. I'm not sure if Dymola uses OPC-DA (Windows only) or OPC-UA though – sjoelund.se Apr 02 '21 at 16:06
  • @sjoelund.se, I am considering using the Modelic_DeviceDrivers library to transfer data via UDP, but it turns out I have to connect every variable via a component, and I have a few thousands of variables, it would take too much effort to connect them. – Jack Apr 02 '21 at 17:02
  • Modifying the result .mat during the simulation will not work reliably due to how it is written. – Hans Olsson Apr 06 '21 at 07:03

2 Answers2

1

Long time ago I wrote a small C-program that runs the executable of Dymola with two threads. One of them is responsible for terminating the whole simulation after exceeding an input time limit. I used the executable of this C-program within the standard given mfiles from Dymola. I think with some hacking capabilities, one would be able to conduct the mentioned requirements.

Have a look at https://github.com/Mathemodica/dymmat however I need to warn that the associated mfiles were for particular type of models and the software is not maintained since long time. However, the idea of the C-program would be reproducible.

Atiyah Elsheikh
  • 568
  • 3
  • 12
1

I didn't fully test this, so please think of this more like "source of inspiration" than a full answer:

In Section "4.3.6 Saving periodic snapshots during simulation" of the Dymola 2021 Release Notes you'll find a description to do the following:

The simulator can be instructed to print the simulation result file “dsfinal.txt” snapshots during simulation.

This can be done periodically using the Simulation Setup options "Complete result snapshots", but I think for your case it could be more useful to trigger it from the model using the function Dymola.Simulation.TriggerResultSnapshot(). A simple example is given as well:

when x > 0 then
  Dymola.Simulation.TriggerResultSnapshot();
end when;

Also one property of this function could help, as it by default creates multiple files without overwriting them:

By default, a time stamp is added to the snapshot file name, e.g.: “dsfinal_0.1.txt”.

The format of the created dsfinal_[TIMESTAMP].txt is a bit overwhelming at first, as it contains all information for initializing the model, but there should be everything you need...

So some effort is shifted to the post processing, as you will likely need to read multiple files, but I think this is an acceptable trade-off.

Markus A.
  • 6,300
  • 10
  • 26
  • 1
    And you can also set the output interval from your model, skipping past "uninteresting" sections of the simulation. – Dag B Apr 06 '21 at 08:24