OpenModelica和JModelica提供明显不同的结果 [英] OpenModelica and JModelica deliver significantly different results

查看:342
本文介绍了OpenModelica和JModelica提供明显不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题之后,我正在尝试比较JModelica和OpenModelica之间的仿真结果. Modelica文件与上述文章相同,并且JModelica包装器是更正的版本:

Following this question, I'm trying to compare the results of the simulation between JModelica and OpenModelica. The Modelica file is identical to the above-mentioned post and the JModelica wrapper is the corrected version:

#%%
from pymodelica import compile_fmu
from pyfmi import load_fmu
import matplotlib.pylab as plt

#%%
model_name = 'friction1D.fricexample_1'
mofile = 'friction1D.mo'

#%%
fmu_name = compile_fmu(model_name, mofile)
sim = load_fmu(fmu_name)

#%%
opts = sim.simulate_options()
opts["ncp"] = 500
opts['CVode_options']['rtol'] = 1.0e-8
res = sim.simulate(final_time=10, options=opts)

#%%
time = res['time']
vel = res['v']
ffo = res['ffo']
sfo = res['sfo']

#%%
plt.plot(time, vel)
plt.xlabel("Time (s)")
plt.ylabel("Velocity (m/s)")
plt.show()

#%%
plt.plot(time, ffo, label="friction force")
plt.plot(time, sfo, label="shear force")
plt.xlabel("Time (s)")
plt.ylabel("Force (N)")
plt.legend()
plt.show()

导致:


               
                      Fig.1 - Velocity versus time solved by JModelica.                


               
           Fig.2 - Friction and shear force versus time solved by JModelica.                

但是如果我在OpenModelica中将模拟选项设置为:

but if I set the simulation options in OpenModelica as:


                     
                    Fig.3 - Simulation options in OpenModelica.                

其结果是:


               
                   Fig.4 - Velocity versus time solved by OpenModelica.                


               
        Fig.5 - Friction and shear force versus time solved by OpenModelica.                


如果您能帮助我知道为什么结果如此不同以及如何使用这两种不同的编译器实现相似的模拟,我将不胜感激.


I would appreciate it if you could help me know why the results are so different and how I can achieve a similar simulation with these two different compilers.

PS 发布了一个后续问题

P.S. posted a follow-up question here on the OpenModelica forum.

推荐答案

首先我在上一篇文章中提到的代码是错误的.除了已经讨论过的一些小问题之外,此处中提及.

First of all the code, I had mentioned in my previous post was wrong. In addition to some small issues which have been discussed here, one should use the noEvent function to be sure the conditions of an if-statement are compiled correctly (more info here). The correct version of the code is mentioned here.

Christian Winther 指示JModelica提供与OpenModelica类似的结果 参数.我将选项设置为:

For JModelica to deliver similar results as OpenModelica I was instructed by Christian Winther here to play with the opts["CVode_options"]["maxh"] parameter which has a default value of 0. I set the option to:

opts['CVode_options']['maxh'] = 0.01

和JModelica工作正常.

and JModelica worked fine.

这篇关于OpenModelica和JModelica提供明显不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆