1

I am currently using FMIKit for Simulink found here https://github.com/CATIA-Systems/FMIKit-Simulink

From the documentation it works very well to query values of parameters within the FMU using FMIKit.getStartValue(FMUBLOCK, 'Variablename');

but only if you know the name and structure of the variable you are looking for.

I wanted to know if there is a way to extract the full list of variables in the FMU together with their values just before I start the simulation (for sim debugging purposes)?

1 Answers1

1

You can get the start values of the model variables by reading the model description of the FMU (e.g. the VanDerPol.fmu from the FMI 2.0 Test FMUs):

% 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

gives you

x0: 2
der(x0): 
x1: 0
der(x1): 
mu: 1.3
Torsten Sommer
  • 308
  • 1
  • 4
  • Hi Torsten , whilst this gives the values built into the FMU, it doesn't appear to register any changes resulting from using the FMIKit.setStartValue calls. What I am looking for is a report of all the values at any instant when the model is open – Maverick1182 Jan 09 '20 at 09:10
  • This method appears to capture changes made via the setStartValue() command. Is there a way to query the values of these parameters at once rather than one-at-a-time (in a similar way to setting multiple values in one setStartValue() statement, which works and is faster than multiple declarations of setStartValue()) in order to speed up the listing process? I have over 9000 parameters which means it currently takes several minutes to build the list of values for the model. – Maverick1182 Jan 13 '20 at 09:15
  • You can also get the [UserData struct](https://github.com/CATIA-Systems/FMIKit-Simulink/blob/master/docs/fmu_import.md#userdata-struct) from the FMU block and use the start values Map directly: `ud = get_param(gcb, 'UserData'); ud.startValues` – Torsten Sommer Jan 14 '20 at 14:05