在simuli金宝appnk上的家伙

金宝app基于Simulink和模型的设计

THE Most Useful Command for Debugging Variable Step Solver Performance

Today I want to share a trick I often use to determine if a variable step simulation runs as fast as it should.

可视化模型所采取的步骤

首先,保存模拟时间数据。这可以从中完成数据导入/出口窗格of the model configuration.

记录仿真时间数据

仿真完成后,绘制时间数据的导数。这可以通过以下行进行:

semilogy(tout(1:end-1),diff(tout))

我喜欢为y轴使用对数刻度,因为所花费的时间步骤可以在非常大的范围内变化。

Now let's look at a few examples showing what kind of information we can extract from this figure.

超出公差

When applying this technique to the example demovdp.mdl, we obtain the following figure:

semilogy(tout(1:end-1),diff(tout)) for demo vdp.mdl

Using this figure, we can identify 2 main things.

首先,我们可以看到大部分时间,求解器采取的步骤对应于max step sizespecified in the model configuration. This means that you might be able to increase solver max step size and allow the solver to take larger steps, reducing the total number of steps needed to finish the simulation.

其次,我们看到在某些时刻,时间步骤顺利减少。这意味着求解器可以尽可能大的步骤尊重指定的步骤宽容

要确认上面,让我们更改Solver Max Sime Size,并查看它如何影响步骤尺寸:

semilogy(tout(1:end-1),diff(tout)) for demo vdp.mdl

In this example, the effect is pretty small. But we can see that if we increase the max step size, the simulation takes larger steps.

请注意,I recommend being cautious when increasing the solver max step size or tolerances. Take the time to do a convergence study to ensure the results still provide the accuracy you need.

Zero-Crossing

Another important pattern that can be identified using this technique is the effect of zero-crossings on the simulation.

Let's take this simple model, made of a sine wave connected to a saturation block.

生成零交叉事件的示例模型

在该示例中,每次进入或退出饱和时,饱和度块会产生零交叉事件。正如我们所看到的,这会强制Simulink求解器采取非常小的步金宝app骤来准确捕获此事件。

Effect of zero-crossing on time steps

The zero-crossing mechanism provides accuracy by taking small steps. Knowing that is the behavior of the solver, it is up to you to judge if a block needs zero-crossing or not.

结论

If your model runs slower than you expect, this technique can help you determine if it is because it takes smaller steps than it needs to.

In my debugging toolbox, this is one of the first things I try when I am investigating the performance of a simulation.

现在轮到你了

Do you have any tricks to share to help determinining if a variable-step simulation runs as fast as it can? Please share it by leaving acomment here

|

评论

要发表评论,请点击此处