与Ompython进行模拟的停止时间

发布于 2025-01-26 08:34:29 字数 391 浏览 0 评论 0原文

我正在开发OpenModelica中的系统,该系统在各种模拟中设计了一群无人机的行为。现在,我想通过Ompython获得仿真结果,因为我将使用matplotlib制作各种KPI的图表。如果我想获得值,则OpenModelica脚本功能需要:

val(字符串valueName,实时点,字符串文件);

我想在模拟的末尾进行值。问题是模拟停止时间不是恒定的!那么,是否有一个函数可以检索模拟的停止时间?

编辑1
我设法使用 simulate 函数在Python中检索了此信息。但是我想使用 buildmodel 函数,因为使用它,我可以更改系统中的变量并再次仿真而没有任何问题。有建议吗?

i'm developing a system in openmodelica which design the behaviour of a swarm of drone in various simulation. Now, i want to get the simulation result with OMPython, because i will use matplotlib to make charts of the various KPI. If i want to get values, the openmodelica scripting function requires:

val(String valueName, Real timePoint, String file);

And i want to take the value at the end of the simulation. The problem is that the simulation stop time is not constant! So, is there a function to retrieve the stop time of the simulation?

EDIT 1:
I managed to retrieve this information in python using the simulate function. But i want to use BuildModel function, because with it i can change variables in the system and simulate again without any problem. any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ弥猫深巷。 2025-02-02 08:34:29

您可以在模拟后读取结果文件,以获取停止时间。您确实需要阅读整个矢量,因为没有API只能获得最后一次。 (也可以使用其他Python软件包打开垫子文件;如果您想对结果中的数据执行更多操作,这可能会更容易):

installPackage(Modelica);
loadModel(Modelica);getErrorString();
simulate(Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum, fileNamePrefix="M");
// Or buildModel(...); system("./M"), etc...
vars:=readSimulationResult("M_res.mat",{time});getErrorString();
stopTime:=vars[1,end];

You can read the result-file after the simulation in order to get the stopTime. You do need to read the entire vector since there is no API to just get the last time though. (It is also possible to open the mat-file using other Python packages; this might be easier if you want to perform more operations on the data in the results):

installPackage(Modelica);
loadModel(Modelica);getErrorString();
simulate(Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum, fileNamePrefix="M");
// Or buildModel(...); system("./M"), etc...
vars:=readSimulationResult("M_res.mat",{time});getErrorString();
stopTime:=vars[1,end];
人事已非 2025-02-02 08:34:29

您可以使用将终止时间存储在模型本身中:

model StoreFinalTime
Real t_stop;
equation
when terminal() then
  t_stop = time;
end when;
end StoreFinalTime;

You could use terminal() to store the termination time in the model itself:

model StoreFinalTime
Real t_stop;
equation
when terminal() then
  t_stop = time;
end when;
end StoreFinalTime;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文