rtp and rapid accelerator mode Vs Inital State configuration

5 ビュー (過去 30 日間)
Pablo Nanez
Pablo Nanez 2019 年 11 月 12 日
コメント済み: Pablo Nanez 2021 年 3 月 12 日
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 件のコメント
Riccardo Spica
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
Pablo Nanez
Pablo Nanez 2021 年 3 月 12 日
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 :)

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by