Engee documentation

Getting started with solvers in Engee

What is a solver and what is it for

Solvers are tools for computing the dynamic behaviour of Engee models. The choice of a solver and its settings significantly affect the accuracy of the final solution and the speed of its obtaining. An unsuccessful one may even lead to an incorrect solution. There is no universal solver for all problems, so it is important to choose it taking into account the modelling goals and model features.

To view the current solver or select another one, open the window Settings debug article icon 1 and go to section Solver selection:

solvers settings 1

The first thing to do is to select the type of solver:

  • Fixed step - The step remains unchanged throughout the computational experiment. Usually used for real-time calculations or for checking the correctness of the numerical solution. Generally inefficient because the step over the entire simulation interval is limited by the requirements of certain more dynamic sections. Reducing the step size to a certain limit allows to increase the accuracy of the solution, but naturally has a negative effect on the speed of calculation;

  • Variable step - automatically adjust the step size as the computational experiment progresses, taking into account changes in the solution and estimates of local integration errors. Such solvers reduce the step in complex domains to maintain accuracy and increase it in simple domains to speed up the computation.

Solvers are also divided into discrete and continuous solvers. For models without continuous states (not having continuous integrators, transfer functions, etc.) - discrete solversm are used, otherwise continuous solvers are used. If one of the continuous solvers is selected for a model without continuous states, it will automatically be replaced by a discrete constant or variable step solver for efficiency, according to the original choice. An attempt to calculate a model with continuous states with a discrete solver will result in an error when starting the calculation.

Continuous solvers can be based on numerical methods of various types, among which it is worth mentioning separately:

  • * Implicit methods* - require solving a system of nonlinear algebraic equations at each step. They are suitable for stiff systems (see Sect. Solver selection) because they allow large steps without loss of stability, but each step requires serious computational resources. Examples in Engee: ImplicitEuler, Trapezoid, TRBDF2, RadauIIA5, KenCarp*, Kvaerno*, QNDF*, QBDF*, FBDF;

  • Semi-implicit methods - unlike implicit methods require solving already a system of linear algebraic equations at each step. Like implicit ones, they are well suited for rigid systems of equations. In general, strongly depend on the accuracy of the calculation of the Jacobi matrix. Examples in Engee: Rosenbrock*, Rodas*;

  • Multistep methods - use data from several previous steps to compute the next one. They can be particularly effective for large problems, but in the presence of multiple events their speed drops due to constant reinitialisations, so they are not recommended for models with discontinuous components. Examples in Engee: VCABM*, AB*, ABM*, QNDF*, QBDF*, FBDF.

    • is a family of methods, e.g. Kvaerno* means Kvaerno3, Kvaerno4, Kvaerno5, etc.

Solver selection

When calculating a model, it is impossible to achieve high accuracy and high speed at the same time. It is necessary to find a balance between these parameters by selecting a suitable solver. This will require a good understanding of the characteristics of the system it will be solving, namely:

  • System rigidity - a rigid model is one in which fast and slow processes occur simultaneously, such as in chemical reactions or electromechanical systems. For such models explicit methods due to their small stability region require very small steps, so it is better to use implicit or semi-implicit methods, the step of which will be limited only by accuracy requirements. A system is considered rigid if its time constants differ by 6 or more orders of magnitude;

  • Model size - the number of continuous variables uniquely identifying a particular state of the model. A model is considered large if it has more than 1000 state variables. The more there are, the slower the computation, especially in usage of implicit and semi-implicit methods. For large models, it is better to use methods with fewer calculations of the right-hand side (derivatives of the system) at each step;

  • Requirements to the solution accuracy - determine the closeness of numerical and exact solutions. The requirements for absolute and relative accuracy are separately distinguished:

    • Absolute tolerance (atol) - if the variable is modulo less than this setpoint, the local error estimate for the variable is considered to be zero. For example, for models with first-order solution components the value is usually used, but in general this setpoint is individual for each particular model;

    • Relative tolerance (rtol) - defines the allowable local error with respect to the variable value itself. Approximate values of the setpoint:

      • - low precision;

      • - high accuracy;

      • - very high accuracy.

        Higher accuracy requires usage of advanced solvers, which can noticeably increase the total computation time.

  • Gaps in the solution - some library components, e.g. Abs or Saturation, are characterised by sudden jumps in behaviour, resulting in gaps in the solution. Multistep methods are generally less efficient for such problems.

The following table can be used as a starting point for choosing a variable step solver:

Accuracy/rigidity Non-rigid Moderately stiff Rigid

Low

BS3

ROCK2

ImplicitEuler, Trapezoid, Rodas3, Rosenbrock23, TRBDF2

High Dimension: TRBDF2

Medium

Tsit5, BS5, DP5

Large dimension: VCABM

ROCK4

Rodas4, Rodas4p, KenCapr4

Large dimension: QNDF, QBDF

High

DP8, Vern6, Vern7, Vern8, Vern9

High dimensionality: VCABM

Rodas5, Rodas5p, RadauIIA5, Kvaerno5

Rodas5, Rodas5p, RadauIIA5, Kvaerno5

Large dimensionality: QNDF, QBDF

Since there is no universal solver for all models, you should choose a solver yourself, focusing on the peculiarities of the problem, required accuracy and acceptable computation time. In this case, you can try not only solvers from one cell (in the table above), but also from neighbouring cells in order to find the most optimal variant. The rational solution is to find a balance between performance and quality, which will allow to achieve correct and efficient modelling.