Increase Simulation Speed Using the Partitioning Solver
The Partitioning solver is a Simscape™ fixed-step local solver that improves performance for certain models by reducing computational cost of simulation. Decreased computational cost yields faster simulation rates for desktop simulation and decreased task execution time (TET) for deployment. The solver converts the entire system of equations for the attached Simscape network into several smaller sets of switched linear equations that are connected through nonlinear functions. Computational cost is reduced because it is more efficient to calculate solutions for several smaller equation systems than it is to calculate the solution for one large system of equations.
The Partitioning solver does not partition models, that is it does not split a model into separate subsystems for multicore processing. To learn how to partition a Simscape model, see Partition a Model.
To use the Partitioning solver, open the Solver Configuration block settings and:
Select the Use local solver check box.
Set the Solver type parameter to
Clear the Start simulation from steady state check box.
Set the Equation formulation parameter to
For real-time simulation, also select the Use fixed-cost runtime consistency iterations check box. For more information, see Make Your Model Real-Time Viable.
Not all networks can simulate with the Partitioning solver. A simulation that uses the Partitioning solver results in an error if the Simscape network cannot be represented by switched linear equations connected through nonlinear functions. Simulating with the Partitioning solver also yields an error for networks that contain:
A custom component that uses the Simscape language
A block that uses a discrete sample time for periodic events. Examples include the PS Counter, PS Random Number, PS Repeating Sequence, or PS Uniform Random Number blocks from the Simscape/ Physical Signals / Sources library.
Certain Solver Configuration block settings are not compatible with the Partitioning solver. A simulation that uses a Partitioning solver results in an error if the model contains a Solver Configuration block with:
Start simulation from steady state selected
Equation formulation set to
Frequency and time
To further improve simulation performance, you can set the Partition
storage method parameter to
specify a value for the Partition memory budget [kB] parameter,
based on the Total memory estimate data in the Statistics
Viewer. For more information, see Solver Configuration and
Partitioning Solver Statistics.
Simulate a Simscape Model Using the Partitioning Solver
This example shows how to compare the speed and the accuracy of a simulation that uses the Partitioning solver to baseline results. It also shows how to compare the speeds of the Partitioning solver and the Backward Euler solver.
Open the model. At the MATLAB® command prompt, enter the code.
To return all simulation outputs within a single
Simulink.SimulationOutputobject so that you can later compare simulation times, enable the single-output format of the
% Enable single-output format set_param(model,'ReturnWorkspaceOutputs', 'on')
Enable the signal that goes to the Motor RPM scope block for Simulink® data logging and viewing with the Simulation Data Inspector.
The logging badge marks the signal in the model.
Run timed simulations for each of these solvers:
Variable-step global solver, the original solver for the model
Fixed-step local Backward Euler solver
Fixed-step local Partitioning solver
compTimeDiffTable = 3×2 table Solver Sim_Duration ________________ ____________ 'Baseline' [0.0319] 'Partitioning' [0.0204] 'Backward Euler' [0.0291] compPctDiffTable = 3×2 table Comparison Percent_Difference ____________________________________ __________________ 'Partitioning versus Baseline' [35.9128] 'Backward Euler versus Baseline' [ 8.6623] 'Partitioning versus Backward Euler' [29.8349]
Simulation time on your machine may differ because simulation speed depends on machine processing power and the computational cost of concurrent processes.
The local fixed-step Partitioning and Backward Euler solvers are faster than the variable-step baseline solver. The Partitioning solver is typically, but not always, faster than the Backward Euler solver.
To compare the results, open the Simulation Data Inspector.
To see the comparison, click Compare and then click Sensing 1.
The first plot shows the overlay of the baseline and Partitioning solver simulation results. The second plot shows how they differ. The default tolerance for differences is
0. To determine if the accuracy of the results meet your requirements, you can adjust the relative, absolute, and time tolerances. For more information, see Compare Simulation Data.
- Determine Step Size
- Estimate Computation Costs
- Reduce Fast Dynamics
- Reduce Numerical Stiffness
- Reduce Zero Crossings
- Partition a Model