How can I use parsim in combination with a Simulink Variant Subsystem

12 次查看(过去 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.
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');

采纳的回答

Rahul Kumar
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
  1 个评论
Simon Haslbeck
Simon Haslbeck 2018-11-5
Thank you for your help, solution 1 does work. For solution 2 I first have to check if a data dictionary is integrateable without bigger complications.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Component-Based Modeling 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by