Skip to content
Merged
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
15 changes: 11 additions & 4 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,10 +1648,14 @@ def linearize(self): # 22
return

# code to get the matrix and linear inputs, outputs and states
getLinFile = '{}_{}.{}'.format('linear', self.modelName, 'mo')
checkLinFile = os.path.exists(getLinFile)
if checkLinFile:
self.requestApi('loadFile', getLinFile)
linearFile = "linearized_model.mo"

# support older openmodelica versions before OpenModelica v1.16.2 where linearize() generates "linear_modelname.mo" file
if not os.path.exists(linearFile):
linearFile = '{}_{}.{}'.format('linear', self.modelName, 'mo')

if os.path.exists(linearFile):
self.requestApi('loadFile', linearFile)
cNames = self.requestApi('getClassNames')
linModelName = cNames[0]
buildModelmsg=self.requestApi('buildModel', linModelName)
Expand All @@ -1668,6 +1672,9 @@ def linearize(self): # 22
return matrices
else:
return self.requestApi('getErrorString')
else:
errormsg = self.sendExpression("getErrorString()")
return print("Linearization failed: " + "\"" + linearFile + "\"" + " not found \n" + errormsg)
except Exception as e:
raise e

Expand Down