-
Notifications
You must be signed in to change notification settings - Fork 220
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
Encounter Prediction Switching Condition for TRACE #788
Conversation
If the timestep is this large, then aren't you basically ignoring planet-planet interactions during conjunctions unless there is an encounter. The runs on windows sometimes fail because of a timing unit test which is probably too strict (you should be able to click on the failed tests and see the error). |
Yes, you are. Increasing the switching radius/decreasing the timestep could fix this in principle, but for these large N problems this seems more robust. Hmm, I'm seeing a different error in my tests: ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (rebound) |
Ah sorry, I just assumed it's the usual timing thing, but it's a syntax error. My bad. If you look at the output, the compiler error says that the following and similar expressions are not correct:
You probably want to have
A few more things:
|
Hello, to add some comments (we can also discuss via email): |
And yes, after checking, I guess this linear extrapolation could reuse something from LINE collision detection? |
I'll keep things on the PR in case others want to follow along:
|
OK, so if I understood everything, here's the difference between what LINE is doing and Tiger's change. He's doing a prediction with Euler as LINE would do no velocity update (because velocities are constant, yes?), and eq (2) above would be gone. And definitely no cubic minimum would be needed. I'm guessing all the slowdown is coming from these cubic solvers right? |
Thanks for the explanations. That helps!
|
Ah, my mistake! I meant to implement r_{n \pm 1/2} = r_n \pm t v_n \pm 1/2 t^2 a_n but forgot the acceleration term. It's now in (so now the cubic makes sense) and seems to be meaningfully better than the default case. On the accretion example I tested we catch 50% more close encounters and go from 1.3e-2 to 5.3e-3 relative error. @hannorein The two switching functions and arrays are a hack, this can certainly be optimized still. My logic was this: we need the pre- and -post positions/velocities for all particles. But the way the switching function syntax is set up right now, we calculate these positions/velocities N^2 times (since the switching function is called for every pair of particles), rather than the N which is all we need. So I just computed them in the pericenter switching condition loop (since we get the approximate accelerations "for free" for the PRS condition anyway). The final implementation will have to move them out of here, and I'm not sure what the best way to do this is -- we shouldn't demand every switching function does this, since the default doesn't need the encounter prediction. |
Hello, by cubic I just mean the Chambers 1999 cubic interpolation polynomial, eq. (11) and pasted here. Given r_n, r_{n \pm 1/2}, v_n, v_{n \pm 1/2}, we calculate the minimum r. But @tigerchenlu98 , note that in your new modification, I believe r is described by a quadratic polynomial, so the cubic machinery is still not needed. We just need the minimum of a quadratic equation now. And I'd also encourage what @hannorein mentions as well that we try velocities constant (so then it's only the minimum of a linear function!) |
Also, note I think we need this, |
You're both totally right, the cubic is completely unnecessary -- don't know what I was thinking |
Might be good, once the new switching criteria is implemented, to verify it's still reversible and there is still no energy drift in say, chaotic exchange problem. |
@tigerchenlu98 The unit test fails because of the |
The PR looks good to me. Just one thing regarding the naming: right now we have |
Hi Hanno, There is a default pericenter condition -- |
src/rebound.h
Outdated
@@ -849,11 +849,11 @@ DLLEXPORT double reb_integrator_mercurius_L_C5(const struct reb_simulation* cons | |||
|
|||
// Built in trace switching functions | |||
|
|||
DLLEXPORT int reb_integrator_trace_switch_peri_default(struct reb_simulation* const r, const unsigned int j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're removing reb_integrator_trace_switch_peri_default
?
Ah I didn't mean to do that -- it's added back now. |
Ok. Now it makes sense. Thanks! |
@hannorein @dmhernan
This is in response to a few comments/suggestions we've gotten - my first try at implementing a switching condition that accounts for close encounters mid-timestep. In brief, we crudely calculate positions and velocities at dt/2 behind and ahead of the check and use the interpolation scheme from MERCURIUS encounter_predict. From preliminary testing it catches many more close encounters in large N problems, where relative velocities may be quite high compared to rcrit.
At the moment this is quite a bit slower than the default condition without a huge accuracy boost, so I don't think it's worth making the default, but having it as an option may be useful. There's also certainly room for optimization, let me know if you have immediate thoughts.
Also not quite sure why the checks are not passing... everything is fine on my machine (python and C) for what it's worth.