stiff3 is a semi-implicit Runge Kutta solver with adaptive time-stepping originally from the book by Villadsen & Michelsen, Solutions of Differential Equation Models by Polynomial Approximation, Prentice-Hall, 1978.

The solver is now available as an fpm package and uses LAPACK for the matrix factorization and back-substitution in the semi-implicit time-stepping.

The solver is designed for autonomous problems of the form

\frac{dy}{dx} = f(y)

In case of a non-autonomous problem where x appears explicitly, i.e. y' = f(x,y), it suffices to switch to a new integration variable t and introduce the additional ODE

\frac{dx}{dt} = 1

The repository provides an example for the Van der Pol oscillator. Here are some plots of the solutions and phase cycle.

There is one remaining issue with the stiff3 solver where Iâ€™m seeking help. It has to do with a section of code that sets to zero some elements of the Jacobian matrix. I believe this section is just an outdated practice that has to do with legacy usage patterns. Iâ€™ve posted it as a question on SciComp StackExchange, but so far it is still unanswered.

Indeed, that is more elegant. However, I think the zero values should be set explicitly in the user-provided Jacobian routine, and there is no need for this chunk of code at all. It doesnâ€™t make sense to me to hardcode a df_tol cutoff in the Jacobian matrix.

Great stuff @ivanpribec! Nice to see the fpm ecosystem growing with more useful packages!

Regarding your final point, Iâ€™ve previously come across thresholding of small matrix elements for iterative methods - I believe itâ€™s to avoid having very small eigenvalues which degrade convergence of the overall method or place severe limits on the region of stability.

As pointed out on the scicomp post, these small values creep in unavoidably due to floating-point arithmetic, but they are essentially zero because they are smaller than the effective numerical precision which gets smaller as matrix condition number increases. (I think I read somewhere that every order of magnitude in the condition number takes off one significant figure in numerical precision.) The value of the cut-off threshold was perhaps set based on some expected condition number.

I donâ€™t have a direct comparison but I can imagine that VODE is much more robust, having originated from the group of Hindmarsh. VODE is also younger, published in 1989, while the stiff3 code I refactored was originally published in 1978.

There are several things missing in stiff3, including:

dense output of variables

support for banded or sparse Jacobians

more precise control over the error tolerances and time-stepping

Stiff3 was designed primarily for autonomous systems, i.e. those without an explicit â€śtimeâ€ť dependence. As a semi-implicit method it is also designed to work exclusively with analytic Jacobian matrices. Use of finite-difference approximations for the Jacobian matrix will not work.

Use VODE if you need a robust and mature ODE solver. Stiff3 is more of a teaching code, perhaps still useful for smaller problems.