Main Content

slsim.allowedModelChanges

Determine changes you can make to model based on simulation status

Since R2022b

    Description

    changeLevel = slsim.allowedModelChanges(mdl) returns a string, changeLevel, that indicates the types of changes you can make to the model mdl based on the simulation status of the model.

    Use this function to control the execution of code that modifies a model and runs during simulation, including model, block, and simulation callback functions. You can also use this function to check which changes are allowed in iterative simulation workflows that use fast restart.

    example

    Examples

    collapse all

    Open and simulate the model sldemo_autotrans.

    mdl = "sldemo_autotrans";
    open_system(mdl)
    out = sim(mdl,"ReturnWorkspaceOutputs","on");

    Use the slsim.allowedModelChanges function to check which kinds of changes you can make to the model. Use the get_param function to check the simulation status.

    changeLevel = slsim.allowedModelChanges(mdl)
    changeLevel = 
    'any'
    
    simStatus = get_param(mdl,"SimulationStatus")
    simStatus = 
    'stopped'
    

    Because the model does not have fast restart enabled, the model does not stay compiled between simulations, and you can make any change to the model between simulations, including structural changes.

    Suppose you want to run a set of simulations for each input scenario in the file the Signal Editor block loads. Enable fast restart so that you only need to compile the model once in that set of simulations.

    set_param(mdl,"FastRestart","on")

    Simulate the model again.

    out = sim(mdl);

    Check which changes are allowed and the simulation status. Because the model has fast restart enabled, the model remains compiled after the simulation finishes, and you cannot make structural changes to the model. You can change only run-to-run and runtime tunable parameters.

    changeLevel = slsim.allowedModelChanges(mdl)
    changeLevel = 
    'runtorun'
    
    simStatus = get_param(mdl,"SimulationStatus")
    simStatus = 
    'compiled'
    

    Disable fast restart for the model.

    set_param(mdl,"FastRestart","off")

    Check which changes are allowed and the simulation status.

    changeLevel = slsim.allowedModelChanges(mdl)
    changeLevel = 
    'any'
    
    simStatus = get_param(mdl,"SimulationStatus")
    simStatus = 
    'stopped'
    

    Input Arguments

    collapse all

    Name of model to be modified, specified as a string or a character vector.

    Example: "vdp"

    Data Types: char | string

    Output Arguments

    collapse all

    Changes allowed for simulation status of model, returned as one of these options:

    • "any" — All types of changes are allowed, including structural changes and tuning run-to-run and runtime tunable parameters.

    • "runtorun" — Only changes to run-to-run and runtime tunable parameters are allowed. Structural changes to the model are not allowed.

    • "runtime" — Only changes to runtime tunable parameters are allowed. Structural changes and changes to run-to-run tunable parameters are not allowed.

    • "none" — No changes to the model are allowed.

    Version History

    Introduced in R2022b