question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TR-BDF2 algorithm for solving ODE systems

See original GitHub issue

Is 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:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wiggingcommented, Jan 28, 2021

@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.

0reactions
wiggingcommented, Jan 29, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Analysis and implementation of TR-BDF2
(1985) developed a one-step method, TR-BDF2, for the simulation of circuits and ... for the numerical solution of systems of ordinary differential equations....
Read more >
A self adjusting multirate algorithm based on the TR-BDF2 ...
Abstract. We propose a self adjusting multirate method based on the TR-. BDF2 solver. The potential advantages of using TR-BDF2 as the key....
Read more >
BDF2 and TR-BDF2: what is better? [closed]
The TR-BDF2 method computes an auxiliary value yn+1/2 with the trapezoidal method and applies the BDF2 for computing yn+1 by using yn and...
Read more >
The TR-BDF2 method for second order problems in ...
TR-BDF2 method can be applied to second order problems and refor- mulated so as to avoid solving systems of dimension larger than the....
Read more >
An Analysis of the TR-BDF2 integration scheme
2.1 Newton's method for solving systems of nonlinear systems of equations ... In the context of ordinary differential equations (ODEs) the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found