How can I use parsim in combination with a Simulink Variant Subsystem
14 次查看(过去 30 天)
显示 更早的评论
Hello,
I included a Variant Subsystem into the following Simulink-model (which is just an example) and run it with "parsim" via a script. Thereby I get this error message, that I don't understand:
-------------
Error due to multiple causes.Caused by:
Variant control 'Variant_1' of variant block 'sldemo_suspn_3dof_variant/Variant Subsystem' must be a condition expression or name of a Simulink.Variant object in the global scope workspace of the model. Ensure that the condition does not match the model name.
Variant control 'Variant_2' of variant block 'sldemo_suspn_3dof_variant/Variant Subsystem' must be a condition expression or name of a Simulink.Variant object in the global scope workspace of the model. Ensure that the condition does not match the model name.
-------------
The Simulink.Variants Variant_1 and Variant_2 and the parameter Variant_Switch are all part of the workspace.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193604/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193606/image.png)
mdl = 'sldemo_suspn_3dof_variant';
isModelOpen = bdIsLoaded(mdl);
open_system(mdl);
delete(gcp('nocreate'));
Variant_Switch = 1;
Cf_sweep = Cf*(0.05:0.1:0.95);
numSims = length(Cf_sweep);
for i = numSims:-1:1
in(i) = Simulink.SimulationInput(mdl);
in(i) = setBlockParameter(in(i), [mdl '/Road-Suspension Interaction'], 'Cf', num2str(Cf_sweep(i)));
end
out = parsim(in, 'ShowProgress', 'on');
0 个评论
采纳的回答
Rahul Kumar
2018-10-31
Hi Simon,
Variant_1, Variant_2, and Variant_Switch, along with any other variables used by the model and defined in the base workspace need to be available to the parallel workers. There are two ways of achieving this
1. Use 'TransferBaseWorkspaceVariables' option with parsim
out = parsim(in, 'TransferBaseWorkspaceVariables', 'on')
The above option will copy all variables in the base workspace over to the base workspace of the parallel workers. The reason that this is not automatically handled by parsim is that in most cases, the model is already configured to load the required variables either using a model callback or via data dictionary so this additional step of transferring variables is usually not required.
2. Define the variables used in the model in a data dictionary . This allows parsim to automatically load the data dictionary on the parallel workers so that the variables are available.
I would suggest the first option if you are just tying out parsim with example models but consider using option 2 for production work.
-- Rahul
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Component-Based Modeling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!