如何使用Ompython覆盖模型系统中的数组?
我正在使用OpenModelica从事一个项目。我正在尝试多次模拟系统,并编写了Python脚本以自动化它。我还覆盖了模拟的每次迭代中的参数,但是如果我尝试覆盖一个数组,我会在控制台上获得此内容:
Traceback (most recent call last):
File "pythonScripts/testing.py", line 164, in <module>
startSimulation(5,2,1,4, noFault,flyZone[1])
File "pythonScripts/testing.py", line 118, in startSimulation
vars = omc.sendExpression("readSimulationResult(\"System_res.mat\",{time})")
File "/home/francesco/.local/lib/python3.8/site-packages/OMPython/__init__.py", line 779, in sendExpression
answer = OMTypedParser.parseString(result)
File "/home/francesco/.local/lib/python3.8/site-packages/OMPython/OMTypedParser.py", line 120, in parseString
res = omcGrammar.parseString(string)
File "/home/francesco/.local/lib/python3.8/site-packages/pyparsing/core.py", line 1143, in parse_string
raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found '(' (at char 4), (line:1, col:5)
这是我如何做到的示例:
def startSimulation(n, intr, miss, statObs, fault, flyZone):
with open("newValues.txt", 'wt') as f:
f.write("const.N="+str(n)+"\n")
f.write("const.nIntr="+str(intr)+"\n")
f.write("const.nRocket="+str(miss)+"\n")
f.write("const.nStatObs="+str(statObs)+"\n")
f.write("fault.transMatrix[4,4]="+str(fault)+"\n")
f.write("const.flyZone[3]="+flyZone+"\n")
f.flush()
os.fsync(f)
os.system("./System -overrideFile=newValues.txt >> LogOverride")
noFault = "[1, 0, 0, 0; 1, 0, 0, 0; 1, 0, 0, 0; 1, 0, 0, 0]"
flyZone = ["{100,100,100}","{150,150,150}","{200,200,200}"]
startSimulation(5,2,1,4, noFault,flyZone[1])
有什么建议吗?
I'm working on a project, using openmodelica. I'm trying to simulate the system multiple times and i wrote a python script to automatize it. I also override parameters on each iteration of the simulation, but if i try to override an array i'll get this on console:
Traceback (most recent call last):
File "pythonScripts/testing.py", line 164, in <module>
startSimulation(5,2,1,4, noFault,flyZone[1])
File "pythonScripts/testing.py", line 118, in startSimulation
vars = omc.sendExpression("readSimulationResult(\"System_res.mat\",{time})")
File "/home/francesco/.local/lib/python3.8/site-packages/OMPython/__init__.py", line 779, in sendExpression
answer = OMTypedParser.parseString(result)
File "/home/francesco/.local/lib/python3.8/site-packages/OMPython/OMTypedParser.py", line 120, in parseString
res = omcGrammar.parseString(string)
File "/home/francesco/.local/lib/python3.8/site-packages/pyparsing/core.py", line 1143, in parse_string
raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found '(' (at char 4), (line:1, col:5)
This is an example of how i did it:
def startSimulation(n, intr, miss, statObs, fault, flyZone):
with open("newValues.txt", 'wt') as f:
f.write("const.N="+str(n)+"\n")
f.write("const.nIntr="+str(intr)+"\n")
f.write("const.nRocket="+str(miss)+"\n")
f.write("const.nStatObs="+str(statObs)+"\n")
f.write("fault.transMatrix[4,4]="+str(fault)+"\n")
f.write("const.flyZone[3]="+flyZone+"\n")
f.flush()
os.fsync(f)
os.system("./System -overrideFile=newValues.txt >> LogOverride")
noFault = "[1, 0, 0, 0; 1, 0, 0, 0; 1, 0, 0, 0; 1, 0, 0, 0]"
flyZone = ["{100,100,100}","{150,150,150}","{200,200,200}"]
startSimulation(5,2,1,4, noFault,flyZone[1])
Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
生成C代码时,OpenModelica将将数组扩展到标量,因此您需要在NewValues.txt中分别覆盖每个数组元素:
OpenModelica will expand arrays into scalars when the C code is generated so you need to override each of the array elements separately in newValues.txt: