在 FMIKit-Simulink 中创建所有当前变量及其各自值的列表
Create a list of all current variables and their respective values in FMIKit-Simulink
我目前正在使用 FMIKit for Simulink 在此处找到 https://github.com/CATIA-Systems/FMIKit-Simulink
根据文档,使用 FMIKit.getStartValue(FMUBLOCK, 'Variablename');
可以很好地查询 FMU 中的参数值
但前提是您知道要查找的变量的名称和结构。
我想知道是否有一种方法可以在我开始模拟之前提取 FMU 中变量的完整列表及其值(用于 sim 调试目的)?
您可以通过阅读FMU的模型描述来获取模型变量的起始值(例如FMI 2.0 Test FMUs中的VanDerPol.fmu):
% import the FMU and select the FMU block
% set a different start value for variable "mu"
FMIKit.setStartValue(gcb, 'mu', '1.3');
% read the model description (returns a Java object)
md = FMIKit.getModelDescription('VanDerPol.fmu');
% iterate over the list of variables
for i = 1:md.scalarVariables.size
v = md.scalarVariables.get(i-1);
% get the name and start value
name = char(v.name);
% get the start value from the FMU block
start = FMIKit.getStartValue(gcb, name); % might be empty
disp([name ': ' start])
end
给你
x0: 2
der(x0):
x1: 0
der(x1):
mu: 1.3
我目前正在使用 FMIKit for Simulink 在此处找到 https://github.com/CATIA-Systems/FMIKit-Simulink
根据文档,使用 FMIKit.getStartValue(FMUBLOCK, 'Variablename');
可以很好地查询 FMU 中的参数值但前提是您知道要查找的变量的名称和结构。
我想知道是否有一种方法可以在我开始模拟之前提取 FMU 中变量的完整列表及其值(用于 sim 调试目的)?
您可以通过阅读FMU的模型描述来获取模型变量的起始值(例如FMI 2.0 Test FMUs中的VanDerPol.fmu):
% import the FMU and select the FMU block
% set a different start value for variable "mu"
FMIKit.setStartValue(gcb, 'mu', '1.3');
% read the model description (returns a Java object)
md = FMIKit.getModelDescription('VanDerPol.fmu');
% iterate over the list of variables
for i = 1:md.scalarVariables.size
v = md.scalarVariables.get(i-1);
% get the name and start value
name = char(v.name);
% get the start value from the FMU block
start = FMIKit.getStartValue(gcb, name); % might be empty
disp([name ': ' start])
end
给你
x0: 2
der(x0):
x1: 0
der(x1):
mu: 1.3