Skip to content

Commit 0c80af6

Browse files
ondras12345lochel
authored andcommitted
Add debug logging to ModelicaSystem sendExpression
1 parent 6064ba9 commit 0c80af6

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

OMPython/__init__.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
717717
## set default command Line Options for linearization as
718718
## linearize() will use the simulation executable and runtime
719719
## flag -l to perform linearization
720-
self.getconn.sendExpression("setCommandLineOptions(\"--linearizationDumpLanguage=python\")")
721-
self.getconn.sendExpression("setCommandLineOptions(\"--generateSymbolicLinearization\")")
720+
self.sendExpression("setCommandLineOptions(\"--linearizationDumpLanguage=python\")")
721+
self.sendExpression("setCommandLineOptions(\"--generateSymbolicLinearization\")")
722722

723723
self.setTempDirectory(customBuildDirectory)
724724

@@ -736,14 +736,14 @@ def setCommandLineOptions(self, commandLineOptions: str):
736736
## set commandLineOptions if provided by users
737737
if commandLineOptions is not None:
738738
exp = "".join(["setCommandLineOptions(", "\"", commandLineOptions, "\"", ")"])
739-
cmdexp = self.getconn.sendExpression(exp)
739+
cmdexp = self.sendExpression(exp)
740740
if not cmdexp:
741741
self._check_error()
742742

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

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

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

837837
def _check_error(self):
838-
errstr = self.getconn.sendExpression("getErrorString()")
838+
errstr = self.sendExpression("getErrorString()")
839839
if errstr is None or not errstr:
840840
return
841841

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

868868
def sendExpression(self, expr, parsed=True):
869+
logger.debug("sendExpression(%r, %r)", expr, parsed)
869870
return self.getconn.sendExpression(expr, parsed)
870871

871872
# request to OMC
@@ -880,7 +881,7 @@ def requestApi(self, apiName, entity=None, properties=None): # 2
880881
else:
881882
exp = '{}()'.format(apiName)
882883
try:
883-
res = self.getconn.sendExpression(exp)
884+
res = self.sendExpression(exp)
884885
except Exception as e:
885886
errstr = "Exception {} raised: {}".format(type(e), e)
886887
self._raise_error(errstr=errstr)
@@ -1233,8 +1234,8 @@ def getSolutions(self, varList=None, resultfile=None): # 12
12331234
return
12341235
# exit()
12351236
else:
1236-
resultVars = self.getconn.sendExpression("readSimulationResultVars(\"" + resFile + "\")")
1237-
self.getconn.sendExpression("closeSimulationResultFile()")
1237+
resultVars = self.sendExpression("readSimulationResultVars(\"" + resFile + "\")")
1238+
self.sendExpression("closeSimulationResultFile()")
12381239
if (varList == None):
12391240
return resultVars
12401241
elif (isinstance(varList, str)):
@@ -1243,10 +1244,10 @@ def getSolutions(self, varList=None, resultfile=None): # 12
12431244
self._raise_error(errstr=errstr)
12441245
return
12451246
exp = "readSimulationResult(\"" + resFile + '",{' + varList + "})"
1246-
res = self.getconn.sendExpression(exp)
1247+
res = self.sendExpression(exp)
12471248
npRes = np.array(res)
12481249
exp2 = "closeSimulationResultFile()"
1249-
self.getconn.sendExpression(exp2)
1250+
self.sendExpression(exp2)
12501251
return npRes
12511252
elif (isinstance(varList, list)):
12521253
# varList, = varList
@@ -1259,10 +1260,10 @@ def getSolutions(self, varList=None, resultfile=None): # 12
12591260
return
12601261
variables = ",".join(varList)
12611262
exp = "readSimulationResult(\"" + resFile + '",{' + variables + "})"
1262-
res = self.getconn.sendExpression(exp)
1263+
res = self.sendExpression(exp)
12631264
npRes = np.array(res)
12641265
exp2 = "closeSimulationResultFile()"
1265-
self.getconn.sendExpression(exp2)
1266+
self.sendExpression(exp2)
12661267
return npRes
12671268

12681269
def strip_space(self, name):
@@ -1591,7 +1592,7 @@ def optimize(self): # 21
15911592
cName = self.modelName
15921593
properties = ','.join("%s=%s" % (key, val) for (key, val) in list(self.optimizeOptions.items()))
15931594
optimizeError = ''
1594-
self.getconn.sendExpression("setCommandLineOptions(\"-g=Optimica\")")
1595+
self.sendExpression("setCommandLineOptions(\"-g=Optimica\")")
15951596
optimizeResult = self.requestApi('optimize', cName, properties)
15961597
self._check_error()
15971598

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

16881689
def getLinearInputs(self):

0 commit comments

Comments
 (0)