Installing and interacting with simulations in OMPython.

123 views
Skip to first unread message

adrianb...@gmail.com

unread,
Apr 26, 2018, 4:30:49 PM4/26/18
to Modelica-BuildingSystems
Hello,

I am trying to use BuildingSystems with OMPython

import os
import sys
import OMPython
from OMPython import OMCSessionZMQ
print(sys.version)
print(os.getcwd())

omc
= OMCSessionZMQ()

cmds
= [
   
"getVersion()",
   
"loadModel(NcDataReader2)",
   
"loadModel(BuildingSystems)",
   
"getClassNames()",
   
]

for cmd in cmds:
    answer
= omc.sendExpression(cmd)
   
print("\n{}:\n{}".format(cmd, answer))

3.5.5 |Anaconda, Inc.| (default, Mar 12 2018, 23:12:44) 
[GCC 7.2.0]
/media/proto/942ea58f-5397-4c08-aa32-b507c86d1c07/IA/Energy_code/BuildingSystems-modelica
2018-04-26 20:32:49,101 - OMPython - INFO - OMC Server is up and running at file:////tmp/openmodelica.proto.port.e2c0dbd1362c4e4bba1d9086c092d3a6
getVersion():
OpenModelica 1.13.0~dev-924-g9375dc8

loadModel(NcDataReader2):
False

loadModel(BuildingSystems):
False

getClassNames():
()


It gives me False when I am trying to load the model, It seems that NcDataReader2 have to be installed, but I dont see anything about how to load BuildingSystems in the doc

Matthis Thorade

unread,
Apr 26, 2018, 4:56:53 PM4/26/18
to Modelica-BuildingSystems
Hi,
What OS are you on?

When on Ubuntu, you can install the libraries that get packaged by OpenModelica by following the instructions here:
https://openmodelica.org/download/download-linux

If that does not work, or you do not want to do it, there are two other ways:
Add the path where youhave downloaded the libraries to the MODELICAPATH environment variable,
or use loadFile instead of loadModel:
https://github.com/OpenModelica/OMPython/issues/62#issuecomment-384586892

Regards,
Matthis

Matthis Thorade

unread,
Apr 26, 2018, 5:25:07 PM4/26/18
to Modelica-BuildingSystems
Another idea:
Depennding on what you want to do, FMI and related tools might be more suited:
http://fmi-standard.org/
http://jmodelica.org/page/4924
https://github.com/CATIA-Systems/FMPy
You would export the Modelica model to FMI/FMU once (think of it as executable plus XML file describing the interface), then you can interact with it from Python, e.g. change parameters, do optimization etc.

adrianb...@gmail.com

unread,
Apr 27, 2018, 9:54:57 AM4/27/18
to Modelica-BuildingSystems
Hi Matthis,

Thanks for your advices, I already have BuildingSystems loaded with the loadFile command. Thanks.

What I want to do is to simulate the battery and the solar panel and being interacting with the battery load for each day inside the simulation. Better explained, I have a reinforcement learning algorithm external to the simulation, and I want to put this algorithm interacting with the battery load, each time inside the simulation. Not the results, in between to simulate a selling/buying market.

What do you recommend me to choose? With OMPython... do a simulation with fmi and interact with the RL algorithm with XML or how?

Thanks!!

adrianb...@gmail.com

unread,
Apr 27, 2018, 9:57:02 AM4/27/18
to Modelica-BuildingSystems
I need to get and push commands to the battery

Matthis Thorade

unread,
Apr 27, 2018, 11:45:07 AM4/27/18
to Modelica-BuildingSystems
Hi,
both approaches probably have advantages and disadvantages.
FMI means, you can only change parameters and input of your model, but not the equations or structure. Modelica is acausal, so before execution the equations have to be sorted and then translated to C, and then compiled. FMI already is compiled code, a DLL on Windows or a SO file on Linux.
Not sure if that helps, you probably have to try yourself what works best.
Regards,
Matthis
Reply all
Reply to author
Forward
0 new messages