示例#1
0
 def simulator(self):
     try:
         dymola = None
         dymola = DymolaInterface("C:/Program Files/Dymola 2019 FD01/bin64/Dymola.exe")
         openResult = dymola.openModel(self.packageName)
         print("                    openModel : ", openResult )   
         if not openResult:
             print("openModel is failed. Below is the translation log.")
             log = dymola.getLastErrorLog()
             print(log)
             exit(1)
         dymola.experimentSetupOutput(events=False)
         result = dymola.simulateExtendedModel(self.modelName,0.0, self.simTime, 0, self.deltaTime, "Radau", 0.00001, self.deltaTime, self.resultName, initialNames=self.handleModelParamName, initialValues=self.handleModelParamVal)
         
         print("                    simulateExtendedModel : ", result[0])
         if not result[0]:
             print("Simulation is failed. Below is the translation log.")
             log = dymola.getLastErrorLog()
             print(log)
             exit(1)
         
     except DymolaException as ex:
         print(("Error: " + str(ex)))
     finally:
         if dymola is not None:
             dymola.close()
             dymola = None
     return 0
示例#2
0
class DymolaLauncher(object):
    """
    Dymola Launcher
  """
    def __init__(self, **kwargs):
        """
      This class is aimed to launch Dymola jobs
      via the python interface
      @ In, kwargs, dict, the dictionary of options
    """
        from dymola.dymola_interface import DymolaInterface
        # intialize dymola
        cwd = os.getcwd()
        if sys.platform.startswith("win"):
            print("trying to find dymola executable")
            found = None
            for item in sys.path:
                if item.endswith("dymola.egg"):
                    found = item
            if found is not None:
                print("dymola found in: ", found)
                dymola_exe = os.path.join(
                    os.path.dirname(
                        os.path.dirname(os.path.dirname(
                            os.path.dirname(found)))), "bin64", "dymola.exe")
                print("dymola exe: ", dymola_exe)
                self.dymola = DymolaInterface(dymolapath=dymola_exe)
            else:
                print("dymola not found in", sys.path)
                self.dymola = DymolaInterface()
        else:
            self.dymola = DymolaInterface()
        self.workDir = kwargs.get("workingDir")
        if not os.path.isabs(self.workDir):
            self.workDir = os.path.join(cwd, self.workDir)
        print("swd", self.workDir, "cwd", cwd, "MODELICAPATH",
              os.environ.get("MODELICAPATH", ""))
        self.silent = kwargs.get("silent")
        self.dymola.cd(self.workDir)
        self.dymola.experimentSetupOutput(events=False)

    def run(self, input):
        """
      Run the input file
      @ In, input, str, the input file to run
      @ Out, None
    """
        self.returnOut = self.dymola.RunScript(input, silent=self.silent)

    def getResultOutput(self):
        """
      Return the result
      @ In, None
      @ Out, outcome, tuple, outcome (result, returnCode, log)
    """
        if not self.returnOut:
            outcome = (None, -1, self.dymola.getLastErrorLog())
        else:
            outcome = (self.returnOut, 0, self.dymola.getLastErrorLog())
        print("result", outcome)
        return outcome

    def close(self):
        """
      Finalize dymola
      @ In, None
      @ Out, None
    """
        self.dymola.close()