文档

使用PARSIM的平行模拟:测试案例扫描

This example shows how you can run multiple Simulink® simulations corresponding to different test cases in the Signal Editor block using SimulationInput objects and theParsim命令。PARSIM命令使用并行计算工具箱™并行运行模拟,否则模拟以串行运行。

Model Overview

该模型sldemo_suspn_3dof下面显示的基于道路的模拟车辆动力学 - 用于不同道路轮廓的悬架相互作用。车辆动力学以三个自由度捕获:垂直位移,滚动和音高。左右轮胎的道路轮廓数据被导入信号编辑器块中,作为不同的测试用例。道路悬浮互动子系统根据道路数据和当前车辆状态在四个轮胎位置计算车辆上的悬架力。在身体动力学子系统中,这些力以及所得的螺距和滚动矩用于以三个自由度确定车辆运动:垂直位移,滚动和音高。

使用不同的道路配置文件模拟悬架模型,以确定设计是否符合所需的性能目标。并行计算工具箱用于加快这些多个模拟,如下所示。

mdl ='sldemo_suspn_3dof'; isModelOpen = bdIsLoaded(mdl); open_system(mdl);

Set up Data Required for Multiple Simulations

使用信号编辑器块的numberOfScenarios参数确定信号编辑器块中的案例数。案例数用于确定步骤3中运行的迭代次数。

sigeditblk = [mdl'/Road Profiles']; numCases = str2double(get_param(sigEditBlk,'NumberOfScenarios');

创建一个阵列金宝appSimulink.SimulationInputobjects to define the set of simulations to run. Each SimulationInput object corresponds to one simulation and will be stored as an array in a variable,。蒙版参数,Activescenario,指定信号编辑器块方案的扫描值。为每个仿真设置活动场景。

为了idx = numCases:-1:1 in(idx) = Simulink.SimulationInput(mdl); in(idx) = setBlockParameter(in(idx), sigEditBlk,'ActiveScenario',,,,idx);结尾

Note that specifying the model parameter on the SimulationInput object does not apply it to the model immediately. The specified value will be applied during the simulation and reverted back to its original value, if possible, after the simulation finishes.

并行运行模拟

使用Parsim函数以并行执行模拟。模拟对象的数组,,,,,created in the last step is passed into theParsim功能是第一个参数。来自Parsimcommand is an array of金宝appsimulink.simulationOutput存储在变量中的对象出去。Set the 'ShowProgress' option to 'on' to print a progress of the simulations on the MATLAB command window.

out = parsim(在“表演”,,,,'上');
[28-Feb-2018 12:26:20] Checking for availability of parallel pool... Starting parallel pool (parpool) using the 'local' profile ... connected to 6 workers. [28-Feb-2018 12:27:04] Loading Simulink on parallel workers... [28-Feb-2018 12:27:04] Configuring simulation cache folder on parallel workers... [28-Feb-2018 12:27:04] Loading model on parallel workers... [28-Feb-2018 12:27:08] Running simulations... [28-Feb-2018 12:27:18] Completed 1 of 20 simulation runs [28-Feb-2018 12:27:18] Completed 2 of 20 simulation runs [28-Feb-2018 12:27:18] Completed 3 of 20 simulation runs [28-Feb-2018 12:27:18] Completed 4 of 20 simulation runs [28-Feb-2018 12:27:18] Completed 5 of 20 simulation runs [28-Feb-2018 12:27:18] Completed 6 of 20 simulation runs [28-Feb-2018 12:27:22] Completed 7 of 20 simulation runs [28-Feb-2018 12:27:22] Completed 8 of 20 simulation runs [28-Feb-2018 12:27:22] Completed 9 of 20 simulation runs [28-Feb-2018 12:27:22] Completed 10 of 20 simulation runs [28-Feb-2018 12:27:22] Completed 11 of 20 simulation runs [28-Feb-2018 12:27:23] Completed 12 of 20 simulation runs [28-Feb-2018 12:27:26] Completed 13 of 20 simulation runs [28-Feb-2018 12:27:26] Completed 14 of 20 simulation runs [28-Feb-2018 12:27:26] Completed 15 of 20 simulation runs [28-Feb-2018 12:27:26] Completed 16 of 20 simulation runs [28-Feb-2018 12:27:26] Completed 17 of 20 simulation runs [28-Feb-2018 12:27:26] Completed 18 of 20 simulation runs [28-Feb-2018 12:27:29] Completed 19 of 20 simulation runs [28-Feb-2018 12:27:29] Completed 20 of 20 simulation runs [28-Feb-2018 12:27:29] Cleaning up parallel workers...

每个仿真图对象都包含已记录的信号以及仿真metadata。在运行多个模拟时使用Parsim,捕获错误,以便随后的模拟可以继续运行。任何错误都会在ErrorMessage模拟图对象的属性。

情节结果

Plot the vertical vehicle displacement from the different simulations to see how the vehicle performed to the different road profiles. The signal is logged in the SimulationOutput object in the Dataset format. Use the得到从每个元素中获取包含时间和信号数据的时间表对象的方法出去

legend_labels =单元格(1,数字);为了i = 1:数字simout = out(i);ts = simout.logsout.get('Vertical_disp')。ts.plot;legend_labels {i} = ['跑 'num2str(i)];抓住all结尾标题(“ 3-DOF悬架模型的响应”) xlabel('Time (s)');ylabel(“车辆垂直位移(M)”);legend(legend_labels,'Location',,,,“东北”);

关闭MATLAB工人

最后,如果以前没有打开,请关闭平行池和模型。

如果(~ isModelOpen) close_system (mdl 0);结尾删除(GCP(GCP)('nocreate');
Parallel pool using the 'local' profile is shutting down.