Search code examples
modelicaopenmodelica

OpenModelica updating CombiTable input in real time


I have a model in which I am using a CombiTable1D to retrieve an external input from a .txt file. The file is generated by a Python script at the moment but in the final phase of the project, it is going to be updated each second. For now, simulation takes place without a problem as the .txt file is static. Just read the file and make simulation according to the data written there.

What I want to do is to simulate a model until a certain time, let's say 100s, and then make it wait until a real time event by which the .txt file is updated for the next external input values between 100-200. The simulation should continue by getting these new values for the next 100 seconds.

As I have already been working with OMPython, it is really practical for me to edit the .txt file using Python, let's say for each 10 seconds in real time. I can now simulate the model until the time instance that I define as the refreshing point of the external input. But I couldn't figure out how to keep the state of the simulation and make it read the file once again.


Solution

  • Actually, this sounds like a co-simulation scenario to me. Anyway, what you could do is to extend from CombiTable1D and have something like

    block CombiTable1DWithUpdate
      extends Modelica.Blocks.Tables.CombiTable1D(final tableOnFile=true);
      algorithm
        when sample(0, 10) then
          readTableData(tableID, /* force update */ true, verboseRead);
        end when;
    end CombiTable1DWithUpdate;