主要内容

restore

R2026b

Restore simulation configuration and model to their previous state

Since R2024a

    Description

    simulator_out = restore(simulator) restores the configuration set, signal logging, fast-restart state, and any other simulation arguments changed by the setup function.

    example

    Examples

    collapse all

    Open the model.

    model = "sdoCSTR";
    open_system(model)
    

    Create a simulation configuration for the model.

    simulator = sdo.SimulationTest(model);
    

    Configure the model and simulator for optimization and simulation, enabling fast restart.

    simulator = setup(simulator,FastRestart="on");
    

    Simulate the model.

    simulator = sim(simulator);
    

    The first simulation in fast restart mode requires the model to compile. Subsequent simulations execute in fast restart mode and reuse the compiled data.

    Adjust tunable model parameters.

    A = sdo.getParameterFromModel(model,"A");
    A.Value = 0.6;
    simulator.Parameters = A;
    

    Simulate the model again.

    simulator = sim(simulator);
    

    The model simulates in fast restart mode.

    Restore the simulator to its initial configuration, which disables fast restart.

    simulator = restore(simulator);
    

    Input Arguments

    collapse all

    Simulation configuration for Simulink® model, specified as an sdo.SimulationTest object. A simulation configuration specifies input signals, model parameter and initial state values, and signals to log for a model.

    Output Arguments

    collapse all

    Restored simulation configuration, returned as an sdo.SimulationTest object.

    Tips

    • You can add a cleanup function to ensure that the restore function always runs, even when the optimization generates an error.

      simulator = sdo.SimulationTest('mymodel');
      simulator = setup(simulator);
      cleanupObj = onCleanup(@()restore(simulator));

    Version History

    Introduced in R2024a