Reputation: 91
This question is about the odeint function in the scipy.integrate module.
I'm simulating interacting galaxies on the following principle: I let two nuclei move in a Kepler orbit and then I take every star in the galaxies to be without a mass.
I'm working in the reference frame of 1 galaxy so I'm using two classical Newton gravity forces + 1 centrifugal force.
All this is integrated with odeint (scipy.integrate module), which works great. I'm having a problem with the speed odeint is integrating my stars tho: Every star takes about 10-15 seconds to be integrated in about 100 time steps (~1 billion year), but this equals to a few hours to integrate for in total 1000 stars. According to my professor, HIS program runs about 5 minutes, doing those number of stars. I don't even have a clue how I can improve this speed, since I cannot change the equations, and odeint is really taking 99% of the running time.
So long story short, how I can improve my odeint calculation time?
Thanks
Upvotes: 2
Views: 1238
Reputation: 1858
odeint
is a good general purpose ode integrator, but it might not be using the best method for your problem for some reason. You might try using ode
1 instead since you can control it a little bit more by changing which integrator it uses. If the problem is not stiff then it is usually reasonable to use the Runge-Kutta (4)5 method (dopri5 using ode
) and if the problem is stiff then the BDF methods are usually a good choice. Since I don't model the type of problem you describe, I don't know if your problem is stiff and I suggest that you try dopri5 first and the BDF method second.
You may also have a problem in your code that makes the evaluation of the right hand side unreasonably inefficient so you might try doing some work there to speed of the execution. Another advantage to ode
is that you can provide it with a function that gives the exact Jacobian which can considerably increase the speed since approximations aren't used.
Reference: Scipy docs on ode
Upvotes: 2