rtp and rapid accelerator mode Vs Inital State configuration
5 次查看(过去 30 天)
显示 更早的评论
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:
https://www.mathworks.com/help/simulink/slref/simulink.blockdiagram.buildrapidacceleratortarget.html
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 个评论
Riccardo Spica
2021-3-12
Hi Pablo,
I think I am running into the very same issue.
Have you found a solution in the meantimie?
Thanks.
Riccardo
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!