TR-BDF2 algorithm for solving ODE systems
See original GitHub issueIs your feature request related to a problem? Please describe.
The proposed feature request is to implement the TR-BDF2 algorithm in SciPy for solving ODE systems. The TR-BDF2 algorithm is an implicit Runge-Kutta formula with a trapezoidal rule step as its first stage and a backward differentiation formula of order two as its second stage. The algorithm is suitable for stiff problems and resilient to oscillations.
Describe the solution you’d like
I would like to implement the algorithm using the method
argument as part of the solve_ivp
function.
from scipy.integrate import solve_ivp
sol = solve_ivp(dydt, tspan, y0, method='TRBDF2', args=(params,))
Describe alternatives you’ve considered
For a large system of coupled ODEs, I have used Matlab’s ode23tb
function for this algorithm. I have tried the Radau
, BDF
, and LSODA
solvers in SciPy but they don’t converge to a solution for my particular problem. Matlab’s ode23tb
function is the only one that seems to work.
Additional context (e.g. screenshots)
Matlab implements TR-BDF2 algorithm as the ode23tb
function (see the Matlab docs for more info). Discussion of the algorithm is given in the following papers: “Transient simulation of silicon devices and circuits” and “Analysis and implementation of TR-BDF2”. Julia also has an implementation of the algorithm as TRBDF2
which is part of the DifferentialEquations.jl package (see the Julia docs for details). I also found this C program that appears to use the algorithm to solve a nonlinear diffusion equation.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
@laurent90git I don’t have a simple example but I do have a detailed example that consists of an ODE system of 15 equations. I can push the code to GitHub and share the repository with you if you’re interested in all the details of the problem that I’m trying to solve. The equations for the problem are taken from the Agu et al. 2019 paper which discusses a one-dimensional model for biomass gasification. The author of the paper implemented the model in Matlab where the
ode23tb
solver was the only one that gave reasonable results. The author said the other solvers would produce errors or not converge to a solution. I’m trying to develop the same model in Python and can’t get the existing solvers in SciPy to work.@laurent90git Thank you for such an in-depth comment. It sounds like some refactoring is needed to make the gasifier code better suited for the SciPy solvers. But in general, I believe it’s still a good idea to have a TR-BDF2 method available in SciPy.
Now back to the gasifier code…
I think it would be best to talk about the gasifier code using the Issues on the project’s repository. I started an Issue at https://github.com/wigging/bfb-gasifier/issues/1 where we can continue this conversation. So please move your comment to that Issue.
I also changed the name of the repository which is now https://github.com/wigging/bfb-gasifier. So make sure you update your local repo with
git remote set-url origin https://github.com/wigging/bfb-gasifier
.Also, please see the other Issue regarding the code structure of the model https://github.com/wigging/bfb-gasifier/issues/2. You may have some suggestions on how to structure the code which would make it easier to work with.