def run(self):
     global omc
     del (omc)
     omc = OMCSession()
     omc.sendExpression("setModelicaPath(\"" + omhome + "/lib/omlibrary\")")
     omc.sendExpression('cd("tmp")')
     return []
Esempio n. 2
0
 def __init__(self, rootPath):
     '''
     Constructor starts omc and loads MSL
     '''
     self.rootPath = rootPath
     self.omc = OMCSession()
     os.chdir(self.rootPath)
     self.omc.sendExpression("loadModel(Modelica)")
Esempio n. 3
0
def createsession():
    ## Create a new omc session for the users and allot a seperate working directory for the session ##
    #print 'creating omc session'
    session['msg'] = []
    session['mat'] = []
    sid = request.form['sid']
    session['tmpdir'] = tempfile.mkdtemp()
    #print session['tmpdir']
    os.chdir(session['tmpdir'])
    sess = OMCSession()
    sessionobj[sid] = sess
    #print sessionobj
    #sys.stdout.flush()
    return "success"
Esempio n. 4
0
    def __init__(self, modelName, modelFileName, config):

        Plugins.Simulator.SimulatorBase.Model.__init__(self, modelName,
                                                       modelFileName,
                                                       'OpenModelica', config)
        self._omc = OMCSession()
        self.onlyResultFile = False
        self.integrationSettings.resultFileExtension = 'mat'

        self._availableIntegrationAlgorithms = [
            'Dassl', 'Euler', 'Rungekutta', 'Dopri5'
        ]
        self.integrationSettings.algorithmName = self._availableIntegrationAlgorithms[
            0]

        self._IntegrationAlgorithmHasFixedStepSize = [False, True, True, False]
        self._IntegrationAlgorithmCanProvideStepSizeResults = [
            False, True, True, False
        ]

        self.compileModel()

        if self.resFile != '""':
            self._initialResult = loadResultFileInit(
                os.path.join(os.getcwd(), self.name + "_init.xml"))
        else:
            print "The selected model could not be instantiated, check for any dependencies that the model might have"
            return

        # SocketServer setup to visualize the simulation progress bar
        HOST, PORT = "localhost", 0
        self.server = SocketServer.TCPServer((HOST, PORT),
                                             ThreadedTCPRequestHandler)
        self.ip, self.port = self.server.server_address
        self.server_port = self.port

        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.daemon = True
        self.server_thread.setDaemon(True)
        self.server_thread.start()
def createOmcSession():
    return OMCSession(
        docker=docker, dockerExtraArgs=dockerExtraArgs,
        timeout=5) if corbaStyle else OMCSessionZMQ(
            docker=docker, dockerExtraArgs=dockerExtraArgs, timeout=5)
Esempio n. 6
0
 def __init__(self, resources= None, settings= None):
     super(EngineOMC, self).__init__(resources, settings)
     self._omcSession= OMCSession()
     self._simulationResult= None
$\frac{dx}{dt} = ax$.

"""
code='''model Simple
    Real x(start=1);
    parameter Real a=1;
equation
    der(x)=a*x;
end Simple;''' # модель мовою Modelica 
with open('Simple.mo', 'w') as f: f.write(code) # створити файл моделі
import os, sys
sys.path.insert(0, r"e:\OpenModelica\share\omc\scripts\PythonInterface") # шлях до модулів
from OMPython import OMCSession, ModelicaSystem

# перший спосіб - використання OMCSession:
omc = OMCSession()
omc.sendExpression('loadFile("Simple.mo")')
omc.sendExpression('setParameterValue(Simple, a, 2)')
omc.sendExpression('simulate(Simple)')
omc.sendExpression('plot(x)')
print omc.sendExpression('val(x , 1.0)') # результат x(time=1.0)

# або більш зручний спосіб:
mod=ModelicaSystem("Simple.mo","Simple")
print mod.getParameters()
mod.setParameters(a=2)
mod.setSimulationOptions(stopTime=2.0)
mod.simulate()
print mod.getSolutions('time','x') # результати як масиви

# або компілювати модель і симулювати без OMPython:
Esempio n. 8
0
 def __init__(self, **kwargs):
     Kernel.__init__(self, **kwargs)
     self.omc = OMCSession()
     self.matfile = None
        with open(errFile, 'a+') as fp:
            fp.write(
                "C++ FMI runtime not supported in this installation (HelloWorld failed or did not respect fileNamePrefix)"
            )
        writeResultAndExit(0)
    elif conf["simCodeTarget"] == "C" and not conf["haveFMI"]:
        with open(errFile, 'a+') as fp:
            fp.write(
                "C FMI runtime not supported in this installation (HelloWorld failed or did not respect fileNamePrefix)"
            )
        writeResultAndExit(0)

omhome = conf["omhome"]
os.environ["OPENMODELICAHOME"] = omhome

omc = OMCSession()
if ompython_omhome != "":
    os.environ["OPENMODELICAHOME"] = ompython_omhome
    omc_new = OMCSession()
else:
    omc_new = omc

cmd = 'setCommandLineOptions("%s")' % conf["single_thread_cmd"]
if not omc.sendExpression(cmd):
    raise Exception('Could not send %s' % cmd)

try:
    os.unlink("%s.tmpfiles" % conf["fileName"])
except:
    pass
#cmd = 'setCommandLineOptions("--running-testsuite=%s.tmpfiles")' % conf["fileName"]