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

6 views (last 30 days)
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');

Accepted Answer

Rahul Kumar
Rahul Kumar on 31 Oct 2018
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 Comment
Simon Haslbeck
Simon Haslbeck on 5 Nov 2018
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Component-Based Modeling in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!