Main Content

Run Simulations on a Remote Cloud Computing Cluster

This example shows you how to create a simulink.multisim.DesignStudy object for running multiple simulations with a parameter sweep, and then run the simulations on a remote cloud computing cluster using MATLAB® as a client. This example uses the road suspension model and performs a parameter sweep. The model simulates the vehicle dynamics based on the road-suspension interaction for different road profiles imported into the Signal Editor block. The model is simulated using different values of stiffness of the suspension to determine if the design meets desired performance goals. This example performs a parameter sweep to find the combination of spring stiffness that leads to minimum vertical displacement.

Load the Model

Load the model ex_multisim_sldemo_suspn_3dof, supporting data, and the road profiles.

Note

To gain access to the model and the supporting files, use the command openExample('simulink_features/ParsimParamSwpInRapidAcceleratorModeExample'). The only files the example uses from the working folder are ex_multisim_sldemo_3dof.slx, sldemo_suspn_3dof_data.m, and sldemo_suspn_3dof_sgData.

mdl = 'sldemo_suspn_3dof';
sldemo_suspn_3dof_data;
load_system(mdl);
sigEditBlk = [mdl '/Road Profiles'];

Create a simulink.multisim.DesignStudy Object

To evaluate how the spring stiffness affects vertical displacement, create a parameter space. Use the simulink.multisim.DesignStudy object to tune the spring stiffness of the front and rear suspension Kf and Kr respectively.

Kr_sweep = simulink.multisim.Variable('Kr',linspace(Kr/2,Kr*2,5),'Workspace','global-workspace');
Kf_sweep = simulink.multisim.Variable('Kf',linspace(Kf/2,Kf*2,5),'Workspace','global-workspace');
ex = simulink.multisim.Exhaustive([Kr_sweep,Kf_sweep]);
ds = simulink.multisim.DesignStudy(mdl,ex);

Connect to a Cloud Cluster

To run the simulations on a remote computing cloud cluster, you require a cluster that is already setup. The URL is obtained from your cluster administrator. Use the simulink.cloud.addCluster function to register a remote cloud computing Kubernetes cluster that has Simulink® simulation platform services installed.

clusterURL = "yourcluster.example.com";
cluster = simulink.cloud.addCluster('myCluster',clusterURL);

Launch Simulations on Cloud Cluster

The uploadModelArtifact function uploads all the model artifacts that are required for the simulations to run on the remote cloud computing cluster. This step may take several minutes.

cluster.uploadModelArtifact(mdl)

To launch the simulations on the remote computing cloud cluster, use the batchsim function with the simulink.cloud.Cluster object and the simulink.multisim.DesignStudy object

job = batchsim(cluster,ds);
.

The code below allows you to print the progress of the simulations while the job runs on the cloud cluster.

progress = (job.NumCompletedSims/job.NumSims) * 100;
fprintf(1,"%s:\t%3.00f %%",job.ID, progress)
while ~strcmp(job.State,'Finished')
    pause(0.5);
    br = repmat('\b',1,3+1+1); % 3 for the numbers, one for the space, one for the % sign
    progress = (job.NumCompletedSims/job.NumSims) * 100;
    fprintf(1,[br,'%3.00f %%'],progress)
end
fprintf(1,'\n');

Fetch Outputs and Inputs of the Simulation

To access the outputs and the inputs, log into remote storage (s3). Use the fileDatastore to fetch and store the outputs from the simulink.cloud.Job object. The code below also retrieves and plots the input values of the simulation. For more information, see Work with Remote Data.

fds = fileDatastore(job.OutputLocation,ReadFcn=@load);
jobLocation = cluster.StorageLocation+job.ID;
inputLocation = join([jobLocation,"inputs"],"/");
input_fds = fileDatastore(inputLocation,ReadFcn=@load,FileExtensions={'.mat'});

max_disp = [];
in_Kr = [];
in_Kf = [];

figure
hold on
while hasdata(fds)
    out = fds.read;
    out = out.out;

    in = input_fds.read;
    in = in.simInp;
    vars = in.Variables;
    loc_in_Kr = vars(ismember([vars.Name],"Kr")).Value;
    loc_in_Kf = vars(ismember([vars.Name],"Kf")).Value;
    in_Kr(end+1) = loc_in_Kr;
    in_Kf(end+1) = loc_in_Kf;
    label = "Kr-"+loc_in_Kr+"-Kf-"+loc_in_Kf;
    v_disp = out.logsout{1};
    plot(v_disp.Values.Time,v_disp.Values.Data,'DisplayName',label)
    max_disp(end+1) = max(v_disp.Values.Data);
end
hold off

Plot the bubble chart to display the maximum recorded displacement for a combination of Kf and Kr. The bubble size in this bubble chart indicates the displacement figure.

figure
bubblechart(in_Kr,in_Kf,max_disp);
title(job.ID+": Maximum Displacement Against Front and Rear Spring Stiffness")
xlabel Kr
ylabel Kf
bubblesize([5,30])
bubblelegend('Max Displacement','Location','eastoutside')

See Also

| | | |

Related Topics