OpenModelica / OMPython

A Python interface to OpenModelica communicating via CORBA or ZeroMQ
Other
100 stars 58 forks source link

Using "fixed-step" solver with ModelicaSystem library #87

Open prat33kg opened 5 years ago

prat33kg commented 5 years ago

Hello

I was wondering if there is any method to set fixed-step solver through ModelicaSystem library. I am trying to use this library along with Scipy.optimize to perform parameter fitting for my model. But everytime the model simulates with a different parameter value, it gives different number of outputs for a model. Is there any way to regularize this?

arun3688 commented 5 years ago

@PatronusCoder You can use getSimulationOptions() to see the options you can set and use obj.setSimulationOptions(stepSize=0.004) to have fixed stepsize

For more information look into docs (https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html#enhanced-ompython-features)

alchemyst commented 5 years ago

@PatronusCoder it might be better (more accurate or faster depending on the data) to use a variable step solver and then interpolated on the solution for the known points to calculate your error function.

sjoelund commented 5 years ago

@arun3688 I would have expected that setting the stepSize will use the same solver as before, and not a fixed-step solver. Like @alchemyst says a variable step solver (dassl) is the default and by default OpenModelica interpolates the output points (and adds discrete event points on top).

To choose a fixed-step solver, you need to change the solver to Euler or Runge-Kutta...

There is also an API-function to re-interpolate a result-file (but there are still extra points for discrete events, I think): https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/scripting_api.html#filtersimulationresults

prat33kg commented 5 years ago

@arun3688 Setting the stepSize does not give the time steps only at the expected time instances. As @sjoelund said, OpenModelica interpolates the outputs and adds discrete event points on top. Some of these points are either on same time instances i.e. duplicates and some are between the time steps. Moreover, the number of output points are not consistent. They change with changing parameters. Although I made my Python script to remove the duplicates and all the in-between points, sometimes the final dataset is smaller than my measured dataset. So is it possible that the solver skips some time steps in between?

Also, I am focussing on using ModelicaSystem class because OMC commands are very slow and not very practical when you want to run these commands in a loop.