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 the Customizing Solvers for Physical Models.
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.
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 Choose a Solver in the Simulink documentation.
When you first create a model, the default Simulink solver is ode45. 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. A variable-step solver is the default.
You can also select from among explicit and implicit solvers. An explicit solver is the default. But for physical models, MathWorks recommends implicit solvers, such as ode14x, ode23t, and ode15s. Implicit solvers require fewer time steps than explicit solvers, such as ode45, ode113, and ode1.
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 Enabling or Disabling Simulink Zero-Crossing Detection.
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 or Trapezoidal Rule) 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. Fixed-cost simulation requires a global fixed-step solver.
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
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. From the top menu bar in the model window, select Simulation > Model Configuration Parameters. Review and adjust the following settings.
Simscape Pane of the Configuration Parameters Dialog Box
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 Customizing Solvers for Physical Models.
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:
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.
You may need to provide time derivatives of some of the input signals, especially if you use an explicit solver. One way of providing the necessary input derivatives is by filtering the input through a low-pass filter. Input filtering makes the input signal smoother and generally improves model performance. The additional benefit is that the Simscape engine computes the time derivatives of the filtered input. The first-order filter provides one derivative, while the second-order filter provides the first and second derivatives. If you use input filtering, it is very important to select the appropriate value for the filter time constant.
The filter time constant controls the filtering of the input signal. The filtered input follows the true input but is smoothed, with a lag on the order of the time constant that you choose. Set the time constant to a value no larger than the smallest time interval in the system that interests you. If you choose a very small time constant, the filtered input signal is closer to the true input signal. However, this filtered input signal increases the stiffness of the system and slows the simulation.
Instead of using input filtering, you can provide time derivatives for the input signal directly, as additional physical signals.
You can control the way you provide time derivatives for each input signal by configuring the Simulink-PS Converter block connected to that input signal:
Open the Simulink-PS Converter block dialog box.
Click the Input handling tab.
To turn on input filtering, set the Filtering
and derivatives parameter to
Select the first-order or second-order filter, by using the Input
filtering order parameter, and set the appropriate Input
filtering time constant parameter value for your model.
To avoid filtering the input signal, set the Filtering
and derivatives parameter to
derivative(s). Then set the Input derivatives parameter
Provide first derivative —
If you select this option, an additional Simulink input port
appears on the Simulink-PS Converter block, to let you connect the
signal providing input derivatives.
Provide first and second derivatives —
If you select this option, two additional Simulink input ports
appear on the Simulink-PS Converter block, to let you connect the
signals providing input derivatives.
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 Working with Simscape Representation.
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.
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.
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.