Search code examples
modelicafmipyfmi

How to get access to how results are stored using FMPy to simulate FMU-CS?


I develop a simulation script for optimization where each function evaluation is a simulation. Usually the speed can be improved considerably by only allow the simulation to store results in the RAM memory and thus avoid writing to the hard disc. How can this be done using FMPy?

When I use PyFMI the corresponding commands are:

opts_fast = mode.simulate_options()
opts_fast['result_handling'] = 'memory'

and the simulation is done with

sim_res = model.simulate(final_time=1 , options=opts_fast)

Solution

  • My contact with people behind the FMPy software tell me that simulations results are stored in RAM-memory only. There are a number of options for the function simulate_fmu() as you can see by

    from fmpy import simulate_fmu
    simulate_fmu?
    

    Here is no option for storing results in a file on disk. This means that if you need to store the result on disk you need to write the appropriate Python code for that.

    A key difference between FMPy and PyFMI concerning results generated is that for FMPy you need to specify what variables you want to store and specify that in the variable "output" that is a list of variables to be stored during simulation. While PyFMI stores by default everything, but you can alternatively specify a (smaller) list of variables to be stored.

    To improve speed in optmization involving many evaluations using simulations it is important to reset() the FMU rather than loading it anew again. That is the same advice as for using PyFMI.