Opened 7 years ago

Last modified 7 years ago

#4698 new defect

OMPython + 'Failed to build model: BouncingBall'

Reported by: msoliman.w@… Owned by: somebody
Priority: high Milestone: Future
Component: *unknown* Version:
Keywords: Cc:

Description

Trying to use OMPython to simulate Modelica Models. I tried the example in the help and it failed. Below are the sequence of commands. Not sure what is wrong. Please help. Thanks

In [2]: from OMPython import OMCSessionZMQ

...: omc = OMCSessionZMQ()

2017-12-25 15:33:30,137 - OMPython - INFO - OMC Server is up and running at file:///C:/Users/msoli/AppData/Local/Temp/openmodelica.port.dbdec2bfec4f4db88c5a79f56907c637

In [3]: omc.sendExpression("getVersion()")
Out[3]: 'v1.12.0 (64-bit)'

In [4]: omc.sendExpression("cd()")
Out[4]: 'C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_64'

In [5]: omc.sendExpression("loadModel(Modelica)")
Out[5]: True

In [6]: omc.sendExpression("loadFile(getInstallationDirectoryPath() + \"/share/doc/omc/testmodels/BouncingBall.mo\")")
Out[6]: True

In [7]: omc.sendExpression("instantiateModel(BouncingBall)")
Out[7]: 'class BouncingBall\n parameter Real e = 0.7 "coefficient of restitution";\n parameter Real g = 9.810000000000001 "gravity acceleration";\n Real h(start = 1.0) "height of ball";\n Real v "velocity of ball";\n Boolean flying(start = true) "true, if ball is flying";\n Boolean impact;\n Real v_new;\n Integer foo;\nequation\n impact = h <= 0.0;\n foo = if impact then 1 else 2;\n der(v) = if flying then -g else 0.0;\n der(h) = v;\n when {h <= 0.0 and v <= 0.0, impact} then\n v_new = if edge(impact) then (-e) * pre(v) else 0.0;\n flying = v_new > 0.0;\n reinit(v, v_new);\n end when;\nend BouncingBall;\n'

In [8]: omc.sendExpression("simulate(BouncingBall, stopTime=3.0)")
Out[8]:
{'messages': 'Failed to build model: BouncingBall',

'resultFile': ,
'simulationOptions': "startTime = 0.0, stopTime = 3.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'BouncingBall', options =
, outputFormat = 'mat', variableFilter = '.*', cflags = , simflags = ",
'timeBackend': 0.0,
'timeCompile': 0.0,
'timeFrontend': 0.0,
'timeSimCode': 0.0,
'timeSimulation': 0.0,
'timeTemplates': 0.0,
'timeTotal': 0.0}

Change History (1)

comment:1 by Martin Sjölund, 7 years ago

Call getErrorString() and you should see an error-message.

Note: See TracTickets for help on using tickets.