Which solver to use for Electrical System Simulation? | Simscape Electrical Modeling Practices for Fast Simulation
From the series: Simscape Electrical Modeling Practices for Fast Simulation
This video discusses model considerations to make when selecting a suitable solver for a physical network. You will learn about recommendations on variable-step and fixed-step solvers.
Published: 7 May 2024
Hello, my name is Eva, and I'm an application engineer at MathWorks. And in this video, I would like to give an overview on solvers for Simscape models. So to begin with, let's look at some solver and model considerations. So your model independent, if it is a Simulink model or also contains a Simscape network, can include discrete and/or continuous states. And it might display stiff or non-stiff behavior.
Stiffness itself is not an exactly defined term, but you can typically regard a model as stiff if it contains rapidly varying timescales-- so if it contains both slower and faster dynamics. And the solver can be categorized by its step size type. So it can be fixed-step or variable-step. Its state updates, which can be discrete or continuous. Its integration method, which can be explicit or implicit. And the solver order, which can be of fixed or variable type.
Here are two examples of solvers you can select for your Simulink or Simscape network. The name itself of the solver already gives some basic information on its categories. And looking at some of those in more detail, starting with explicit versus implicit solvers. So explicit solvers compute the current time step by using information from the previous time step. This results in less computational effort, but is also less stable. And explicit solvers are typically well-suited for non-stiff systems.
In contrast, implicit solvers compute the next time step by using an equation that contains both the previous and the next time step. This typically presents with more computational effort, but also more stability. And implicit solvers are better suited for stiff systems, which also makes them better suited for Simscape networks. And looking at fixed-step time and variable-step time solvers. So fixed time step solvers solve the model at regular time intervals, which is the step size.
And you can typically achieve more accuracy by decreasing that step size. And fixed-step solvers are typically mandatory if your final goal is cogeneration or hardware deployment. And variable step solvers can vary the step size during simulation. And they are typically varied to meet tolerance requirements, or to capture certain events such as zero crossings. And specifically, if you have a model with rapidly changing states, using a variable-step solver can reduce the total number of steps needed to solve the model.
And a specific option that comes when working with variable-step solvers is the definition of an absolute and relative tolerance. And during the simulation, the solver will always choose a step size so that the estimated error stays below either the relative or absolute tolerance. So looking at an example of how a state value-- this, for example, could be a Simscape variable-- varies over time.
So when that variable is of higher value, this is where typically the relative tolerance dictates the step size. As opposed to when it has a lower value, this is where the absolute tolerance is typically more important. When working with systems that contains continuous states, which is typically also present in Simscape networks, the available solvers for continuous state dynamics are listed here. So they are available for both variable-step size and fixed-step size. And there are those that are more recommended for stiff systems.
These are typically the ones that are also recommended when working with Simscape networks. However, there's an additional consideration you have to make when working with Simscape. It is that it constructs DAEs, or Differential Algebraic Equations. So when you hit Run on a model containing a Simscape network, one of the first steps will be to construct an equation systems.
And for the Simscape network, this will typically result in both ODEs, or Ordinary Differential Equations, equations that describe the rate of change of system variables. And it will also add algebraic equation constraints. And, as I said, typically both are present, which then results in a DAE, or Differential Algebraic Equation, system. So looking at a simple example of an electrical network which creates two voltage variables and one current variable.
And these will be described by two differential equations describing the rate of change of the voltages. And it will introduce the current variable by adding an algebraic constraint. And the solver will solve for all of those three variables. And when working with Simscape networks, you have the choice of using a variable-step solver. This is what is recommended for desktop simulation because it typically comes with better performance and accuracy for physical systems.
And even though if your final goal is to use a fixed-step solver, for example, because you're doing code generation, you can use the variable-step solver results as a baseline result, or you can also work with it to start-- try to uncover potential modeling issues. And when working with fixed-step simulation, there is the choice of either using a Simscape local solver, which is the first recommendation. With that, there is no subsampling.
Simscape networks will only be updated at each sample time and the entire network will be regarded as discrete. And consequentially, the choice of the global solver can be independent from that, or you can also have different sample times in your overall model. For example, if you have one sample time for the physical system and another one for the controller. Alternatively, you can omit the local solver and use the global Simulink solver, which then results in one sample time for the whole model.
Maybe starting with or sticking to variable-step solvers, Simscape networks typically require an implicit solver that is suited for stiff systems. And there's one that is exclusive for Simscape, which is the DAESSC, which is also the default auto-solver choice if the resulting equations from Simscape presents as DAEs. And in the auto-choice, if your Simscape networks results in only ODEs, the ode23t, which is suited for stiff systems and, compared to other ODE solvers, tends to be more stable, but damp out oscillation more.
An alternative to this one could also be the ODE 15s, which is, again, suited for stiff systems, but compared to the previous option, is less stable, but better at capturing oscillations. Another newer alternative is the odeN, which is not a true variable-step solver, but also not a true fixed-step solver. It provides fixed-step integration without the error control. So looking at that in more detail, as I said, it lives in between fixed and variable steps. So you can maybe call it a fixed-variable-step solver that is able to capture events.
And its fixed step size behavior is dictated by the max step size selection, but the solver can decide to reduce that fixed-step size specifically to capture events. For example, different discrete update rates or sample times in your model, or zero crossings. And the odeN is specifically meaningful if you work with PWM signals. But as opposed to a true variable-step solver, it doesn't provide error control.
So looking at where those different types of solvers live in terms of accuracy and cost. So fixed-step solvers typically come with lower cost but also tend to have lower accuracy. And if you start capturing events, such as zero crossings, but also want to provide error control, this is where the variable-step solvers live, which tend to come at higher cost, but also provide higher accuracy. So the odeN solver is located in between these two with the ability to capture, for example, zero crossings, but it does not provide error control.
And when working with a true fixed-step solver, the first recommendation would be to use a local Simscape solver. This is the one that lives in the solver configuration block. And within that, you have different choices for the local fixed-step solver, which is using the backwards Euler solver, which tends to damp out oscillation, but it is more stable. And the trapezoidal rule compared to the previous one is better at capturing oscillations, but is therefore also less stable.
And the third option, the partitioning solver, it can convert a larger Simscape network into smaller sets of equations. This is not an approach that is suitable for all Simscape models, but it can result in faster simulation. And if you opt to use a global fixed-step solver, a recommendation could be to use the ode14x, which is an implicit Simulink solver. Or alternatively, the ode1b3, which is a global backward Euler solver which can present as a lower cost alternative to the ode14x. Thank you for looking at this video. And you can find more information on the different solvers in the documentation.