Use Local Solvers in Referenced Models
When you use referenced models to represent system components, you can configure each referenced model to use a local solver. When you use a local solver in a referenced model, the software solves the model reference as a separate set of differential equations using the local solver. The referenced model can use a solver that is the same or different from the solver used in the top model. Whether the local solver is the same or different, the local solver can use a different, larger step size.
Using a local solver can improve simulation performance by allowing you to:
Reduce redundant calculations in components with slower time dynamics.
Choose a different solver that is better suited for a component.
The choice of solver and solver settings involves a trade off between speed and accuracy in simulation. When you use local solvers, you can make different choices based on the requirements for each component.
For an example about using a local solver, see Simulate DC Motor Step Response Using Local Solver.
How Local Solvers Work
In a typical simulation that uses only one solver, the simulation loop executes in three phases for each major time step: output, update, and advance.
Output — The output method for each block in the system executes according to block position in execution order.
Update — The update method for each block in the system executes according to block position in execution order. The update method typically includes calculation of discrete state values.
Advance — The solver calculates continuous state values and determines the next major time step based on the solver selection, the solver parameter values, and the system dynamics.
When you use a local solver, the local solver computes state values for the referenced model during the update method for the referenced model. As part of the update method, the local solver performs a local advance for the model reference to calculate the next local time step. Because the local solver advance occurs before the system-level advance phase, the local solver execution gets ahead of the execution for the top model. When the local advance phase uses values that come from the parent model, the local solver extrapolates those values to the local time.
The top solver advance phase and the output phase for the next time step both occur between each local advance. In the top solver advance and output phases, the top solver might use values that are calculated by the local solver. Because the local solver is ahead of the top solver, the local solver provides interpolated values to the top solver.
Because using a local solver involves interpolation and extrapolation, simulation results might not match between equivalent simulations of the same model with and without the use of the local solver.
How to Configure Local Solvers
Configure the settings for a local solver using a combination of the configuration parameters for the referenced model and the block parameters for each Model block that references the model. The configuration parameter values in the referenced model have the same value for every instance of that model. You can configure the Model block parameter values differently for each model reference instance.
Configure these options using the configuration parameters of the referenced model:
Use local solver when referencing model — Select this parameter to use a local solver for the model when referenced in a model hierarchy.
When you select this parameter, the Solver and Fixed-step size parameter values for the referenced model apply to the local solver.
Type — Select
When you use a local solver, the top solver can be a variable-step or fixed-step solver, and the local solver must be a fixed-step solver.
Solver — Select
autoto have the software choose a solver, or select a solver other than the discrete solver, which is not supported as a local solver.
Fixed-step size (fundamental sample time) — Specify
autoto have the software determine the step size or specify the step size for the local solver as an integer multiple of the step size for the top model.
Configure these options using the Model block parameters:
Input signal handling — How the local solver extrapolates inputs from the top model during the local advance stage
Output signal handling — How the top solver interpolates required values from the model reference during the system advance phase
Additional Considerations for Local Solvers
You must determine whether a local solver provides benefit based on the dynamics and characteristics of your system. When evaluating where a local solver might provide benefit, look for model components that:
Operate with time constants one or more orders of magnitude larger than other parts of the system
Have continuous states that are decoupled from the rest of the system
Local solvers for referenced models operate on continuous states in the referenced model. Because using a local solver for a referenced model with only discrete states has no effect on simulation results, local solvers are not supported for models that do not contain continuous states. When a model contains no continuous states, the software always uses the discrete solver. The fixed-step discrete solver is not supported as a local solver.
Model hierarchies that contain one or more referenced models configured to use a local solver do not support:
Saving or restoring a model operating point
Referenced models configured to use a local solver do not support:
Fixed-step zero-crossing detection
Software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation modes
Model arguments are supported for referenced models configured to use a local solver only for normal mode simulation.
Local solvers are not supported for referenced models that directly or indirectly reference another model that has both continuous and discrete sample times, except when the model with continuous and discrete sample times:
Also uses a local solver
Directly or indirectly references another model that uses a local solver
Local solvers are not supported for models referenced by Model blocks:
Inside for-each subsystems
With initialize, reset, or terminate ports
That have variable-size signals at the model interface
When the top solver or a parent solver is implicit, the Solver Jacobian Method configuration parameter value for the top or
parent model must be the default value