简体   繁体   English

如何在 JModelica 中读取 .mat 输出文件?

[英]How to read .mat output files in JModelica?

To save the time, I'm trying to read the .mat file rather than simulate the model again.为了节省时间,我试图读取.mat文件而不是再次模拟模型。

I used scipy.io.loadmat but it didn't work well:我使用了scipy.io.loadmat但效果不佳:

res = loadmat('ChatteringControl_result.mat')
res.keys()

['Aclass', 'dataInfo', 'name', 'data_2', 'data_1', 'description']

The keys are not variable names, and I don't know how to get the variable values.键不是变量名,我不知道如何获取变量值。

Then I searched for resolutions, and found DyMat , it works well for other variables but cannot get time .然后我搜索了分辨率,并找到了DyMat它适用于其他变量但无法获取time

res1 = DyMat.DyMatFile('ChatteringControl_result.mat')
T = res1['T']
t = res1['time']

KeyError: 'time'

So, how can I get all the results in JModelica?(Without open Matlab of course.)Like, a built-in function in JModelica?那么,如何在 JModelica 中获得所有结果?(当然没有打开 Matlab。)比如 JModelica 中的内置函数?

BIG THANKS!十分感谢!

https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/technical_details.html#the-matv4-result-file-format describes the format. https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/technical_details.html#the-matv4-result-file-format描述了格式。 I think you can also look in a Dymola manual for more details.我认为您还可以查看 Dymola 手册以了解更多详细信息。

As for DyMat, there is no reason to get the time trajectory because you typically lookup what value a variable has at a certain time.对于 DyMat,没有理由获取时间轨迹,因为您通常会查找某个变量在某个时间具有的值。 The start and stop-times are in the data_1 matrix as far as I remember (or typically get it from the first trajectory in the data_2 matrix).据我所知,开始和停止时间都在 data_1 矩阵中(或者通常从 data_2 矩阵中的第一个轨迹中获取)。 (The data_2 matrix may be interpolated, so the time values stored in it may not reflect the actual steps taken internally by the solvers) (data_2 矩阵可能是内插的,因此存储在其中的时间值可能无法反映求解器内部采取的实际步骤)

To load the mat file using JModelica you can use this code:要使用 JModelica 加载 mat 文件,您可以使用以下代码:

from pyfmi.common.io import ResultDymolaBinary

res = ResultDymolaBinary("MyResult.mat")

var = res.get_variable_data("myVar")

var.t #Time trajectory
var.x #Variable trajectory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM