When viewed from the user’s perspective, simulation models should always run faster than they currently do. There is no model on the planet that runs *too* fast! Non-linear systems of equations (especially ones with large numbers of equations) often present one of the biggest drags on model speed. Such equation systems result from coupled sets of equations forming a loop in the model.

Imagine a scenario where a vehicle velocity sensor output is used in an engine control system. The sensor output has a direct impact on the quantity it is measuring. You’ve made an algebraic loop, manifesting as a Non-Linear system in the model. Often, this nonlinear system will be a limiting factor on your simulation speed. This overhead results from the use of an iterative numerical method to find the system’s result for each time step.

Dymola will try to minimise Non-Linear systems for you during the symbolic manipulation process. But in many cases it can’t get rid of them all. When searching for increased simulation performance, we need to be able to adapt the model to remove a Non-Linear system. Filters can be used to do just this. For best results, we should be careful selecting where and how to use them. This blog post will guide you through this.

## What is a Non-Linear system? Why should I care about them?

Each loop is basically a system of equations bound together by its own result variable. Think back to our vehicle velocity sensor example. Let’s say an engine control action is dependent on the vehicle velocity. A change in vehicle velocity changes the control action of the engine, in turn affecting the vehicle velocity, which changes the engine control… and so forth.

Some loops vary in a linear fashion and can be solved more easily. Others vary in a Non-linear way; these are the dreaded Non-Linear systems of equations. These systems require their own up to date Jacobian matrix to be solved. It even sounds computationally expensive. Sometimes this can be generated analytically, otherwise a numerical Jacobian has to be calculated and often re-calculated at each step. This further compounds your Non-Linear system induced world of pain.

The states chosen in the model directly impact Dymola’s ability to break loops. You might be already aware of states and their impact from previous editions of the Claytex blog, especially if you are familiar with Multibody models.

## How does a filter reduce the size of a Non-Linear system?

So what do states have to do with a filter? Filter blocks within Dymola feature transfer functions describing the differential (time dependent) relationship between the raw input and filtered output. Quite simply, Dymola is able to identify the filter output as a state during symbolic manipulation.

Let’s think of the filter as a raw input and smooth output linked by the transfer function and apply it to the vehicle velocity sensor example. With the addition of the filter state relating these two variables, Dymola is able to split the Non-Linear system bound together by a single variable (vehicle velocity) into two *separate* equations sets. A raw input and a filtered output. Immediately the single large Non-Linear system is able to be considered two separate systems and can be reduced to an equation set with no Non-Linear systems.

## How and where to deploy filters to break up Non-Linear systems.

Locating your filter very much depends upon the model itself. Current incarnations of Dymola make this job simple. Variables used in Non-Linear systems are now viewable from the translation window. Simply set the **Advanced.LogNonLinearIterationVariables** flag either from the commands window or the dialog box.

Any domain is valid for Non-Linear system iteration variables. Being Real based, filter location is limited to real variables. Therefore, the Non-Linear system needs to be interrogated for a suitable location. We should look for non-physical variables in the equation set for a clue as to where it could go.

That being said, physical variables in your Non-Linear system can also indicate potential filter locations. Look for any variable in the system that you recognize as being an actuator output. After all, actuators generally feature real inputs. If there’s a real input, there’s potential filter location. In some cases, the actuator comes with a built-in filter ready to be activated by Boolean.

Here is a practical example of how a filter can be deployed to remove a large Non-Linear system:

If we look at the the box highlighted in the figure above, we can see that I have removed a filter on the ESP pump command. All the other wheels have it, which is why there is only one entry in the large Non-Linear system, corresponding to the wheel without a filter.

This is how the ESP pump should look, with 4 filters. As we can see, the very large Non-Linear system has been removed!

## Filter with care!

There’s no such thing as a free lunch, right? The same applies to deploying filters to speed up your model. A state is added to your model each time you add a filter. Each state has to be integrated by the solver, adding computational effort. Usually there is a net gain. It’s often easier to solve a state than a large Non-Linear system. This is especially true if the state you’ve added is relatively stable and doesn’t change quickly.

We also need to consider the effect of the filter on system dynamics. By adding the filter, you are adding lag (proportional to the time constant) and a degree of smoothing. How much lag is too much is up to you. It also depends on your system operating region. Too much lag in our earlier engine control example would cause a lethargic controller. This behaviour may be unacceptable in transient conditions such as traction control. Yet, we could consider it acceptable in a steady state condition like cruise control. Excessive filter lag is also associated with a high degree of signal smoothing. System dynamics can be suppressed or missed with excessive smoothing.

## Closing remarks

Filters are a useful tool to us as model developers. Reformulating or rebuilding models to eliminate Non-Linear systems can sometimes be achieved without adding filters. In other cases, filters are the only way. Care should be taken when deploying filters however, to ensure the model is running as desired and providing adequate fidelity for the task at hand!

**Written by: Theodor Ensbury – Project Engineer**

**Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion.**