OpenModelica / OMPython

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

Accessing a model within a non-basic Modelica library with OMPython #190

Closed Neylog closed 1 year ago

Neylog commented 1 year ago

Hello,

I am currently writing on my masters thesis. Therefore I am trying to access the model WWTP_ADM.mo that is within the OpenWasteWater-library by jobehrendt.

But whenever i try to load the model i get the following error:

loadFile Error: Error: Failed to insert class WWTP_ADM within OpenWasteWater;

My code looks as follows:

import OMPython

omc = OMPython.OMCSessionZMQ() modelpath = "C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/" mod = OMPython.ModelicaSystem(modelpath + "WWTP_ADM.mo", "WWTP_ADM")

I also tried loading the package.mo but that also didn't work. The error here is as follows:

loadFile Error: [C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/ADM/package.mo:3:1-1097:8:writable] Error: Expected the package to have within ; but got within OpenWasteWater;. Error: Failed to load package ADM () using MODELICAPATH C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/.

The code for that looks like this:

import OMPython

omc = OMPython.OMCSessionZMQ() modelpath = "C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/ADM/" mod = OMPython.ModelicaSystem(modelpath + "package.mo", "package")

Thank you in advance.

Kind regards, Neylog

arun3688 commented 1 year ago

@Neylog You have to import ModelicaSystem Constructor and not OMCSessionZMQ , please see the user guide below https://openmodelica.org/doc/OpenModelicaUsersGuide/1.22/ompython.html#enhanced-ompython-features, so your code should be something like below

from OMPython import ModelicaSystem
modelpath = "C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/ADM/"
mod = OMPython.ModelicaSystem(modelpath + "package.mo", "package")
Neylog commented 1 year ago

Hi @arun3688; thank you for your quick response. I'll look into it further, but the code you send is exactly the one i tried at first hence it produces the same error.

arun3688 commented 1 year ago

@Neylog The second argument should be modelname and hence it should be

modelpath = "C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/ADM/package.mo"
mod = ModelicaSystem(modelpath, "modelname to be simulated")
Neylog commented 1 year ago

@arun3688 thank you for the quick response. Do you have an idea how I can call a package that is part of another package then? The modified code looks like this now:

from OMPython import ModelicaSystem

modelpath = "C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/ASM1/package.mo" mod = ModelicaSystem(modelpath, "WWTP_ADM.mo", "WWTP_ADM")

The thing is that the Library is built like this:

image

So there is a "main package" and then we have smaller ones within the main one and the model i want to use is part of the smaller one within. Additionally the Model I want to call uses models within the ASM1 and the ADM package.

I am just starting off with OMPython and Modelica in it's entirety so I am not quite sure how to do that now.

arun3688 commented 1 year ago

@Neylog So it should be

ModelicaSystem("C:/Uni/MA-Lademann/OpenWasteWater_base/OpenWasteWater/ADM/package.mo", "WWTP_ADM", ["dependant libraries"])

look into the user guide for the constructor arguments, the third parameter is basically loading the dependant models and libraries.

Neylog commented 1 year ago

Thank you I'll try it like that.

casella commented 1 year ago

@Neylog please close the ticket as soon as you are fine. Thanks!