Use Model Operating Point for Faster Simulation Workflow
To effectively design a system, you simulate a model iteratively so you can analyze the system based on different inputs, boundary conditions, or operating conditions. In many applications, the systems you need to model and simulate exhibit a startup phase that involves significant dynamic behavior. For example, the takeoff stage of flight occurs before each aircraft maneuver in a set of simulations for a model of an airplane. When you run a set of simulations for such a system, you can reduce the amount of time required for the set of simulations by using model operating points.
Simulate the startup phase once.
Save the final operating point at the end of the startup phase.
Use the model operating point at the end of the startup phase as the initial state for each simulation.
The model operating point includes all information you need to resume a simulation, including block states, hidden block states, and the state of the solver and the execution engine. When you resume a simulation by using an operating point as the initial state, the simulation results match exactly the results of an equivalent simulation that runs from the start.
When you save final states without saving the operating point, only block states that are captured by state logging are saved. Block states alone might not be sufficient to resume the simulation. For more information, see Save Block States and Simulation Operating Points.
The flow chart summarizes the workflow for running a set of simulations from an initial operating point. In each simulation that starts from the initial operating point, you can modify parts of the model, such as tunable parameters, to simulate different scenarios without having to simulate the startup phase each time.
Save Model Operating Points
You can configure a model to save the final operating point using the Configuration Parameters dialog box.
The model operating point is always saved as a
Simulink.op.ModelOperatingPoint object. By default, simulation results are
returned as a single
Simulink.SimulationOutput object. The model
operating point is stored in a property of the
SimulationOutput object that
has the name you specify in the Final states box in the Configuration
Parameters dialog box or by using the
When you simulate a model that is configured to save the final operating point, the model operating point is saved and available in the workspace when:
The simulation completes.
A block, such as the Stop block, stops the simulation.
You stop the simulation by clicking Stop or by using the
set_paramfunction to issue the simulation command to stop.
You pause the simulation by clicking Pause or by using the
set_paramfunction to issue the simulation command to pause.
To save the model operating point at any time during simulation, pause the simulation,
then use the
get_param function to get the value of the
CurrentOperatingPoint parameter for the
op = get_param(mdl,"CurrentOperatingPoint");
You can save multiple operating points from a simulation so that you can continue the simulation from one of several operating points, depending on your requirements.
Restore Model Operating Points
To resume a simulation from a model operating point, specify the stop time for the
resumed simulation, enable initial state loading, and specify the
Simulink.op.ModelOperatingPoint object that represents the model
operating point as the initial state.
On the Simulation tab, in the Simulate section, in the Stop time field, enter a value that is larger than the value of the
snapshotTimeproperty of the
ModelOperatingPointobject that represents the model operating point.
On the Modeling tab, under Setup, click Model Settings.
In the Configuration Parameters dialog box, select the Data Import/Export pane.
In the Data Import/Export pane, select Initial state.
In the Initial state field, specify the name of the variable that contains the model operating point. For example, enter
xFinalif you used the default variable name to save the final operating point.
When you specify the initial state for a simulation as a model operating point, you do not change the start time for the simulation. The simulation from the initial operating point continues the simulation in which the operating point was created, so both simulations have the same start time. The start time also acts as a reference for all time and time-dependent variables. For example, the operating point information for a block might include the number of sample time hits that occurred for that block in simulation up to the point at which the operating point was saved.
For example, suppose you run a simulation of the startup phase for your model from 0 to 100 seconds and save the model operating point at 100 seconds. To run a simulation from 100 seconds to 200 seconds:
Specify the stop time for the model as 200 seconds.
Specify the initial state for the simulation as the model operating point you saved at 100 seconds.
Leave the start time for the model as 0 seconds.
When you run the simulation, the software restores the simulation time of 100 seconds as part of restoring the model operating point. Suppose the model operating point includes information that a block in the model had 10 sample time hits by the time the model operating point was saved. The software recognizes the first time step in the resumed simulation as the 11th sample time hit for the block, relative to 0, and not the first hit, relative to 100.
If you save the final operating point in the simulation that ran from 100 seconds to 200 seconds, you can continue the simulation again by using that operating point as the initial state for another simulation. For example, you could run another simulation from 200 seconds to 250 seconds by specifying the operating point saved at the end of the second simulation as the initial state for a third simulation.
When the start time for a simulation that starts from an initial operating point does not
match the value of the
startTime property of the
ModelOperatingPoint object, the software issues a warning and uses the
startTime property value as the start time for the simulation.
Additional Considerations for Saving and Restoring Model Operating Points
Changes that you make to your model between saving and restoring the model operating point can affect the validity of the operating point for the simulation or the simulation results.
When you make structural changes to the model, the operating point is no longer valid, and the software always issues an error.
When you make nonstructural changes, such as renaming the model or changing logging settings, the software issues a warning by default only if the changes you made affected the interface checksum.
Nonstructural changes to the model generally do not affect the ability to restore a model operating point but might affect the simulation results. To specify the diagnostic behavior when nonstructural changes affect the interface checksum, use the Operating point restore interface checksum mismatch parameter.
By default, the software issues an error if you try to simulate a model from an
operating point that was saved in a different release. You can configure the software to
issue a warning instead and restore the block states stored in the
loggedStates property of the
object, but the simulation results might not match the result of a simulation that runs from
the start time, without the initial operating point. For more information, see Operating point object from a different release.
Not all blocks, features, modeling patterns, and simulation modes support saving and restoring model operating points. In some cases, you can save and restore block states without the model operating point to avoid limitations for model operating points. For more information, see Save Block States and Simulation Operating Points.
|Feature or Modeling Pattern
|Considerations or Limitations
Saving and restoring model operating points is supported for normal, accelerator, and rapid accelerator simulations.
You cannot save an operating point from a simulation that runs in one simulation mode and restore that operating point in a simulation that runs in a different simulation mode.
Additional limitations apply for rapid accelerator simulations.
Rapid accelerator simulations
Saving and restoring a model operating point in rapid accelerator simulations has these limitations:
These blocks do not support saving and restoring the model operating point in rapid accelerator simulations:
Saving and restoring an operating point is not supported for model hierarchies that contain one or more referenced models configured to use a local solver. For more information, see Use Local Solvers in Referenced Models.
You cannot modify operating point information, such as block states, for blocks inside referenced models configured to simulate in accelerator mode.
These blocks do not support model operating point when they are inside a referenced model that is configured to simulate in accelerator mode:
MATLAB Function block
Saving and restoring the model operating point is generally supported for models that containMATLAB Function blocks. However, the use of certain constructs in the MATLAB® code can affect the support.
Saving and restoring the model operating point is not supported for models that contain MATLAB Function blocks with code that uses persistent variables with handle object data types or with values that contain one or more handle objects.
|Custom C code
|The operating point information might be incorrect for a block that calls custom C code that contains static variables or has side effects, such as writing to a file.
When you write an S-function, you can specify how the software saves and restores operating point information for the S-function by setting the operating point compliance.
The software saves S-Function block outputs as part of the operating point even if the S-function configures the operating point compliance to save no operating point information. Saving and restoring model operating points is not supported for S-functions that produce outputs with custom data types. For more information, see Configure Custom Data Types.
You cannot save or restore model operating points in code you generate for a model using Simulink® Coder™ or Embedded Coder®.
Stack (DSP System Toolbox) block
Supports model operating point when the Push full
stack parameter value is anything other than
Does not support model operating point
when the Push full stack parameter value is
Queue (DSP System Toolbox) block
Supports model operating point when the Push onto full
register parameter value is anything other than
Does not support model operating point
when the Push onto full register parameter value is
Model name programmatic interface
You cannot specify an operating point as the states input when you use the model name as a programmatic interface. For more information, see Use Model Name as Programmatic Interface.
- Final states | Save final operating point | Initial state | Single simulation output | Operating point restore interface checksum mismatch | Operating point object from a different release