How to be sure that the Simulink model is receiving right tunable parameters?

2 Ansichten (letzte 30 Tage)
sali
sali am 30 Jan. 2019
Bearbeitet: sali am 31 Jan. 2019
I have this piece of code in Matlab 2015b under Unix, I want to run the model 10000 times each time the model should receive 9 different inputs (K1 to K9), so I chose to run it under rapid accelerator mode with par for, in the model I used 9 Gain blocks to pass these inputs as in the attached snapshot, my questions are :
1- Did I define it right ? and how to know if the model received the inputs properly, since the final results are not accurate!
2- Is there anything I should do in the model itself such as model workspace, inline parameters and so on?
3- The simulation does not work unless I put any value for K variables, as I put it here as 1 (K1.Value=1;and so on ,...........) , so shall I put any value ? Will that value affect the rest of the simulation?
4-What is the meaning of the Checksum?
Any help would be appreciated.
numParamSets = 10000;
K1 = Simulink.Parameter;
K2 = Simulink.Parameter;
K3 = Simulink.Parameter;
K4 = Simulink.Parameter;
K5 = Simulink.Parameter;
K6 = Simulink.Parameter;
K7 = Simulink.Parameter;
K8 = Simulink.Parameter;
K9 = Simulink.Parameter;
K1.CoderInfo.StorageClass = 'SimulinkGlobal';
K2.CoderInfo.StorageClass = 'SimulinkGlobal';
K3.CoderInfo.StorageClass = 'SimulinkGlobal';
K4.CoderInfo.StorageClass = 'SimulinkGlobal';
K5.CoderInfo.StorageClass = 'SimulinkGlobal';
K6.CoderInfo.StorageClass = 'SimulinkGlobal';
K7.CoderInfo.StorageClass = 'SimulinkGlobal';
K8.CoderInfo.StorageClass = 'SimulinkGlobal';
K9.CoderInfo.StorageClass = 'SimulinkGlobal';
%
K1.Value=1;
K2.Value=1;
K3.Value=1;
K4.Value=1;
K5.Value=1;
K6.Value=1;
K7.Value=1;
K8.Value=1;
K9.Value=1;
paramSets = cell(1, numParamSets);
idx = 1;
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
close_system(mdl, 0);
for page = 1:10000
paramSets{idx} = Simulink.BlockDiagram.modifyTunableParameters(...
rtp,...
'K1',PartialArray(1,1,page),...
'K2' ,PartialArray(1,2,page),...
'K3',PartialArray(1,3,page),...
'K4' ,PartialArray(2,1,page),...
'K5',PartialArray(2,2,page),...
'K6',PartialArray(2,3,page),...
'K7',PartialArray(3,1,page),...
'K8' ,PartialArray(3,2,page),...
'K9' ,PartialArray(3,3,page));
idx = idx+1;
end
numSimCmdArgStructs = numParamSets;
simCmdParamValStructs = cell(1, numSimCmdArgStructs);
paramValStruct.SaveTime = 'on';
paramValStruct.SaveOutput = 'on';
paramValStruct.SimulationMode = 'rapid';
paramValStruct.RapidAcceleratorUpToDateCheck = 'off';
paramValStruct.RapidAcceleratorParameterSets = [];
paramValStruct.LimitDataPoints = 'off';
idx = 1;
for paramSetsIdx = 1:numParamSets
simCmdParamValStructs{idx} = paramValStruct;
simCmdParamValStructs{idx}.RapidAcceleratorParameterSets = paramSets{paramSetsIdx};
idx = idx + 1;
end
out = cell(1, numSimCmdArgStructs);
parfor(i = 1:numSimCmdArgStructs)
out{i} = sim(mdl, simCmdParamValStructs{i});
close_system(mdl, 0);
end

Antworten (1)

Mark McBroom
Mark McBroom am 30 Jan. 2019
I found this in the help. Looks like you need to set RapidAcceleratorUpToDateCheck to 'on'
Accelerator and SIL/PIL Simulations
These tunability limitations apply to accelerator, rapid accelerator, SIL, and PIL simulations:
  • Suppose you use a MATLAB variable or Simulink.Parameter object in a model workspace to set the value of a block parameter in a model. If you use the sim function to simulate the model in rapid accelerator mode and set the RapidAcceleratorUpToDateCheck pair argument to 'off', you cannot use the RapidAcceleratorParameterSets pair argument to specify different values for the variable or object. The structure returned by Simulink.BlockDiagram.buildRapidAcceleratorTarget does not contain information about the variable or object.
  • If a block parameter value references workspace variables, you cannot change the block parameter value during rapid accelerator simulation, such as by using the function set_param. Instead, you can tune the values of the referenced variables.Alternatively, use parameter sets to tune runtime parameters in between rapid accelerator simulations. For more information, see Tuning Runtime Parameters.
For more information about parameter tunability during accelerated simulations, see Tuning Runtime Parameters and sim in parfor with Rapid Accelerator Mode. For more information about parameter tunability during SIL and PIL simulations, see Tunable Parameters and SIL/PIL (Embedded Coder).
  1 Kommentar
sali
sali am 31 Jan. 2019
Bearbeitet: sali am 31 Jan. 2019
Thanks Marks for your answer but why different information is mentioned in the Guy on Simulink website? that is what is confusing me !
https://blogs.mathworks.com/simulink/2015/03/19/getting-the-most-out-of-rapid-accelerator-mode/?s_tid=srchtitle

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Event Functions 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