主要内容

Parallel Simulations Using Parsim: Test-Case Sweep

此示例显示如何使用SimumingInpput对象以及使用SimumingIncut对象金宝app运行与信号编辑器块中的不同测试用例相对应的多个Simulink®模拟parsimcommand. The parsim command uses Parallel Computing Toolbox™, if it is available, to run simulations in parallel, otherwise the simulations are run in serial.

模型概述

The modelsldemo_suspn_3dofshown below simulates the vehicle dynamics based on the road - suspension interaction for different road profiles. The vehicle dynamics are captured in three degrees of freedom: vertical displacement, roll, and pitch. The road profile data for the left and right tires is imported into the Signal Editor block as different test cases. The Road-Suspension Interaction subsystem calculates the suspension forces on the vehicle at the four tire locations based on the road data and the current vehicle state. In the Body Dynamics subsystem these forces and the resulting pitch and roll moments are used to determine the vehicle motion in three degrees of freedom: vertical displacement, roll, and pitch.

The suspension model is simulated using different road profiles to determine if the design meets desired performance goals. Parallel Computing Toolbox is used to speed up these multiple simulations, as illustrated below.

mdl ='sldemo_suspn_3dof';ismodelopen = bdisloaded(mdl);Open_System(MDL);

设置多种模拟所需的数据

Determine the number of cases in the Signal Editor block using the NumberOfScenarios parameter of the Signal Editor block. The number of cases is used to determine the number of iterations to run in step 3.

sigEditBlk = [mdl'/道路配置文件'];numcases = str2double(get_param(sigeditblk,'numberofscenarios'));

Create an array ofSimulink.SimulationInput要定义要运行的模拟集的对象。每个仿真线对象对应于一个模拟,并且将被存储为变量中的数组,in。The mask parameter,ActiveScenario, specifies the sweep value for the Signal Editor block scenario. The active scenario is set for each simulation.

foridx = numcase:-1:1(idx)= simul金宝appink.simulationInput(MDL);在(idx)= setBlockParameter(在(idx),sigeditblk中,'ActiveScenario',IDX);end

请注意,在SimulationInPut对象上指定模型参数不会立即将其应用于模型。在模拟过程中,将在模拟期间应用指定的值,并在模拟结束后恢复到原始值。

Run Simulations in Parallel Using Parsim

使用parsimfunction to execute the simulations in parallel. The array of SimulationInput objects,in,在最后一步中创建的被传递到parsimfunction as the first argument. The output from theparsim命令是一系列Simulink.SimulationOutputobjects which is stored in the variableout。将“showprogress”选项设置为“开”以打印Matlab命令窗口上的模拟的进度。

out = parsim(in,'ShowProgress','on');
[21-FEB-2021 01:43:41]检查并行池的可用性...使用“本地”配置文件...启动并行池(Parpool)...连接到并行池(工人数量:6)。[21-FEB-2021 01:44:30]在并行工人上启动Si金宝appmulink [21-Feb-2021 01:45:05]配置并行工人的模拟缓存文件夹... [21-FEB-2021 01:45:07]在平行工人上加载模型... [21-FEB-2021 01:45:13]运行模拟...... [21-FEB-2021 01:45:26]完成了20个模拟运行中的1个[21-2月2021年01:45:26]完成了20个模拟运行中的2个[21-FeB-2021 01:45:26]完成了20个模拟运行中的3种[21-FeB-2021 01:45:26]完成了20个模拟跑步[21-FEB-2021 01:45:26]完成了5个模拟运行中的5个(21-FeB-2021 01:45:26]完成了20个模拟运行中的6个[21-Feb-2021 01:45:28]完成20个仿真运行中的7个(共20个模拟)[21:45:29]完成了20个模拟运行中的8个[21-FeB-2021 01:45:29]完成了20个模拟运行中的9个[21-Feb-2021 01:45:29]完成了20个模拟运行中的10个[21-FeB-2021 01:45:29]完成了20个模拟运行中的11个[21-FeB-2021 01:45:29]完成了20个模拟运行中的12个[21-FeB-2021 01:45:31]完成了20个模拟运行中的13个[21-feb-2021 01:45:31]完成了20个模拟运行中的14个[21-FeB-2021 01:45:31]完成了20个模拟运行中的15个[21-Feb-2021 01:45:31],其中16分(共用)仿真运行[21-FEB-2021 01:45:31]完成了20个模拟运行中的17个[21-FEB-2021 01:45:31]完成了20个模拟运行中的18个[21-Feb-2021 01:45:34]完成了19个的20个模拟运行[21-FeB-2021 01:45:34]完成了20个模拟运行中的20个[21-Feb-2021 01:45:34]清理平行工人......

Each SimulationOutput object contains the logged signal along with the模拟Metadata。When running multiple simulations usingparsim, errors are captured so that subsequent simulations can continue to run. Any errors would show up in the错误信息property of the SimulationOutput object.

Plot Results

从不同的模拟中绘制垂直车辆位移,看看车辆如何执行到不同的道路轮廓。信号在数据集格式中记录在SimulationOutput对象中。使用getmethod to obtain the timeseries object containing the time and signal data from each element ofout

legend_labels = cell(1,numCases);fori = 1:numCases simOut = out(i); ts = simOut.logsout.get('vertical_disp').Values; ts.plot; legend_labels{i} = ['Run 'num2str(i)]; hold全部endtitle('Response of a 3-DoF Suspension Model')Xlabel('时间(s)');ylabel('Vehicle vertical displacement (m)');传奇(Legend_Labels,'地点','NorthEastOutside');

Close MATLAB Workers

Last, close the parallel pool and the model if they were not previously opened.

if(〜是iSmodElopen)Close_System(MDL,0);enddelete(gcp('nocreate'));

See Also

||

相关话题