rtp and rapid accelerator mode Vs Inital State configuration

3 Ansichten (letzte 30 Tage)
Pablo Nanez
Pablo Nanez am 12 Nov. 2019
Kommentiert: Pablo Nanez am 12 Mär. 2021
For a particular system I require to use rapid accelerator mode.
Also, it is required to precompile the model and pass the parameters using rtp for speed improvements.
Up to this point, everything works fine as reported in:
The issue appears when I try to also use initial conditions that came from the Final states of previous simulations. Somehow, the rtp overrides the initial conditions.
The workflow is something like this:
1) build the model code using
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(sysModel)
2)Then run the model
simout = sim(sysModel,'SimulationMode','rapid',...
'RapidAcceleratorUpToDateCheck','off', ...
'RapidAcceleratorParameterSets',rtp);
3) Then retrieve the final state and save it as initial state for the next 'Batch'
states1 = simout.dataOutput;
xInitial = simout.xFinal;
xInitial.time = 0;
4) Now, activate the Initial State feature and provide the name of the variable
set_param(sysModel,'LoadInitialState', 'on');
set_param(sysModel,'InitialState', 'xInitial')
5) Simulate again (I was expecting to start from the final state of the previous simulation, but this does not work ? )
simout = sim(sysModel,'SimulationMode','rapid',...
'RapidAcceleratorUpToDateCheck','off', ...
'RapidAcceleratorParameterSets',rtp);
The only way that I was able to get the desired result was just rebuilding it, but that is exactly what I am trying to avoid.
Is there any way to include the initial conditions as parameters in the rtp structure? or something like that?
Here is a small example of the workflow that I am trying to implement:
%% load system
clc
sysModel = 'testRTPvsIniState';
open_system(sysModel);
%% Set first initial conditions
x0rtp = [0;1];
A = 1.1;
set_param(sysModel,'LoadInitialState', 'off');
set_param(sysModel,'StartTime','0');
set_param(sysModel,'StopTime','5');
%% compile the model
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(sysModel);
%% simulate for the first 5 seconds
tic
simout = sim(sysModel,'SimulationMode','rapid',...
'RapidAcceleratorUpToDateCheck','off', ...
'RapidAcceleratorParameterSets',rtp);
toc
%% Get the results
states1 = simout.dataOutput;
xInitial = simout.xFinal;
xInitial.time = 0;
%% Set new initial conditions
set_param(sysModel,'LoadInitialState', 'on');
set_param(sysModel,'InitialState', 'xInitial')
%% simulate using previous build
tic
simout = sim(sysModel,'SimulationMode','rapid',...
'RapidAcceleratorUpToDateCheck','off', ...
'RapidAcceleratorParameterSets',rtp);
toc
states2 = simout.dataOutput;
xInitial2 = simout.xFinal;
%% simulate using new build
% compile the model
rtp2 = Simulink.BlockDiagram.buildRapidAcceleratorTarget(sysModel);
tic
simout = sim(sysModel,'SimulationMode','rapid',...
'RapidAcceleratorUpToDateCheck','off', ...
'RapidAcceleratorParameterSets',rtp2);
toc
states3 = simout.dataOutput;
xInitial3 = simout.xFinal;
  2 Kommentare
Riccardo Spica
Riccardo Spica am 12 Mär. 2021
Hi Pablo,
I think I am running into the very same issue.
Have you found a solution in the meantimie?
Thanks.
Riccardo
Pablo Nanez
Pablo Nanez am 12 Mär. 2021
No, unfortunatelly I had to live with the rebuilds. I separated the code using variant subsystems, that reduced the rebuild time (since it was only rebuilding portions of the model). I just had to wait longer to get the results. We are already done with those results, so I think I am not going to try to solve this problem (at least for the near future). The issue was on 2018b so perhaps with the newest version you don't have the same problem. Good luck :)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by