Main Content

simscape.getLocalSolverFixedCostInfo

R2026b

Determine the iteration requirement for fixed-cost solvers

    Description

    s = simscape.getLocalSolverFixedCostInfo(modelName) determines the value for the Nonlinear iterations parameter to simulate the model, modelName, when using a fixed-step, fixed-cost solver. The function outputs a structure array with fields that contain information about the model, such as the solver path, number of iterations, and whether the simulation fails to converge.

    Note

    If you select the Use fixed-cost runtime consistency iterations parameter in the Solver Configuration block, this function only tries the number of iterations specified in the Nonlinear iterations parameter. Otherwise, the function tries 100 iterations.

    example

    Examples

    collapse all

    Determine the iteration requirement to optimize the model from the Full-Wave Bridge Rectifier example for a fixed-step, fixed-cost solver. Open the model.

    openExample("simscape/FullWaveBridgeRectifierExample")
    

    Double-click the Solver Configuration block. Select Use local solver, and clear Use fixed-cost runtime consistency iterations. In MATLAB, use the simscape.getLocalSolverFixedCostInfo function.

    set_param("FullWaveBridgeRectifier/Solver Configuration","UseLocalSolver","on")
    s = simscape.getLocalSolverFixedCostInfo("FullWaveBridgeRectifier")
    
    s =
    
      struct with fields:
    
           SolverPath: 'FullWaveBridgeRectifier/Solver↵Configuration'
        MaxIterations: 2
           Iterations: [50×1 int32]
                 Time: [50×1 double]

    The MaxIterations field reports that this model requires 2 iterations per step to run as a fixed-step, fixed-cost simulation. To visualize the time series data, use a bar plot.

    bar(s.Time, s.Iterations)
    ylim([1 3])

    Bar graph showing different time steps that require more than one Newton iteration.

    Open the Solver Configuration block, and select Use fixed-cost runtime consistency iterations. Set the Nonlinear iterations parameter to 2. The model is now optimized for using a fixed-step, fixed-cost solver.

    Input Arguments

    collapse all

    Model name, specified as a character vector or string scalar. If the model is not on the MATLAB® path, this argument must include the full path.

    Data Types: char | string

    Output Arguments

    collapse all

    Solver path and maximum iterations data, returned as a structure array with these fields:

    FieldDescription
    SolverPathNetwork path to the Solver Configuration block.
    MaxIterationsMaximum number of nonlinear iterations required for the simulation to converge. The value is -1 if the simulation fails to converge.
    IterationsNumber of nonlinear iterations at each time step, returned as an integer vector.
    TimeSimulation time at each time step, returned as a double vector.

    Data Types: struct

    Assumptions and Limitations

    • The function does not support Simscape™ Multibody™ networks.

    • The function does not support rapid accelerator mode.

    • The function does not support fast restart.

    Version History

    Introduced in R2021b

    expand all