Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def sendExpression(self, command, parsed=True):


class ModelicaSystem(object):
def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, commandLineOptions=None, variableFilter=None): # 1
def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, commandLineOptions=None, variableFilter=None, verbose=True): # 1
"""
"constructor"
It initializes to load file and build a model, generating object, exe, xml, mat, and json files. etc. It can be called :
Expand Down Expand Up @@ -860,12 +860,13 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com

if fileName is not None:
self.loadFile()
self.loadLibrary(verbose)

## allow directly loading models from MSL without fileName
if fileName is None and modelName is not None:
self.loadLibrary()
self.loadLibrary(verbose)

self.buildModel()
self.buildModel(variableFilter, verbose)

def __del__(self):
OMCSessionBase.__del__(self)
Expand All @@ -886,20 +887,25 @@ def loadFile(self):
return print(self.getconn.sendExpression("getErrorString()"))

# for loading file/package, loading model and building model
def loadLibrary(self):
def loadLibrary(self, verbose):
# load Modelica standard libraries or Modelica files if needed
for element in self.lmodel:
if element is not None:
loadmodelError = ''
if isinstance(element, str):
if element.endswith(".mo"):
loadModelResult = self.requestApi("loadFile", element)
if not loadModelResult:
loadmodelError = self.requestApi('getErrorString')
## always print the notification warning to user, to suppress the warnings add verbose=False
if verbose:
print(self.requestApi('getErrorString'))
else:
loadModelResult = self.requestApi("loadModel", element)
if not loadModelResult:
loadmodelError = self.requestApi('getErrorString')
if verbose:
print(self.requestApi('getErrorString'))

elif isinstance(element, tuple):
if not element[1]:
libname = "".join(["loadModel(", element[0], ")"])
Expand All @@ -908,10 +914,10 @@ def loadLibrary(self):
loadModelResult = self.sendExpression(libname)
if not loadModelResult:
loadmodelError = self.sendExpression("getErrorString()")
if verbose:
print(self.requestApi('getErrorString'))
else:
print("| info | loadLibrary() failed, Unknown type detected: ", element , " is of type ", type(element), ", The following patterns are supported\n1)[\"Modelica\"]\n2)[(\"Modelica\",\"3.2.3\"), \"PowerSystems\"]\n")
if loadmodelError:
print(loadmodelError)

def setTempDirectory(self):
# create a unique temp directory for each session and build the model in that directory
Expand All @@ -925,7 +931,7 @@ def setTempDirectory(self):
def getWorkDirectory(self):
return self.tempdir

def buildModel(self, variableFilter=None):
def buildModel(self, variableFilter=None, verbose=True):
if variableFilter is not None:
self.variableFilter = variableFilter

Expand All @@ -937,11 +943,14 @@ def buildModel(self, variableFilter=None):
# buildModelResult=self.getconn.sendExpression("buildModel("+ mName +")")
buildModelResult = self.requestApi("buildModel", self.modelName, properties=varFilter)
buildModelError = self.requestApi("getErrorString")

if ('' in buildModelResult):
print(buildModelError)

# Issue #145. Always print the getErrorString since it might contains build warnings.
if buildModelError:
if verbose:
print(buildModelError)
if ('' in buildModelResult):
return

self.xmlFile=os.path.join(os.path.dirname(buildModelResult[0]),buildModelResult[1]).replace("\\","/")
self.xmlparse()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def generateIDL():
OMPython_packages.extend(['OMPythonIDL', 'OMPythonIDL._OMCIDL', 'OMPythonIDL._OMCIDL__POA'])

setup(name='OMPython',
version='3.5.0',
version='3.5.1',
description='OpenModelica-Python API Interface',
author='Anand Kalaiarasi Ganeson',
author_email='ganan642@student.liu.se',
Expand Down