Log a Subset of Signals using fast restart

1 Ansicht (letzte 30 Tage)
Riccardo Spica
Riccardo Spica am 12 Jan. 2022
Beantwortet: Akshat Dalal am 22 Nov. 2023
Hello,
I am trying to log a subset of signals in a model by specifying a DataLoggingOverride in a Simulink.SimulationInput object.
Everything works as expected as long as I don't use fast restart, in which case the DataLoggingOverride seems to be ignored.
Fast restart significantly improves execution time when I simulate a large number Simulink.SimulationInput objects so I would really like to use it. However, I typically have different batches of simulations (sets of Simulink.SimulationInput arrays) and I don't need to log everything every time so I would like to be able to set different sets (or subsets if necessary) of signals to log for each batch within my scripts.
From the documentation of fastrestart it seems to be possible to change signals to log without reinitializing the model.
Here is a working example in r2021b
load_system(docpath(fullfile(docroot, 'toolbox', 'simulink', ...
'examples', 'ex_bus_logging')));
load_system(docpath(fullfile(docroot, 'toolbox', 'simulink', ...
'examples', 'ex_mdlref_counter_bus')));
mdl = 'ex_bus_logging';
blk = 'ex_bus_logging/IncrementBusCreator';
blkPort = 1;
load_system(mdl);
ov = Simulink.SimulationData.ModelLoggingInfo(mdl);
so = Simulink.SimulationData.SignalLoggingInfo(blk,blkPort);
ov.Signals(1) = so;
% create the simulation input
in = Simulink.SimulationInput(mdl);
in = in.setModelParameter('DataLoggingOverride',ov);
in = in.setModelParameter('SimulationMode', 'accelerator');
% Simulate without fastrestart
out = sim(in);
% observe that only the signal 'ex_bus_logging/IncrementBusCreator' is
% being logged as specified in ov
disp(out.topOut)
% Simulate again with fastrestart
out = sim(in, 'UseFastRestart', 'on');
% observe that signals are logged as specified in the model (ov is ignored)
disp(out.topOut)

Antworten (1)

Akshat Dalal
Akshat Dalal am 22 Nov. 2023
Hi Riccardo,
I understand that you want to log a subset of signals in your model while using the ‘fastRestart’ mode, but ‘DataLoggingOverride’ seems to be ignored and the signals specified in the model are logged.
This is a known issue, and it has been resolved in R2022b. I would recommend you to either upgrade to MATLAB R2022b or If you would like to continue using R2021b, an alternative solution would be to use the ‘preSimFcn’ to set ‘fastRestart’ to ‘ON’ as shown in the pseudocode below.
for i =1:N
in(i) = in(i).setModelParameter('DataLoggingOverride',mi);
in(i) = in(i).setPreSimFcn(@(x) myPreSim(x));
end
out_parsim = parsim(in)
function myPreSim(in)
set_param(in.ModelName,'FastRestart','on');
end
To read more about the ‘preSimFcn’, please refer the following documentation: https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.setpresimfcn.html
I hope this helps.

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by