Main Content

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, smaller (since R2024a) or larger step size.

Using a local solver can facilitate system composition and integration. When you use local solvers, you can solve referenced models in system-level simulations using the same solver and step size used to design and test each model in isolation. Using local solvers can also reduce the number of configuration adjustments you need to make to configuration parameters in referenced models while integrating the model into a larger system.

For some systems, using a local solver can improve simulation performance by allowing you to:

  • Choose a solver that is more appropriate to solve the system in the referenced model

  • Use different step sizes for different components to reduce the number of redundant calculations in systems that have a wide range of dynamics among components.

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 Improve Simulation Performance by Using Local Solvers.

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. In each phase, each block in the model executes the block method that corresponds to the phase according to the execution order.

  • Output — Calculates block output values

  • Update — Typically calculates discrete state values

  • Advance — 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 Fixed-step.

    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 auto to 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 the step size for the local solver or specify auto to have the software determine the step size for the local solver.

    Before R2024a: The local solver step size must be an integer multiple of the step size for the parent solver.

Configure these options using the Model block parameters:

  • Communication step size — The discrete rate at which the Model block executes in the parent model (since R2024a)

  • Input signal handling — How the local solver extrapolates inputs from the parent model during the local advance stage

  • Output signal handling — How the parent solver interpolates required values from the model reference during the parent 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:

  • Multitasking execution

  • Saving or restoring a model operating point

  • Fast restart

  • Linearization

  • Code generation

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

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 auto or Full perturbation.

See Also


Model Settings

Related Topics