OpenModelica / OMPython

A Python interface to OpenModelica communicating via CORBA or ZeroMQ
Other
98 stars 57 forks source link

Loading .mo from other Modelica libraries #62

Open gaceladri opened 6 years ago

gaceladri commented 6 years ago

Hello,

I am trying to load this type of modelica library https://github.com/UdK-VPT/BuildingSystems/blob/master/BuildingSystems/Applications/PhotovoltaicSystems/PhotovoltaicSystem.mo and I am having the next error


2018-04-25 18:29:03,435 - OMPython - INFO - OMC Server is up and running at file:////tmp/openmodelica.proto.port.1b96d47d2ac3433887c3324306650d06

loadFile Error: Error: Failed to insert class PhotovoltaicSystem within BuildingSystems.Applications.PhotovoltaicSystems;

 the available classes were:

I have not classes inside this .mo file. mod=ModelicaSystem(".../BuildingSystems-modelica/BuildingSystems/Applications/PhotovoltaicSystems/PhotovoltaicSystem.mo", "PhotovoltaicSystem", "Modelica")

How could I load this type of modelica file with OMPython?

Thanks!

I also have another question. I am interested to know if it is possible to modify/update variables in real time. I want to take for example the battery load and take this variable inside a control logic, then put some actions against the battery within a reinforcement learning algorithm inside python. Is it possible to do with Modelica?

casella commented 6 years ago

@gaceladri please use trac to post issues, see https://trac.openmodelica.org/OpenModelica. We are only using GitHub for development Regarding your first question, I guess you need to load the package.mo file in the root directory, so as to load the entire library, you can't just open one file. Regarding the second question, please open a discussion ticket on trac

bilderbuchi commented 6 years ago

Huh, trac is used for ompython, too? I was not aware of that...

sjoelund commented 6 years ago

No, Trac is not used for OMPython

thorade commented 6 years ago

@sjoelund then the ReadMe has to be updated: https://github.com/OpenModelica/OMPython#bug-reports https://trac.openmodelica.org/OpenModelica/query?component=OMPython

casella commented 6 years ago

We may decide to migrate the issue tracking of all OpenModelica-related projects on GitHub, but I understand this decision has not been made yet 😀. Or has it?

thorade commented 6 years ago

@casella The github issue tracker could just be disabled, as is done in most of the other OM repos, but it is not disabled for this repo, so people will use both GH and Trac...

@gaceladri I have uploaded an example jupyter notebook demonstrating OMPython usage here: https://github.com/thorade/jupyterNotebooks/blob/master/OMPython/OMPython_Photovoltaics.ipynb

It uses some parts from the OMPython documentation: https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html but some parts are done differently, especially the plotting: the example notebook reads the result file using DyMat and the does the plotting with matplotlib instead of OMPlot.

Also, you might have to change the loading of the library to use loadFile(\"librarypath/package.mo\") instead of loadModel(), because loadModel loads the library from the OpenModelica system libraries (or, it searche MODELICAPATH ?? not sure what it really does).

thorade commented 6 years ago

And, another note: The example uses the netCDF Reader library, but that library does not currentlly package the binaries for the gcc version used by OpenModelica on Windows (so, my notebook works on Linux; on windows you would have to compile the dlls yourself). https://github.com/modelica-3rdparty/netCDF-DataReader/issues/6

gaceladri commented 6 years ago

Thank you both so much for your responses and @thorade thank you very much for the jupyter notebook!

Regarding on my second question about adding python controllers (reinforcement learning agents) to the simulation should I open a post on Trac?

Thanks!

edit: I am seeing this paper https://www.modelica.org/events/modelica2014/proceedings/html/submissions/ECP14096777_DietlGallardoyancesJohnssonAkessonLinkVelut.pdf and further researching about how to do it. Thanks both for your time.