Main Content

Saving and Restoring Simulation Operating Point

此示例显示了使用ModeloperatingPoint对象保存和恢复模拟操作点的工作流程和好处。

The ModelOperatingPoint object contains the complete snapshot of all variables that are related to the simulation of a model. After saving the ModelOperatingPoint object at the end of a simulation, Simulink® can reload the operating point and continue the simulation from the time at which the ModelOperatingPoint object was saved. This action produces the same simulation results as if the simulation were never interrupted.

This example illustrates:

  • How saving the Final states (logged states) is not always sufficient for complete and accurate restoration of a simulation state.

  • How you can save and restore the complete operating point of a simulation, yielding faster simulation workflows

具有可变运输延迟的型号的困难

在模拟过程中记录的状态是完全描述模拟状态所需的所有信息的子集。某些块依赖于未记录的内部信息作为州记录和最终状态导出的一部分。一个这样的块就是传输延迟块。具有传输延迟块的模型通常很难完全恢复到特定状态,因为作为“最终状态”数据记录的一部分,运输延迟的状态并未以结构格式或阵列格式保存。

为了说明此问题,请比较两种情况的仿真结果:

1.模拟一个模型,该模型包含一个从0到5秒的传输延迟块,并将“最终状态”值保存在工作区中。然后加载第一组最终状态,并从5到10秒模拟。

2.模拟同一模型从0到10秒,并迫使模型在5秒钟内产生输出。我们称此模拟的结果为基线结果,因为它是一个不间断的仿真。

The results of the first simulation match the first half of the baseline result. If the simulation state of the first simulation had been restored completely, the second simulation results would match the second half of the baseline.

首先,加载此模型:

mdl =“ Slexvariabletransportdelay”;LOAD_SYSTEM(MDL);

模拟直到5个时间,并以结构格式保存最终状态:

out = sim(mdl,“停止时间”,,,,'5',,,,“ SavefinalState”,,,,'上',,,,...'FinalStateName',,,,'xfinal',,,,“ saveformat',,,,'结构');y1 = out.scopedata;

加载最后一个模拟的最终状态,并运行10:

分配('base',,,,'xfinal',out。'xfinal');out1 = sim(mdl,'开始时间',,,,'5',,,,“停止时间”,,,,'10',,,,...“ SavefinalState”,,,,'off',,,,...“LoadInitialState',,,,'上',,,,“初始状态”,,,,'xfinal');Y2= out1.ScopeData;

运行不间断的模拟,该模拟将作为基线结果:

out2 = sim(mdl,“输出措施”,,,,'AdditionalOutputTimes',,,,...“输出时间”,,,,'[0 5 10]',,,,“LoadInitialState',,,,'off');y = out2.scopedata;

Plot the results. Note that the second half of the baseline result does not match the simulation from 5 to 10 seconds, whose initial state was restored from the final state saved at 5 seconds:

数字;为了IDX = 1:3子图(3,1,IDX);绘图(y.time,y.signals(idx).values);抓住on;plot([y1.time; y2.time],...[y1.signals(idx).values; y2.signals(idx).values],'r-');抓住off;网格on;结尾

保存和恢复模拟的完整操作点

您可以在simulink.op.modeloperatingpoint对象中保存完整的最终操作点。金宝appModelOperatingPoint对象包含恢复仿真结果所需的所有变量。通过使用完整的ModelOperatingPoint,Simulink能够完全恢复模拟金宝app状态并重现基线仿真结果。

Set the parameter for Simulink to save the complete operating point at the end of the simulation.

out3 = sim(mdl,“停止时间”,,,,'5',,,,“ SavefinalState”,,,,'上',,,,...“LoadInitialState',,,,'off',,,,“ SaveOperatingPoint”,,,,'上',,,,...'FinalStateName',,,,'xfinal');y1 = out3.scopedata;

从上次模拟中加载模型操作点,然后再运行5秒。启动时间值必须保持0.0(该值是原始模拟的开始时间)。该软件将原始仿真启动时间存储在xfinal中。该值必须匹配当前仿真的开始时间,以恢复模拟状态。

分配('base',,,,'xfinal',out3.get('xfinal');out4 = sim(mdl,“停止时间”,,,,'10',,,,“ SavefinalState”,,,,'off',,,,...“LoadInitialState',,,,'上',,,,“初始状态”,,,,'xfinal');Y2= out4.ScopeData;

绘制结果并将其与基线模拟进行比较。请注意,这次,仿真状态已完全恢复,并且在操作点还原后的仿真结果与基线匹配。

数字;为了IDX = 1:3子图(3,1,IDX);绘图(y.time,y.signals(idx).values);抓住onplot([y1.time; y2.time],...[y1.signals(idx).values; y2.signals(idx).values],'r-');抓住off;网格on;结尾

关闭模型并清除此示例中使用的变量

CLOSS_SYSTEM(MDL,0);清除mdlIDXxfinalyY1Y2Y3outOUT1OUT2OUT3OUT4