@@ -798,18 +798,14 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
798798 Note: If the model file is not in the current working directory, then the path where file is located must be included together with file name. Besides, if the Modelica model contains several different models within the same package, then in order to build the specific model, in second argument, user must put the package name with dot(.) followed by specific model name.
799799 ex: myModel = ModelicaSystem("ModelicaModel.mo", "modelName")
800800 """
801-
802801 if fileName is None and modelName is None and not lmodel : # all None
803802 if useCorba :
804803 self .getconn = OMCSession ()
805804 else :
806805 self .getconn = OMCSessionZMQ ()
807806 return
808807
809- if fileName is None :
810- return "File does not exist"
811808 self .tree = None
812-
813809 self .quantitiesList = []
814810 self .paramlist = {}
815811 self .inputlist = {}
@@ -830,6 +826,10 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
830826 else :
831827 self .getconn = OMCSessionZMQ ()
832828
829+ ## needed for properly deleting the OMCSessionZMQ
830+ self ._omc_log_file = self .getconn ._omc_log_file
831+ self ._omc_process = self .getconn ._omc_process
832+
833833 ## set commandLineOptions if provided by users
834834 if commandLineOptions is not None :
835835 exp = "" .join (["setCommandLineOptions(" ,"\" " ,commandLineOptions ,"\" " ,")" ])
@@ -846,7 +846,7 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
846846 self .resultfile = "" # for storing result file
847847 self .variableFilter = variableFilter
848848
849- if not os .path .exists (self .fileName ): # if file does not eixt
849+ if fileName is not None and not os .path .exists (self .fileName ): # if file does not eixt
850850 print ("File Error:" + os .path .abspath (self .fileName ) + " does not exist!!!" )
851851 return
852852
@@ -856,19 +856,37 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
856856 self .getconn .sendExpression ("setCommandLineOptions(\" --linearizationDumpLanguage=python\" )" )
857857 self .getconn .sendExpression ("setCommandLineOptions(\" --generateSymbolicLinearization\" )" )
858858
859- self .loadingModel ()
859+ self .setTempDirectory ()
860+
861+ if fileName is not None :
862+ self .loadFile ()
863+
864+ ## allow directly loading models from MSL without fileName
865+ if fileName is None and modelName is not None :
866+ self .loadLibrary ()
867+
868+ self .buildModel ()
860869
861870 def __del__ (self ):
862871 OMCSessionBase .__del__ (self )
863872
864- # for loading file/package, loading model and building model
865- def loadingModel (self ):
873+ def setCommandLineOptions (self ):
874+ ## set commandLineOptions if provided by users
875+ if commandLineOptions is not None :
876+ exp = "" .join (["setCommandLineOptions(" ,"\" " ,commandLineOptions ,"\" " ,")" ])
877+ cmdexp = self .getconn .sendExpression (exp )
878+ if not cmdexp :
879+ return print (self .getconn .sendExpression ("getErrorString()" ))
880+
881+ def loadFile (self ):
866882 # load file
867883 loadFileExp = "" .join (["loadFile(" ,"\" " ,self .fileName ,"\" " ,")" ]).replace ("\\ " ,"/" )
868884 loadMsg = self .getconn .sendExpression (loadFileExp )
869885 if not loadMsg :
870886 return print (self .getconn .sendExpression ("getErrorString()" ))
871887
888+ # for loading file/package, loading model and building model
889+ def loadLibrary (self ):
872890 # load Modelica standard libraries or Modelica files if needed
873891 for element in self .lmodel :
874892 if element is not None :
@@ -892,6 +910,7 @@ def loadingModel(self):
892910 if loadmodelError :
893911 print (loadmodelError )
894912
913+ def setTempDirectory (self ):
895914 # create a unique temp directory for each session and build the model in that directory
896915 self .tempdir = tempfile .mkdtemp ()
897916 if not os .path .exists (self .tempdir ):
@@ -900,7 +919,8 @@ def loadingModel(self):
900919 exp = "" .join (["cd(" ,"\" " ,self .tempdir ,"\" " ,")" ]).replace ("\\ " ,"/" )
901920 self .getconn .sendExpression (exp )
902921
903- self .buildModel ()
922+ def getWorkDirectory (self ):
923+ return self .tempdir
904924
905925 def buildModel (self , variableFilter = None ):
906926 if variableFilter is not None :
0 commit comments