The solver tolerance determines the accuracy that the states in the model are solved within. This post has a closer look at what tolerance is, how the tolerance used in Dymola effects the accuracy of the results and how you can effect the tolerance of a given signal. For further information about solver tolerance please refer to Section 5.4.3 of the Dymola User Manual Volume 1.pdf.

**What is tolerance?**

Tolerance is the accuracy to which the model will be simulated to. Another way of saying this is that the tolerance controls the maximum error of every successful simulation step.

**Why is there an error in the solution?**

The solver makes use of gradient information calculated in the previous time step to calculate the solution at the next time step. These gradients are continuous; however the values of these gradients are approximated by the solver.

An example of a harmonic oscillator being simulated with an Explicit Euler solver is given to illustrate this concept:

An error occurs when calculating the solution for the harmonic oscillator in Figure 1. because the derivative of x is assumed to be constant throughout the timestep. Note a smaller timestep would result in a smaller error; this is typically true for all solvers.

Note that more complex solver methods will typically integrate the gradients more accurately over the time-step.

**How is the error calculated?**

The actual error between the ideal solution and the calculated solution is not possible to calculate so an estimate of the error is calculated. A simplistic method for calculating an error would be to simulate using a smaller time step, an example of this is given in Figure 2.

The error approximation method in Figure 2 is very inefficient and better methods are used in actual solvers.

**Variable time step solvers versus fixed step solvers**

With fixed step solvers the size of the time step used does not vary; this means that the user must supply a small enough time step so that the simulation is accurate.

With a variable step solver the time-step is automatically adjusted so that the error approximation is below the tolerance.

**How the tolerance supplied in Dymola is used to calculate the actual tolerance**

The equation defining the tolerance of the simulation step is:

|local
error| < tolerance * |**x**[i]| +
tolerance * nominal(**x**[i])

where:

**tolerance** is the tolerance supplied in the Dymola solver**|x[i]|** is the absolute value of the state for which the tolerance is being calculated

nominal(**x**[i]) is the nominal value of the **x**[i] state

The error tolerance calculation can be broken into two sections, a relative tolerance and an absolute tolerance. The relative tolerance is:

tolerance*|**x**[i]|

The absolute tolerance is:

tolerance * nominal(**x**[i])

where the nominal() is a constant value supplied by the user for the **x**[i] state.

**Setting the nominal value of a signal**

The nominal value of a signal can be set in Modelica code as follows:

In the code above the nominal value of **s** is set to 10.

If no nominal value is set for a signal, then the default value of 1 is used.

**Understanding tolerance as the number of significant digits and decimal places to be calculated**

A simple way of understanding tolerance is that the relative tolerance sets the number of significant digits to be calculated using:

significant digits = -log_{10}(tolerance) (when **|x**[i]| is larger than the nominal value)

And the absolute tolerance sets the number of decimal places:

decimal places = -log_{10}(tolerance*nominal(x[i])) (when |**x**[i]| is less than the nominal value)

For example, if the tolerance is set to 1e-4 and the nominal value is 1, then the states will be calculated to 4 significant digits for absolute values larger than 1 and absolute values of less than 1 will be calculated to 4 decimal places.

**An example of setting an absolute error tolerance**

In the case of a vehicle being simulated with a tolerance of 1E-6, the maximum velocity error when the vehicle is stationary is 3.6 E-6 km/h or 1 E-6 m/s when the nominal value is 1 (i.e. the maximum error of the vehicle velocity is 1E-6 m/s that is 3.6E-6 km/h). After careful evaluation the user may decide that an absolute error of 1 E -3 m/s is enough.

Firstly determine the state of the model that corresponds to the velocity of the vehicle by translating the model and viewing the states.

Then modify the nominal value of this state to the value calculated using the equation:

nominal value = absolute error/tolerance

The equation above gives a nominal value of 1000 for this case.

This process can be performed for every state of the model.

**Written by: Garron Fish – Chief 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**