以并行或串行方式进行多次动态系统仿真 -凯发官方首页
以并行或串行方式进行多次动态系统仿真
说明
使用 simout
= parsim(in
)simulationinput
对象 in 中指定的输入对模型进行仿真。parsim
命令使用 simulationinput
对象数组作为输入来运行多个仿真。
使用 simout
= parsim(in
,'showsimulationmanager'
,'on'
)simulationinput
对象中指定的输入对模型进行并行仿真,并打开仿真管理器 ui。有关详细信息,请参阅 simulation manager
。
使用 simout
= parsim(in
,name,value
)simulationinput
对象中指定的输入和指定为 name,value
对组的选项对模型进行并行仿真。
parsim
命令使用 parallel computing toolbox™ 许可证以并行方式运行仿真。如果无法创建并行池,或者未使用 parallel computing toolbox,则 parsim
以串行方式运行仿真。
示例
在快速加速模式下使用 parsim
在快速加速模式下仿真模型 vdp
。
加载模型。
model = 'vdp';
load_system(model)
此步骤构建快速加速目标
simulink.blockdiagram.buildrapidacceleratortarget(model);
创建 simulationinput
对象并使用 setmodelparameter
方法将 rapidacceleratoruptodatecheck
设置为 'off'
。
in = simulink.simulationinput(model); in = in.setmodelparameter('simulationmode', 'rapid-accelerator'); in = in.setmodelparameter('rapidacceleratoruptodatecheck', 'off');
对模型进行仿真。
out = parsim(in)
使用 parsim 以并行方式仿真模型
通过扫描变量以并行方式仿真模型 cstr。执行扫描时,使用了 simulationinput 对象的数组。
指定扫描值。
feedtempsweep = 250:10:300;
创建 simulationinput 对象的数组。
for i = length(feedtempsweep):-1:1 in(i) = simulink.simulationinput('cstr'); in(i) = in(i).setvariable('feedtemp0',feedtempsweep(i)); end
以并行方式仿真模型。
out = parsim(in, 'showsimulationmanager', 'on')
[29-jun-2022 15:05:52] checking for availability of parallel pool... starting parallel pool (parpool) using the 'processes' profile ... connected to the parallel pool (number of workers: 6). [29-jun-2022 15:07:01] starting simulink on parallel workers... [29-jun-2022 15:07:34] configuring simulation cache folder on parallel workers... [29-jun-2022 15:07:35] loading model on parallel workers... [29-jun-2022 15:07:49] running simulations... [29-jun-2022 15:08:24] completed 1 of 6 simulation runs [29-jun-2022 15:08:24] completed 2 of 6 simulation runs [29-jun-2022 15:08:24] completed 3 of 6 simulation runs [29-jun-2022 15:08:27] completed 4 of 6 simulation runs [29-jun-2022 15:08:28] completed 5 of 6 simulation runs [29-jun-2022 15:08:28] completed 6 of 6 simulation runs [29-jun-2022 15:08:28] cleaning up parallel workers... out = 1x6 simulink.simulationoutput array
输入参数
in
— 用于对模型进行仿真的 simulink.simulationinput
对象
对象、数组
用于在仿真中指定对模型所作更改的 simulink.simulationinput
对象或 simulink.simulationinput
对象的数组。
示例: in = simulink.simulationinput('vdp')
示例: for i = 10:-1:1 in(i) = simulink.simulationinput('vdp'); end
名称-值参数
示例: 'showprogress'
, 'on'
注意
传递给 parsim
命令的所有参数与 sim
命令使用的参数无关。向 parsim
命令传递下列输入参数列表。
指定可选的、以逗号分隔的 name,value
对组参数。name
为参数名称,value
为对应的值。name
和 value
必须显示在单引号 (' '
) 内。您可采用任意顺序指定多个名称-值对组参数,如 name1,value1,...,namen,valuen
。
attachedfiles
— 要附加到并行池的文件
元胞数组
附加到并行池的附加文件,指定为元胞数组。parsim
不支持从引用子目录中 mat 文件的 from file 模块中加载数据。
showprogress
— 显示仿真的进度
'on'(默认值) | 'off'
设置为 'on'
,以在命令行窗口中查看仿真的进度。当设置为 'off'
时,进度将隐藏。
注意
当显示进度时,可能会在最后几次仿真完成之前显示 'cleaning up parallel workers..'
消息。此消息出现与否并不取决于仿真是否完成。只有当仿真从 future
获取到输出结果时,仿真才真正完成。有关详细信息,请参阅 。
runinbackground
— 在后台运行仿真
'off' (默认) | 'on'
设置为 'on'
将以异步方式运行仿真,从而保持 matlab® 命令提示符可用。要终止在后台运行的仿真,请对 simulink.simulation.future
对象使用 方法。
setupfcn
— 对每个工作进程运行一次的函数句柄
函数句柄
在开始仿真之前,将 function handle
指定为 'setupfcn'
以对每个工作进程运行一次。
示例: 'setupfcn',@()currentproject('modelex/model_example.prj')
注意
当在 setupfcn 中使用 buildrapidacceleratortarget
并且对模型指定了外部输入时,请将 'loadexternalinput'
设置为 'off'
或确保指定的外部输入在工作进程上可用,以防出现编译错误。
cleanupfcn
— 运行仿真后对每个工作进程运行一次的函数句柄
函数句柄
将 function handle
指定为 'cleanupfcn'
以在仿真完成后对每个工作进程运行一次。
managedependencies
— 管理模型依存关系
'on' (默认) | 'off'
当 managedependencies
设置为 on
时,会在需要时自动向并行工作进程发送模型依存关系。如果将 managedependencies
设置为 off
,则将模型依存关系显式附加到并行池。
usefastrestart
— 使用快速重启
'off' (默认) | 'on'
当 usefastrestart
设置为 on
时,仿真使用快速重启在工作进程上运行。
对 simscape™ 组件的可变属性(例如,simscape multibody 的 solid 模块的质量和惯量)执行参数扫描时,要将 simscape 模块参数指定为可在运行时进行配置。有关详细信息,请参阅 (simscape)。
注意
使用 parsim
时,请使用 usefastrestart
选项,而不使用 fastrestart
选项。有关详细信息,请参阅。
快速重启模式下的 parsim
不支持具有 tofile 模块的模型。
transferbaseworkspacevariables
— 将变量传递给并行工作进程
'off' (默认) | 'on'
当 transferbaseworkspacevariables
设置为 on
时,在模型中使用的变量和在基础工作区中定义的所有内容将传输给并行工作进程。
showsimulationmanager
— 启动仿真管理器
'off' (默认) | 'on'
当 'showsimulationmanager'
设置为 'on'
时,可以使用仿真管理器来监视仿真。
stoponerror
— 在出现错误时停止仿真
'off' (默认) | 'on'
如果将 'stoponerror'
设置为 'on'
,则在遇到错误时将停止执行仿真。
输出参数
simout
— 包含记录的仿真结果的仿真对象
对象
包含所有记录的仿真结果的 simulink.simulationoutput
对象的数组。数组的大小等于 simulink.simulationinput
对象的数组的大小。
在单个 simulink.simulationoutput
对象中返回所有仿真输出(记录的时间、状态和信号)。您使用模型配置参数对话框的“数据导入/导出”窗格来定义所记录的模型时间、状态和输出。您可以使用 to workspace 和 scope 等模块记录信号。信号和波形管理器可以直接记录信号。
扩展功能
自动并行支持
通过使用 parallel computing toolbox™ 自动运行并行计算来加快代码执行。
如果安装了 parallel computing toolbox,则在您使用 parsim
时,matlab 会自动在本地计算机上打开工作进程的并行池。matlab 在可用的工作进程上运行仿真。使用并行预设项控制并行行为,包括扩展到集群。
有关详细信息,请参阅running multiple simulations。
版本历史记录
在 r2017a 中推出
另请参阅
| | | | | | | | | | | simulation
manager
| | | |
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.