主要内容

Determine Step Size

第一步Real-Time Model Preparation Workflow,您可以从Simscape™模型的参考版本的可变步骤仿真获取结果。参考结果提供了一种基线,您可以根据修改后评估模型的准确性。此示例显示了如何分析参考结果和变量步骤求解器所花款的步长:

  • Estimate the maximum step size that you can use for a fixed-step simulation

  • Identify events that have the potential to limit the maximum step size

不连续性和快速变化需要准确地捕获这些动态的小型尺寸。您可以使用的最大步长必须足够小以确保准确的结果。如果您的模型包含这样的动态,那么可以准确的效果所需的步长,Ts最大限度, is too small. A step size that is too small does not allow your real-time computer to finish calculating the solution for any given step in the simulation.

的analysis in this example helps you to estimate the maximum step size that fixed-step solvers can use and still obtain accurate results. You can also use the analysis to determine which elements influence the maximum step size for accurate results. For more information on how obtaining reference results and performing a step-size analysis helps you to prepare your model for real-time simulation, see模型准备目标.

  1. 打开参考模型,在matlab®命令提示符,输入:

    model ='ssc_pneumatic_rts_reference';Open_System(型号)

  2. Simulate the model:

    SIM(型号)
  3. Create a semilogarithmic plot that shows how the step size for the solver varies during the simulation.

    h1 = figure; semilogy(tout(1:end-1),diff(tout),“- x”) 标题('Solver Step Size')Xlabel('时间(s)')ylabel('梯级'')

    For much of the simulation, the step size is greater than the value of theTs最大限度在情节中。相应的值〜0.001秒是估计的最大步长,用于在使用模型的固定步骤仿真期间实现精确的结果。要了解如何配置固定步骤求解器的步长,以便进行实时仿真,请参阅选择步骤尺寸和迭代次数.

    xmarkers in the plot indicate the time that the solver took to execute a single step at that moment in the simulation. The step-size data is discrete. The line that connects the discrete points exists only to help you see the order of the individual execution times over the course of the simulation.

    步长减小表示求解器检测到过零事件。当信号的值改变符号或交叉阈值时,可能会发生零交叉检测。模拟减少了步长,以准确地捕获零交叉事件的动态。在求解器处理零交叉事件的动态之后,模拟步长可以增加。求解器可以在返回到零交叉事件之前的步长之前采取几个小步骤。红色框中的区域包含可变步长求解器的恢复时间的变体。

  4. To see different post-zero-crossing behaviors, zoom to the region in the red box at time (t)=〜1秒。

    Script for Zooming In

    Aftert= 1.005秒,步长从〜10e-3秒减小到小于10e-13秒以捕获事件。阶梯尺寸快速增加至约10E-5秒,然后缓慢到达〜10e-4秒。步长减小以捕获第二个事件并快速恢复,然后从第一次事件之前缓慢恢复到步长。恢复速度的速度表明,模拟使用的小步骤捕获模型中元素的动态。如果所需的步骤大小将最大固定步长度限制为足够小的值,则在尝试在实时计算机上尝试仿真时可能会发生溢出。

    需要小步长大小的元素类型是:

    • Elements that cause discontinuities, such as hard-stops and stick-slip friction

    • Elements that have small time constants, such as small masses with undamped, stiff springs and hydraulic circuits with small, compressible volumes

    的step size recovers more quickly after it slows down to process the event that occurs beforet= 1.02秒。此事件不太可能需要小型步骤尺寸来实现准确的结果。

  5. To see different types of slow solver recoveries, zoom to the region within the red box att=〜4.2秒。

    H1;xzoomstart2 = 4.16;xzoomend2 = 4.24;yzoomstart2 = 10e-20;yzoomend2 = 10e-1;轴([xzoomstart2 xzoomend2 yzoomstart2 yzoomend2]);

    Just as there are different types of events that cause solvers to slow down, there are different types of slow solver recovery. The events that occur just beforet= 4.19 and 4.2 seconds both involve zero-crossings. The solver takes a series of progressively larger steps as it reaches the step size from before the event. The large number of very small steps that follow the zero crossing at Slow Recovery A indicate that the element that caused the zero crossing is also numerically stiff.

    的quicker step-size increase after the event that occurs att= 4.2 seconds indicates that the element that caused the zero crossing before Slow Recovery B, is not as stiff as the event at Slow Recovery A.

  6. To see the results, open the Simscape Results Explorer.

    sscexplore(simlog)

  7. 检查角速度。在Simscape Refourfer Explorer窗口中,在模拟日志树层次结构中,选择Measurements>Ideal Rotational Motion Sensor>w.

  8. To add a plot of the gas flow, selectMeasure Flow>Pneumatic Mass & Heat Flow Sensor和then, use Ctrl+click to selectG_ps.

    仿真初始化时发生缓慢的恢复时间,并且大约发生在t= 1, 4, 5, 8, and 9 seconds. These periods of small steps coincide with these times:

    • 电机速度接近零RPM(模拟时间t= ~ 1, 5, and 9 seconds)

    • 电机速度的步长从稳态速度开始到新速度(时间t= ~ 4 and 8 seconds)

    • 流速的步骤改变从稳态速度开始到新的流量(时间t= ~ 4 and 8 seconds)

    • 体积流速接近零kg / s(T.=〜1,4和5秒)

    这些结果表明,慢性阶梯尺寸的回收最有可能是由于模型中的元素涉及摩擦或具有较小的可压缩体积的元素。看如何识别有问题的元素并修改它们以提高模拟速度,请参阅减少数值刚度减少过零点.

See Also

Related Examples

More About