diff --git a/Py4Mod/py4mod/ModelicaModel.py b/Py4Mod/py4mod/ModelicaModel.py index 7fb8d803debe4b6c9ff7fe34a88396fa310c153c..a8062897c6481021d7e740098ee1bbf11660ea8f 100644 --- a/Py4Mod/py4mod/ModelicaModel.py +++ b/Py4Mod/py4mod/ModelicaModel.py @@ -1,3 +1,5 @@ +# -*- coding: latin -*- + from shutil import copyfile from shutil import copy from bisect import bisect @@ -13,8 +15,8 @@ class ModelicaModel(object): """ self._model = model # model identifier in package hierarchy [e.g. packageName.subPackageName.modelName] self._mainPath = mainPath # path where either the model file itself or the corresponding package.mo can be found - if not self._mainPath[-1] == "\\": - self._mainPath = self._mainPath + "\\" + if not self._mainPath[-1] == "/": + self._mainPath = self._mainPath + "/" self._modelName = self.getModelName() # actual name of model extracted from self._model self._modelPath = self.__getModelPath() # complete path of the model file deduced from self._mainPath and self._model self._modelLines = self.__readModel() @@ -476,7 +478,7 @@ class ModelicaModel(object): def __getModelPath(self): """Creates the modelpath out of the projectpath and the model.""" - modelpath = re.sub(r"\.", "\\\\", self._model) + modelpath = re.sub(r"\.", "/", self._model) modelpath = self._mainPath + modelpath + ".mo" return modelpath diff --git a/Py4Mod/py4mod/OMInterface.py b/Py4Mod/py4mod/OMInterface.py index 166294a00c194d564e9fba9ff6f5a6acb8951496..8351108dc0356c9e2303333da9769bc0bd0db38a 100644 --- a/Py4Mod/py4mod/OMInterface.py +++ b/Py4Mod/py4mod/OMInterface.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import os import sys import platform @@ -256,7 +257,9 @@ class OMInterface(object): #check_exeFile_ = os.path.exists(exeFile) if (os.path.exists(exeFile)): - omhome = os.path.join(os.environ.get("OPENMODELICAHOME"), 'bin').replace("\\", "/") + tmp_to_change = "/tmp/OpenModelica_" + os.environ['LOGNAME'] + "/OMEdit/" + #omhome = os.path.join(os.environ.get("OPENMODELICAHOME"), 'bin').replace("\\", "/") + omhome = os.path.join(tmp_to_change, 'bin').replace("\\", "/") my_env = os.environ.copy() my_env["PATH"] = omhome + os.pathsep + my_env["PATH"] #process = subprocess.Popen(cmd, cwd=self.changeWorkingDirectory(), env=my_env) @@ -280,10 +283,11 @@ class OMInterface(object): #print(output) rc = process.poll() - process.terminate() + if rc is not 0: + process.terminate() if (rc is not 0): - raise Exception(str(stderr)) #not tested + raise Exception(str(stderr)) # not tested self.__simulationFlag = True self.resultFileName = os.path.join(self.changeWorkingDirectory(), self.modelName + '_res.mat') diff --git a/Scripts/ModPowerSystemsCI/RunOMSimulationCI.py b/Scripts/ModPowerSystemsCI/RunOMSimulationCI.py index f4146c7f6d2beb392e451202548b0a94d2558107..33d609bc0f6f46fb9bff717c3f47a14e306d5b15 100644 --- a/Scripts/ModPowerSystemsCI/RunOMSimulationCI.py +++ b/Scripts/ModPowerSystemsCI/RunOMSimulationCI.py @@ -1,6 +1,7 @@ import os import sys -sys.path.append(r"D:\HIWI\Git\python-for-modelica-dev_interface\Py4Mod\py4mod") +os.chdir(r"/home/cafi/Desktop/CITest") +sys.path.append(r"./python-for-modelica/Py4Mod/py4mod") from ModelicaModel import ModelicaModel @@ -9,15 +10,22 @@ def simulate_modelica(model_name, model_path): # Initialization interface.createInterface("OPENMODELICA") - interface.loadFile(model_path + '\ModPowerSystems\package.mo') + interface.loadFile("/home/cafi/Desktop/CITest/modpowersystems/ModPowerSystems/package.mo") # Redirection cwd = os.getcwd() - wd = os.path.join(cwd, 'test') + wd = os.path.join(cwd, model_name) if not os.path.exists(wd): os.makedirs(wd) interface.changeWorkingDirectory(wd.replace("\\", "/")) # Build & Run interface.buildModel() - interface.simulate() \ No newline at end of file + interface.simulate() + + +name = 'ModPowerSystems.DynPhasorThreePhase.Examples.BasicCircuits.VoltageSource_RL' +path = './modpowersystems' + + +simulate_modelica(name, path) \ No newline at end of file