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
33 changes: 17 additions & 16 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
## set default command Line Options for linearization as
## linearize() will use the simulation executable and runtime
## flag -l to perform linearization
self.getconn.sendExpression("setCommandLineOptions(\"--linearizationDumpLanguage=python\")")
self.getconn.sendExpression("setCommandLineOptions(\"--generateSymbolicLinearization\")")
self.sendExpression("setCommandLineOptions(\"--linearizationDumpLanguage=python\")")
self.sendExpression("setCommandLineOptions(\"--generateSymbolicLinearization\")")

self.setTempDirectory(customBuildDirectory)

Expand All @@ -736,14 +736,14 @@ def setCommandLineOptions(self, commandLineOptions: str):
## set commandLineOptions if provided by users
if commandLineOptions is not None:
exp = "".join(["setCommandLineOptions(", "\"", commandLineOptions, "\"", ")"])
cmdexp = self.getconn.sendExpression(exp)
cmdexp = self.sendExpression(exp)
if not cmdexp:
self._check_error()

def loadFile(self):
# load file
loadFileExp = "".join(["loadFile(", "\"", self.fileName, "\"", ")"]).replace("\\", "/")
loadMsg = self.getconn.sendExpression(loadFileExp)
loadMsg = self.sendExpression(loadFileExp)
## Show notification or warnings to the user when verbose=True OR if some error occurred i.e., not result
if self._verbose or not loadMsg:
self._check_error()
Expand Down Expand Up @@ -788,7 +788,7 @@ def setTempDirectory(self, customBuildDirectory):

logger.info("Define tempdir as {}".format(self.tempdir))
exp = "".join(["cd(", "\"", self.tempdir, "\"", ")"]).replace("\\", "/")
self.getconn.sendExpression(exp)
self.sendExpression(exp)

def getWorkDirectory(self):
return self.tempdir
Expand Down Expand Up @@ -835,7 +835,7 @@ def _run_cmd(self, cmd: list):
raise ModelicaSystemError("Exception {} running command {}: {}".format(type(e), cmd, e))

def _check_error(self):
errstr = self.getconn.sendExpression("getErrorString()")
errstr = self.sendExpression("getErrorString()")
if errstr is None or not errstr:
return

Expand All @@ -856,7 +856,7 @@ def buildModel(self, variableFilter=None):
else:
varFilter = "variableFilter=" + "\".*""\""
logger.debug(varFilter)
# buildModelResult=self.getconn.sendExpression("buildModel("+ mName +")")
# buildModelResult=self.sendExpression("buildModel("+ mName +")")
buildModelResult = self.requestApi("buildModel", self.modelName, properties=varFilter)
if self._verbose:
logger.info("OM model build result: {}".format(buildModelResult))
Expand All @@ -866,6 +866,7 @@ def buildModel(self, variableFilter=None):
self.xmlparse()

def sendExpression(self, expr, parsed=True):
logger.debug("sendExpression(%r, %r)", expr, parsed)
return self.getconn.sendExpression(expr, parsed)

# request to OMC
Expand All @@ -880,7 +881,7 @@ def requestApi(self, apiName, entity=None, properties=None): # 2
else:
exp = '{}()'.format(apiName)
try:
res = self.getconn.sendExpression(exp)
res = self.sendExpression(exp)
except Exception as e:
errstr = "Exception {} raised: {}".format(type(e), e)
self._raise_error(errstr=errstr)
Expand Down Expand Up @@ -1233,8 +1234,8 @@ def getSolutions(self, varList=None, resultfile=None): # 12
return
# exit()
else:
resultVars = self.getconn.sendExpression("readSimulationResultVars(\"" + resFile + "\")")
self.getconn.sendExpression("closeSimulationResultFile()")
resultVars = self.sendExpression("readSimulationResultVars(\"" + resFile + "\")")
self.sendExpression("closeSimulationResultFile()")
if (varList == None):
return resultVars
elif (isinstance(varList, str)):
Expand All @@ -1243,10 +1244,10 @@ def getSolutions(self, varList=None, resultfile=None): # 12
self._raise_error(errstr=errstr)
return
exp = "readSimulationResult(\"" + resFile + '",{' + varList + "})"
res = self.getconn.sendExpression(exp)
res = self.sendExpression(exp)
npRes = np.array(res)
exp2 = "closeSimulationResultFile()"
self.getconn.sendExpression(exp2)
self.sendExpression(exp2)
return npRes
elif (isinstance(varList, list)):
# varList, = varList
Expand All @@ -1259,10 +1260,10 @@ def getSolutions(self, varList=None, resultfile=None): # 12
return
variables = ",".join(varList)
exp = "readSimulationResult(\"" + resFile + '",{' + variables + "})"
res = self.getconn.sendExpression(exp)
res = self.sendExpression(exp)
npRes = np.array(res)
exp2 = "closeSimulationResultFile()"
self.getconn.sendExpression(exp2)
self.sendExpression(exp2)
return npRes

def strip_space(self, name):
Expand Down Expand Up @@ -1591,7 +1592,7 @@ def optimize(self): # 21
cName = self.modelName
properties = ','.join("%s=%s" % (key, val) for (key, val) in list(self.optimizeOptions.items()))
optimizeError = ''
self.getconn.sendExpression("setCommandLineOptions(\"-g=Optimica\")")
self.sendExpression("setCommandLineOptions(\"-g=Optimica\")")
optimizeResult = self.requestApi('optimize', cName, properties)
self._check_error()

Expand Down Expand Up @@ -1682,7 +1683,7 @@ def linearize(self, lintime=None, simflags=None): # 22
except ModuleNotFoundError:
raise Exception("ModuleNotFoundError: No module named 'linearized_model'")
else:
errormsg = self.getconn.sendExpression("getErrorString()")
errormsg = self.sendExpression("getErrorString()")
raise ModelicaSystemError("Linearization failed: {} not found: {}".format(repr(linearFile), errormsg))

def getLinearInputs(self):
Expand Down