New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LeapfrogIntegrator will reverse the sign of velocity which may lead to incorrect result #278
Comments
Hi @azz147 - can you say more about what you would like to do? In my use cases where I have implemented dynamical friction, if I am integrating backwards in time, I do want to reverse the sign of the friction force. Are you sure you don't want this? |
Hi @adrn , if |
Ah, yes, but note that in line L148 in the code you linked above the timestep is turned positive |
I'm at a conference now so can't look closely until later this week, but I think the integrator is behaving as I would expect. For example, here's a toy: A Kepler potential with a simple/fake drag force that acts opposite the velocity vector. Integrating forwards in time, the orbit decays. Taking the final position and integrating backwards (i.e. just setting dt to a negative value), the orbit grows back to the starting position. https://gist.github.com/62138226e1daf734db1aa9cf7c12781d |
Thanks for the demo, that is very helpful. I realized the code I referred above actually comes from an old version (I use search in GitHub to find the code of that function and somehow I get into an old version code), and 51278ee already fixed this in v1.5. My installed version stays at v1.4.1 due to python 3.7, but I guess I could try to upgrade python to get v1.5. |
Hi, thank you for the great package. I realized the below code in the LeapfrogIntegrator may change the sign of the velocity when
_dt
is negative, which may change the result of the force function because it could depend on the velocity. In my case I add a dynamical friction term in my force function and LeapfrogIntegrator will give me incorrect results.gala/gala/integrate/pyintegrators/leapfrog.py
Lines 146 to 150 in 782a8b1
The text was updated successfully, but these errors were encountered: