Main Content

使用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

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

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

创建一个数组金宝appsimulink.simulationInput.objects 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并行运行模拟

使用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.

出局= Parsim(在,'showprogress''在');
[21-Feb-2021 01:43:41] Checking for availability of parallel pool... Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 6). [21-Feb-2021 01:44:30] Starting Simulink on parallel workers... [21-Feb-2021 01:45:05] Configuring simulation cache folder on parallel workers... [21-Feb-2021 01:45:07] Loading model on parallel workers... [21-Feb-2021 01:45:13] Running simulations... [21-Feb-2021 01:45:26] Completed 1 of 20 simulation runs [21-Feb-2021 01:45:26] Completed 2 of 20 simulation runs [21-Feb-2021 01:45:26] Completed 3 of 20 simulation runs [21-Feb-2021 01:45:26] Completed 4 of 20 simulation runs [21-Feb-2021 01:45:26] Completed 5 of 20 simulation runs [21-Feb-2021 01:45:26] Completed 6 of 20 simulation runs [21-Feb-2021 01:45:28] Completed 7 of 20 simulation runs [21-Feb-2021 01:45:29] Completed 8 of 20 simulation runs [21-Feb-2021 01:45:29] Completed 9 of 20 simulation runs [21-Feb-2021 01:45:29] Completed 10 of 20 simulation runs [21-Feb-2021 01:45:29] Completed 11 of 20 simulation runs [21-Feb-2021 01:45:29] Completed 12 of 20 simulation runs [21-Feb-2021 01:45:31] Completed 13 of 20 simulation runs [21-Feb-2021 01:45:31] Completed 14 of 20 simulation runs [21-Feb-2021 01:45:31] Completed 15 of 20 simulation runs [21-Feb-2021 01:45:31] Completed 16 of 20 simulation runs [21-Feb-2021 01:45:31] Completed 17 of 20 simulation runs [21-Feb-2021 01:45:31] Completed 18 of 20 simulation runs [21-Feb-2021 01:45:34] Completed 19 of 20 simulation runs [21-Feb-2021 01:45:34] Completed 20 of 20 simulation runs [21-Feb-2021 01:45:34] Cleaning up parallel workers...

每个SimulationOutput对象都包含记录信号以及模拟metaData.。使用多次模拟时Parsim,捕获错误,以便后续模拟可以继续运行。任何错误都会出现在ErrorMessageSimulationOutput对象的属性。

绘图结果

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得到获取包含来自每个元素的时间和信号数据的时代对象的方法出去

letcend_labels = cell(1,numcase);为了i = 1:numcases simout = out(i);ts = simout.logsout.get('垂直_disp').Values;ts.plot;Legend_Labels {i} = ['跑 'num2str(i)];抓住all结尾标题('3-DOF暂停模型的响应') xlabel('Time (s)');ylabel('车辆垂直位移(m)');legend(legend_labels,'Location''东北斗');

关闭Matlab Workers.

最后,关闭并行池和模型,如果它们先前未打开。

如果(~ isModelOpen)克洛se_system(mdl, 0);结尾删除(GCP('noicreate'));

也可以看看

||

Related Topics