Main Content

Setting Up Solvers for Physical Models

About Simulink and Simscape Solvers

This section explains how to select solvers for physical simulation. Proper simulation of Simscape™ models requires certain changes to Simulink® defaults and consideration of physical simulation trade-offs. For recommended choices, see Making Optimal Solver Choices for Physical Simulation.

Choosing Simulink and Simscape Solvers

Simulink and Simscape solver technologies provide a range of tools to simulate physical systems, including the powerful Simscape technique of local solvers. You choose global, or model-wide, solvers through Simulink. After making these choices, check that they are consistent; see Harmonizing Simulink and Simscape Solvers.

Working with Global Simulink Solvers

In the Configuration Parameters dialog box of your model, on the Solver pane, the solver and related settings that you select are global choices. For more information, see Solver Selection Criteria.

When you first create a model, the default Simulink solver is VariableStepAuto. For more information, see Choose a Solver. To select a different solver, follow a procedure similar to the procedure in Modifying Initial Settings.

  • You can choose one from a suite of both variable-step and fixed-step solvers.

  • You can also select from among explicit and implicit solvers. For physical models, it is recommended that you use implicit solvers, such as daessc, ode23t, and ode15s. Implicit solvers require fewer time steps than explicit solvers, such as ode45, ode113, and ode1.

    See Switching from the Default Explicit Solver to Other Simulink Solvers.

  • If all the Simulink and Simscape states in your model are discrete, Simulink automatically switches to a discrete solver and issues a warning. Otherwise, a continuous solver is the default.

  • By default, Simulink variable-step solvers attempt to locate events in time by zero-crossing detection. See Managing Zero Crossings in Simscape Models.

Working with Local Simscape Solvers

You can switch one or more physical networks to a local implicit, fixed-step Simscape solver by selecting Use local solver in the network Solver Configuration block. The solver and related settings you make in each Solver Configuration block are specific to the connected physical network and can differ from network to network.

A physical network using a local solver appears to the global Simulink solver as if it has discrete states. You can still use any continuous global solver.

Choosing Local Solvers and Sample Times.  To use a local solver, choose a solver type (Backward Euler, Trapezoidal Rule, or Partitioning) and a sample time. Backward Euler is the default.

Choosing Fixed-Cost Simulation.  You can select a fixed-cost simulation for one or more physical networks by selecting Use fixed-cost runtime consistency iterations, as well as Use local solver, and fixing the number of nonlinear and mode iterations. For more information, see Fixed-Cost Simulation.

Choosing Multirate Simulation.  With the local solver option, you can perform multirate simulations, with:

  • Different sample times in different physical networks, through their respective Solver Configuration blocks

  • A sample-based Simulink block in the model with a sample time different from the Solver Configuration block or blocks

Harmonizing Simulink and Simscape Solvers

Your Simulink and Simscape solver choices must work together consistently. To ensure consistency of your Simulink and Simscape solver choices for a particular model, open the model Configuration Parameters dialog box. In the model window, open the Modeling tab and click Model Settings. Review and adjust the following settings.

Simscape Pane of the Configuration Parameters Dialog Box

Switching from the Default Explicit Solver to Other Simulink Solvers

When you first create a model, the default Simulink solver is VariableStepAuto. Auto solver chooses a suitable solver as described in Choose a Solver, and for some types of models it can choose an explicit solver, ode45. If you do not modify the default (explicit) solver, your performance may not be optimal. Implicit solvers are better for most physical simulations. For more information about implicit solvers and physical systems, see Important Concepts and Choices in Physical Simulation.

Diagnostic Messages About Explicit Solvers.  When you use an explicit solver in a model containing Simscape blocks, the system issues a warning to alert you to a potential problem.

To turn off this default warning or to change it to an error message, go to the Simscape pane of the Configuration Parameters dialog box:

  1. From the Explicit solver used in model containing Physical Networks blocks drop-down list, select the option that you want:

    • warning — If the model uses an explicit solver, the system issues a warning upon simulation. This is the default option that alerts you to a potential problem if you use the default solver.

    • error — If the model uses an explicit solver, the system issues an error message upon simulation. If your model is stiff, and you do not want to use explicit solvers, select this option to avoid future errors.

    • none — If the model uses an explicit solver, the system issues no warning or error message upon simulation. If you want to work with explicit solvers, in particular for models that are not stiff, select this option.

  2. Click OK.

Enabling or Disabling Simulink Zero-Crossing Detection

By default, Simulink tracks an important class of simulation events by detecting zero crossings. With a global variable-step solver and without a local solver, Simulink attempts to locate the simulated times of zero crossings, if present. See Managing Zero Crossings in Simscape Models.

Diagnostic Messages About Globally Disabling Zero-Crossing Detection.  You can globally disable zero-crossing detection in the Solver pane of the Configuration Parameters dialog box, under Zero-crossing options. If you do, and if you are using a global variable-step solver without a local solver, the system issues a warning or error when you simulate with Simscape blocks.

You can choose between warning and error messages in the Simscape pane of the Configuration Parameters dialog box.

  1. From the Zero-crossing control is globally disabled in Simulink drop-down list, select the option that you want, if you globally disable zero-crossing detection:

    • warning — The system issues a warning message upon simulation. This option is the default.

    • error — The system issues an error message upon simulation, which stops.

  2. Click OK.

Making Multirate Simulation Consistent

The sample time or step size of the global Simulink solver must be the smallest time step of all the solvers in a multirate Simscape simulation.

To avoid simulation errors in sample time propagation, go to the Solver pane in the Configuration Parameters dialog box and select the Automatically handle rate transition for data transfer check box.