0
votes

I am trying to simulate an OpenModelica example model using ModelicaSystem python module. But I am getting the following error in its constructor. As follows:

code:

import numpy as np
from matplotlib import pyplot as plt
import pyfmi
from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem

omc = OMCSessionZMQ()

model_path = '/usr/lib/omlibrary/Modelica 3.2.3/Electrical/'

omc.sendExpression('loadModel(model_path + Machines.mo)')

mod = ModelicaSystem(model_path + 'Machines.mo','Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_Inverter')

error:

loadFile Error: Error: Failed to insert class Machines within Modelica.Electrical;

 the available classes were:

Can someone help me?

1

1 Answers

1
votes

I admit the User's Guide on OpenModelica Python Interface is quite unclear at the moment. Also ModelicaSystem is missing an easy way to load a model from a standard library in your path.

loadModel is a function to load the Modelica Standard Library (MSL), see OpenModelica Scripting API for loadModel. You can't load a file with it. If you want to use omc.sendExpression you need to use loadFile to load a specific file from the Python interface.

If you want to create a ModelicaSystem for a MSL example I would suggest to load all of the MSL package:

from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem

omc = OMCSessionZMQ()
model_path = '/usr/lib/omlibrary/Modelica 3.2.3/package.mo'
mod = ModelicaSystem(model_path, 'Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_Inverter')

You can't load only /usr/lib/omlibrary/Modelica 3.2.3/Electrical/Modelica 3.2.3/Electrical/Machines.mo, because it is still depending on the MSL 3.2.3. In OMEdit you get a more precise error message, but in Python you'll only get the first line of that message.