Speed Up Simulation Workflows by Using Model Operating Points - MATLAB & Simulink (original) (raw)
In many applications, systems exhibit a startup phase that involves significant dynamic behavior. For example, suppose you want to simulate the response of an airplane model to several flight maneuvers. To simulate each flight maneuver, the airplane must first take off. In each simulation, takeoff is the same. To save time by simulating takeoff, the startup phase, only once, use model operating points.
- Configure the model or simulation to save the final operating point at the end of simulation.
- Run one simulation through the end of the startup phase.
- Use the model operating point saved at the end of the startup phase as the initial state for subsequent simulations.
A 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 without an initial operating point.
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 Point When Simulation Paused or Stopped
To save a model operating point to the workspace when the simulation is paused or stops, configure the model or simulation to save the final operating point at the end of the simulation. By default, the simulation returns the final operating point with the rest of the simulation results, as a property of the Simulink.SimulationOutput object.
Configuring a model to save the final operating point dirties the model. If you save the model, the parameter values are saved with the model. To configure a model to save the final operating point, enable the Final states and Save final operating point configuration parameters in the model.
- In the Simulink® Toolstrip, on the Modeling tab, underSetup, click Model Settings.
- In the Configuration Parameters dialog box, select the Data Import/Export pane.
- In the Data Import/Export pane, select Final states and Save final operating point.
- Click OK.
Alternatively, use the set_param
function to enable theSaveFinalState
and SaveOperatingPoint
parameters.
set_param(mdl,SaveFinalState="on",SaveOperatingPoint="on")
When you configure a simulation to save the final operating point, the parameter values are applied for the simulation and reverted when the simulation ends. To configure a simulation to save a final operating point, use one of these approaches:
- Use the setModelParameter function to enable the
SaveFinalState
andSaveOperatingPoint
parameters on a Simulink.SimulationInput object or aSimulation object. Then, run a simulation using theSimulationInput
orSimulation
object.
This code shows how to configure the parameters on aSimulationInput
object for the modelmdl
and then simulate the model using thesim
function.
simin = Simulink.SimulationInput(mdl);
simin = setModelParameter(simin,SaveFinalState="on");
simin = setModelParameter(simin,SaveOperatingPoint="on");
out = sim(simin); - Specify the parameters as input to the
sim
function. For example, this code specifies the parameters as name-value arguments.
out = sim(mdl,SaveFinalState="on",SaveOperatingPoint="on");
A 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 returned 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 FinalStateName
parameter. By default, the operating point is returned in a property named xFinal
. To access the final operating point saved from simulation, use dot notation.
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, by using the
set_param
function to issue the simulation command to stop, or by calling the stop orterminate function in a simulation run using aSimulation
object. - You pause the simulation by clicking Pause, by using the
set_param
function to issue the simulation command to pause, or by calling the pause function in a simulation run using aSimulation
object.
To save the model operating point to the workspace at any time during simulation, pause the simulation, then use the get_param
function to get the value of theCurrentOperatingPoint
parameter for the model.
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.
Save Model Operating Point During Simulation
Since R2025a
You can also log model operating points to a MAT file during normal, accelerator, and rapid accelerator simulations. By logging operating points during simulation, you can:
- Recover from crashes faster by resuming the simulation from an operating point logged before the crash.
- Debug errors that occur in long-running simulations faster by starting a simulation debugging session from an operating point logged before the error occurred.
- Run a single simulation to save the model operating point at each transition point in simulations that have predetermined and structured phases. You can then save time by using the appropriate operating point in subsequent simulations so that each simulation runs only the relevant phases.
To ensure that the logged operating point data is saved if the simulation issues an error or MATLAB crashes during simulation, the operating points saved during simulation are logged to a MAT file instead of the workspace. The MAT file contains one variable for each operating point captured. Each variable uses the naming scheme<ModelName>_OperatingPoint_N
, where N
starts at 1 and increases incrementally for each new operating point. To easily debug from the most recently logged operating point, the MAT file contains the variableLatestVariableName
, which is a string set to the name of the variable with the most recently logged operating point. When the number of saved operating points exceeds either 100 or the maximum number of operating points saved in the MAT file specified by the OperatingPointLoggingMaxPoints parameter, the earliest operating point is deleted from the MAT file without renaming the other variables.
To identify the MAT file containing saved operating points associated with a simulation, access the full file path using the Simulink.SimulationOutput
object.
opFilePath = out.SimulationMetadata.ModelInfo.LoggingInfo.OperatingPointLoggingFile;
Note
When you enable the Save final operating point parameter, the final operating point logs to the workspace and does not log to the MAT file with the operating points logged during simulation.
To log operating points during simulation, enable and configure the operating point logging model parameters described in this table.
Parameter Name | Description |
---|---|
OperatingPointLogging | Option to enable operating point logging, specified as one of these values:"on" — Log operating points to MAT file during simulation."off" (default) — Do not log operating points to MAT file during simulation.This command enables operating point logging for the modelmdl.set_param(mdl,OperatingPointLogging="on") |
OperatingPointLoggingMethod | How operating points are logged during simulation, specified as one of these values:"clock-interval" (default) — Log operating point periodically based on wall-clock time."sim-interval" — Log operating point periodically based on simulation time."sim-times" — Log operating point at simulation times specified using the OperatingPointLoggingTimes parameter.This command configures the model mdl to log operating points periodically based on wall-clock time.set_param(mdl,OperatingPointLoggingMethod="clock-interval") |
OperatingPointLoggingTimes | When to log operating points during simulation, specified as a real, scalar, positive number or as an array of real, scalar, double values. The value that you specify depends on the value of theOperatingPointLoggingMethod parameter."clock-interval" logging — Real, scalar, positive number greater than 1. Fractional values are rounded to the nearest second."sim-interval" logging — Real, scalar, positive number greater than 0."sim-times" logging — Array of real, scalar double values. Duplicate values and values outside the time range of the simulation are ignored.When a specified simulation time or a simulation time calculated from the simulation time interval does not align with a major simulation time hit, the operating point is logged at the next major time hit.These commands configure the model mdl to log an operating point every 10 minutes of wall-clock time during simulation.set_param(mdl,OperatingPointLoggingMethod="clock-interval") set_param(mdl,OperatingPointLoggingTimes=600) |
OperatingPointLoggingFile | Relative or absolute file path of MAT file to contain logged operating point data, specified as a string or a character vector. When you specify a relative file path, the software creates the MAT file in the specified location, relative to the current working directory when you start the simulation.By default, the parameter value is an empty string. When the parameter value is an empty string, the software saves the MAT file in the current working directory with a filename based on the name of the model. For example, the default filename for a model named MyModel isMyModel-OperatingPoints.mat.In multiple simulation workflows, you must specify the file path. Specifying absolute file paths is recommended, especially when running simulations using theparsim command, because relative file paths are relative to the directory in which the worker runs the simulation. Logging operating points when running a set of multiple simulations creates multiple MAT files. Each MAT file uses the naming scheme _N, where N starts at 1 and increases incrementally.This command configures the modelmdl to log operating point data to a MAT file namedMyOperatingPointData in the current working directory.set_param(mdl,OperatingPointLoggingFile="MyOperatingPointData.mat") |
OperatingPointLoggingMaxPoints | Maximum number of operating points to save in MAT file, specified as a scalar integer between 1 and 100. By default, the simulation saves up to 10 operating points in the MAT file.Operating point logging can affect simulation performance. To reduce the performance impact, log fewer operating points.This command configures the model mdl to save up to 20 operating points in the MAT file.set_param(mdl,OperatingPointLoggingFile=20) |
To configure parameters in the model, use the set_param
function.
For example, configure the parameters in the model to log an operating point at five specified simulation times and save the operating points to a MAT file namedMyLoggedOPs
.
- Enable operating point logging.
- To log the operating points at specific simulation times, specify
OperatingPointLoggingMethod
as"sim-times"
. - Specify the simulation times at which to save an operating point.
- Configure the model to log operating point data to a MAT file named
MyLoggedOPs
in the current working directory.
set_param(mdl,OperatingPointLogging="on"); set_param(mdl,OperatingPointLoggingMethod="sim-times"); set_param(mdl,OperatingPointLoggingTimes=[100,1000,2500,2600,5000]); set_param(mdl,OperatingPointLoggingFile="MyLoggedOPs.mat");
To configure parameters for a simulation without modifying the model, use thesetModelParameter
function to set the parameters on aSimulink.SimulationInput
object or a Simulation
object.
For example, configure the parameters on a Simulink.SimulationInput
object to log an operating point once every hour and save the data to a file namedMyHourlyOPs
.
- Enable operating point logging.
- To log operating points periodically based on wall-clock time, specify
OperatingPointLoggingMethod
as"clock-interval"
. - Specify the time interval as 3600 seconds.
- Save the operating points to a MAT file named
MyHourlyOPs
in the current working directory.
simin = Simulink.SimulationInput(mdl); simin = setModelParameter(simin,OperatingPointLogging="on"); simin = setModelParameter(simin,OperatingPointLoggingMethod="clock-interval"); simin = setModelParameter(simin,OperatingPointLoggingTimes=3600); simin = setModelParameter(simin,OperatingPointLoggingFile="MyHourlyOPs.mat");
The operating point logging model parameters are not saved as part of the model.
Simulate from Initial Operating Point
To simulate from an initial operating point:
- Enable the Initial state parameter.
- Specify the initial state as a
ModelOperatingPoint
object. - Set the stop time for the simulation to a time that is larger than the snapshot time of the initial operating point.
If you logged operating points to a MAT file during simulation, load the data to use as the initial state. For example, load the last operating point saved to the MAT file namedOperatingPointLogs
in the working directory.
loggedOPs = load("MyLoggedOPs.mat"); latestSnapshot = loggedOPs.(loggedOPs.LatestVariableName);
When you simulate from an initial operating point, do not change the start time of the simulation. The operating point resumes the simulation that produced the operating point. The simulation start time acts as a reference for all time and time-dependent variables. If the simulation start time does not match the start time of the initial operating point, the software issues a warning and uses the start time of the initial operating point as the start time for the simulation.
For example, suppose you run a simulation from 0 to 100 seconds that saves the final operating point. To run a simulation from 100 seconds to 200 seconds using the operating point from the first simulation:
- Specify the stop time as 200 seconds.
- Specify the initial state as the model operating point you saved at 100 seconds.
- Leave the start time set to 0 seconds.
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. For all three simulations, the start time is 0 seconds.
You can configure the parameters to simulate from an initial operating point in the model or in the simulation. Configuring parameters in the model dirties the model. If you save the model, the parameter values are saved in the model. When you configure parameter values in the simulation, the parameters are applied to the model during simulation and reverted when the simulation ends.
To configure the parameters in the model to simulate from an initial operating point:
- In the Simulink Toolstrip, on the Modeling tab, underSetup, click Model Settings.
- In the Configuration Parameters dialog box, on the Data Import/Export pane, select Initial state. Then, in the box, enter either the name of the variable that contains the initial operating point or a MATLAB® expression that evaluates to the initial operating point.
- On the Solver pane, specify a value for the Stop time parameter that is greater than the snapshot time of the initial operating point.
- Click OK.
Alternatively, use the set_param
function to specify theLoadInitialState
, InitialState
, andStopTime
parameters. For example, this code shows how to configure the model mdl
to simulate from an initial operating point saved in a prior simulation for 100 seconds beyond the snapshot time of the initial operating point.
xinit = out.xFinal; st = xinit.snapshotTime + 100; set_param(mdl,LoadInitialState="on",InitialState="xinit",StopTime="st")
To configure a simulation to run from an initial operating point without dirtying the model, use one of these approaches:
- Use the setModelParameter function to specify the
LoadInitialState
,InitialState
, andStopTime
parameters on a Simulink.SimulationInput object or a Simulation object. Then, run a simulation using theSimulationInput
orSimulation
object.
This code shows how to configure the parameters on aSimulationInput
object for the modelmdl
and then simulate the model using thesim
function. TheSimulationInput
object configures the simulation to run from an initial operating point saved in a prior simulation for 100 seconds beyond the snapshot time of the initial operating point.
xinit = out.xFinal;
st = xinit.snapshotTime + 100;
simin = Simulink.SimulationInput(mdl);
simin = setModelParameter(simin,LoadInitialState="on");
simin = setModelParameter(simin,InitialState="xinit");
simin = setModelParameter(simin,StopTime="st");
out = sim(simin); - Specify the parameters as input to the
sim
function. For example, this code specifies the parameters as name-value arguments.
xinit = out.xFinal;
st = xinit.snapshotTime + 100;
out = sim(mdl,LoadInitialState="on",InitialState="xinit", ...
StopTime="st");
Configure Flexibility of Operating Point Initialization
By default, the software is configured to support the simulation continuation workflow by ensuring that the simulation results match the results of an equivalent simulation that runs from the start, without an initial operating point. For example, if you tune a parameter value between saving and loading a model operating point, the simulation results match the results of a simulation that experiences the same change at the snapshot time of the initial operating point. To ensure simulation results satisfy the accuracy requirements of the simulation continuation workflow, the software:
- Detects modifications to the model that can prevent complete initialization to the operating point and can have unexpected, significant, or unintended effects on the simulation results.
- Prevents simulating from an operating point that was generated using a different version of Simulink software.
To detect modifications to the model, the software uses structural checksums. The_structural checksum_ of a model tracks information about the model interface, configuration, and algorithmic structure. The structural checksum represents a superset of checksums, including the interface checksum and the contents checksum.
- The interface checksum tracks a collection of model settings, including inherited and derived settings, that do not affect the model structure or algorithmic behavior but can affect simulation results.
- The contents checksum tracks information about the model structure and algorithmic behavior.
To speed up simulation workflows, such as debugging, that do not require this level of accuracy, configure the software to allow incomplete operating point initialization. The software provides three model configuration parameters you can set independently to satisfy the requirements of your workflow. The table summarizes the available parameters and the workflows they enable.
Configuration Parameter | Default Setting and Workflow | Additional Workflow Options |
---|---|---|
Operating point interface checksum mismatch | By default, the software issues a warning and initializes the simulation using as much operating point data as possible if the interface checksum of the model does not match the interface checksum of the initial operating point.You can modify model settings that do not affect the structure or algorithmic behavior of the model between saving a model operating point and using the operating point to initialize a simulation. | To suppress the warning, set the parameter tonone.To prevent modifications to the model between saving an operating point and using the operating point to initialize a simulation, set the parameter toerror. |
Operating point contents checksum mismatch (since R2025a) | By default, the software issues an error and terminates the simulation if the contents checksum of the model does not match the contents checksum of the initial operating point.You cannot make changes that affect the contents checksum of the model between saving a model operating point and using the operating point to initialize a simulation. | To enable flexible operating point initialization, set the parameter towarning or none. If the contents checksum of the model does not match the contents checksum of the initial operating point, the software initializes the simulation using as much operating point data as possible.When you enable flexible operating point initialization, the ModelInfo structure in the simulation metadata contains the field OperatingPointMismatches that contains information the software is able to report about uninitialized blocks and unused operating point data.If you set the parameter towarning, the software issues one or more warnings during initialization that provide information about differences that cause the contents checksum mismatch and how the software initialized the simulation. |
Operating point object from a different release | By default, the software issues an error and terminates the simulation if the initial operating point that was generated in a different release. | If you set the parameter to warning, the software initializes the simulation using only the block state data in theloggedStates property of the initial operating point. |
Model Operating Point Considerations and Limitations
Not all blocks, features, modeling patterns, and simulation modes support saving and loading model operating points. In some cases, you can avoid model operating point limitations by saving and loading only block states instead. For more information, see Save Block States and Simulation Operating Points.
The table summarizes limitations and considerations for using model operating points with other features.
Feature or Modeling Pattern | Considerations and Limitations |
---|---|
Simulation modes | Saving and loading 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 load that operating point in a simulation that runs in a different simulation mode.Additional limitations apply for rapid accelerator simulations. |
Rapid accelerator simulations and simulations deployed using Simulink Compiler™ | These limitations apply to saving and loading model operating points in rapid accelerator simulations: You cannot modify the operating point information, such as block states.Variable-size signals are not supported.Flexible operating point initialization is not supported.These blocks do not support saving and restoring the model operating point in rapid accelerator simulations: From Spreadsheet blocksModel blocks with initialize, reset, or terminate portsModel blocks configured as multiple-instance export-function modelsModel blocks that reference models that contain string data typesTransport Delay and Variable Transport Delay blocks inside for-each subsystemsn-D Lookup Table blocksData Store Memory blocksMATLAB System blocksLevel-2 MATLAB S-Function blocksS-Function blocks with custom operating point implementationsS-Function blocks that use PWork vectors |
Model references | For model hierarchies that contain one or more referenced models configured to use a local solver, saving and restoring an operating point is supported by only normal mode simulations. 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.Saving and loading model operating points is not supported if a referenced model that is configured to simulate in accelerator mode contains any of these blocks: Level-2 MATLAB S-Function blocksMATLAB System blocksn-D Lookup Table blocksS-Function blocks with custom operating point implementationsS-Function blocks that use PWork vectorsTo File blocksWhen you save logged states data using theDataset format, saving and loading model operating points is not supported if a referenced model that is configured to simulate in accelerator mode contains one or more states that use any of these data types: halfstringCharacter vectorFixed-point |
Simscape™ | Model operating points include operating point data for Simscape blocks in the model. However, theModelOperatingPoint object does not provide access to the Simscape operating point data. As a result, you cannot modify the Simscape operating point data in a model operating point before using it to initialize a simulation.Simscape has a separate operating point that you can use to initialize only the Simscape blocks in the model. For more information, see Using Operating Point Data for Model Initialization (Simscape).You cannot use both a model operating point and a Simscape operating point to initialize the same simulation. If you configure the simulation to load both a model operating point and a Simscape operating point, the model operating point overrides the Simscape operating point.Whether to initialize a simulation using a model operating point or a Simscape operating point depends on which parts of your model require initialization and which parts of the operating point data you need to modify.If you need to initialize both Simulink and Simscape content in your model, use model operating points.If you need to modify Simscape operating point data before initializing a simulation, use Simscape operating points. When you use Simscape operating points, you cannot use a model operating point to initialize the Simulink content of the model.If you need to initialize only Simscape content in your model, use Simscape operating points.If your model contains both Simscape and Stateflow® content, you cannot modify both the Simscape operating point data and the Stateflow operating point data before using an operating point to initialize a simulation. |
Stateflow | Model operating points save operating point information for Stateflow content in the model. Stateflow operating point data is not stored in theloggedStates property of theModelOperatingPoint object. To access and modify the Stateflow operating point data, use the get and set functions. For more information, see Save and Restore Operating Points for Stateflow Charts (Stateflow). |
MATLAB Function block | Saving and restoring the model operating point is generally supported for models that contain MATLAB Function blocks. However, the use of certain constructs in the MATLAB code can affect the support.Saving and loading model operating points 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. |
S-functions | When you write an S-function, you can specify how the software saves and loads the operating point of the S-function by setting the operating point compliance. For Level-2 MATLAB S-functions, see Level-2 MATLAB S-Function Compliance with Model Operating Point.For C MEX S-functions, see ssSetOperatingPointCompliance.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 loading model operating points is not supported for S-functions that produce outputs with custom data types. For more information, see Configure Custom Data Types. |
Code generation | You cannot save or load model operating points in code you generate for a model using Simulink Coder™ or Embedded Coder®. |
Stack (DSP System Toolbox) block | Supports saving and loading model operating points when thePush full stack parameter value is anything other thanDynamic reallocation.Does not support saving and loading model operating points when the Push full stack parameter value is Dynamic reallocation. |
Queue (DSP System Toolbox) block | Supports saving and loading model operating points when thePush onto full register parameter value is anything other than Dynamic reallocation.Does not support saving and loading model operating points when the Push onto full register parameter value is Dynamic reallocation. |
Model name programmatic interface | You cannot use an operating point to specify the states input when you use the model name as a programmatic interface. For more information, see Use Model Name as Programmatic Interface. |
See Also
Model Settings
- Save final operating point | Initial state | Operating point interface checksum mismatch | Operating point contents checksum mismatch | Operating point object from a different release
Objects
- Simulink.op.ModelOperatingPoint | Simulink.SimulationOutput | Simulink.SimulationInput | Simulation | Simulink.SimulationMetadata